Compare commits

..

No commits in common. "main" and "v0.4.0" have entirely different histories.
main ... v0.4.0

20 changed files with 38 additions and 41 deletions

View File

@ -30,6 +30,7 @@ func CAPool() (*x509.CertPool, error) {
// GetCertman sets up certman for the specified cert / key pair. It is // GetCertman sets up certman for the specified cert / key pair. It is
// used in the monitor-api and (for now) in the client // used in the monitor-api and (for now) in the client
func GetCertman(certFile, keyFile string) (*certman.CertMan, error) { func GetCertman(certFile, keyFile string) (*certman.CertMan, error) {
cm, err := certman.New(certFile, keyFile) cm, err := certman.New(certFile, keyFile)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -11,7 +11,7 @@ import (
"go.ntppool.org/common/logger" "go.ntppool.org/common/logger"
) )
//go:generate go tool github.com/masaushi/accessory -type Config //go:generate accessory -type Config
type Config struct { type Config struct {
deploymentMode string `accessor:"getter"` deploymentMode string `accessor:"getter"`
@ -50,10 +50,6 @@ func (c *Config) WebURL(path string, query *url.Values) string {
return baseURL(c.webHostname, c.webTLS, path, query) return baseURL(c.webHostname, c.webTLS, path, query)
} }
func (c *Config) ManageURL(path string, query *url.Values) string {
return baseURL(c.manageHostname, c.webTLS, path, query)
}
func baseURL(host string, tls bool, path string, query *url.Values) string { func baseURL(host string, tls bool, path string, query *url.Values) string {
uri := url.URL{} uri := url.URL{}
uri.Host = host uri.Host = host

View File

@ -7,6 +7,7 @@ import (
) )
func TestBaseURL(t *testing.T) { func TestBaseURL(t *testing.T) {
os.Setenv("web_hostname", "www.ntp.dev, web.ntppool.dev") os.Setenv("web_hostname", "www.ntp.dev, web.ntppool.dev")
os.Setenv("web_tls", "yes") os.Setenv("web_tls", "yes")
@ -21,4 +22,5 @@ func TestBaseURL(t *testing.T) {
if u != "https://www.ntp.dev/foo?foo=bar" { if u != "https://www.ntp.dev/foo?foo=bar" {
t.Fatalf("unexpected WebURL: %s", u) t.Fatalf("unexpected WebURL: %s", u)
} }
} }

View File

@ -69,10 +69,6 @@ func (d DeploymentEnvironment) ManageURL(path string) string {
return manageServers[d] + path return manageServers[d] + path
} }
func (d DeploymentEnvironment) MonitorDomain() string {
return d.String() + ".mon.ntppool.dev"
}
func (d *DeploymentEnvironment) UnmarshalText(text []byte) error { func (d *DeploymentEnvironment) UnmarshalText(text []byte) error {
s := string(text) s := string(text)
if s == "" { if s == "" {

View File

@ -16,7 +16,6 @@ import (
"go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho" "go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
"golang.org/x/net/http2"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
@ -51,8 +50,7 @@ func (ek *Ekko) Start(ctx context.Context) error {
g.Go(func() error { g.Go(func() error {
e.Server.Addr = fmt.Sprintf(":%d", ek.port) e.Server.Addr = fmt.Sprintf(":%d", ek.port)
log.Info("server starting", "port", ek.port) log.Info("server starting", "port", ek.port)
// err := e.Server.ListenAndServe() err := e.Server.ListenAndServe()
err := e.StartH2CServer(e.Server.Addr, &http2.Server{})
if err == http.ErrServerClosed { if err == http.ErrServerClosed {
return nil return nil
} }
@ -122,13 +120,7 @@ func (ek *Ekko) setup(ctx context.Context) (*echo.Echo, error) {
e.Use(middleware.Gzip()) e.Use(middleware.Gzip())
} }
secureConfig := middleware.DefaultSecureConfig e.Use(middleware.Secure())
// secureConfig.ContentSecurityPolicy = "default-src *"
secureConfig.ContentSecurityPolicy = ""
secureConfig.HSTSMaxAge = int(time.Hour * 168 * 30 / time.Second)
secureConfig.HSTSPreloadEnabled = true
e.Use(middleware.SecureWithConfig(secureConfig))
e.Use( e.Use(
func(next echo.HandlerFunc) echo.HandlerFunc { func(next echo.HandlerFunc) echo.HandlerFunc {

View File

@ -8,6 +8,7 @@ import (
) )
func TestHealthHandler(t *testing.T) { func TestHealthHandler(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/__health", nil) req := httptest.NewRequest(http.MethodGet, "/__health", nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()

View File

@ -42,9 +42,11 @@ type Kafka struct {
l *log.Logger l *log.Logger
// wr *kafka.Writer // wr *kafka.Writer
} }
func (k *Kafka) tlsConfig() (*tls.Config, error) { func (k *Kafka) tlsConfig() (*tls.Config, error) {
cm, err := certman.New(k.tls.Cert, k.tls.Key) cm, err := certman.New(k.tls.Cert, k.tls.Key)
if err != nil { if err != nil {
return nil, err return nil, err
@ -187,6 +189,7 @@ func (k *Kafka) brokerAddrs() []string {
} }
func (k *Kafka) NewWriter(topic string) (*kafka.Writer, error) { func (k *Kafka) NewWriter(topic string) (*kafka.Writer, error) {
// https://pkg.go.dev/github.com/segmentio/kafka-go#Writer // https://pkg.go.dev/github.com/segmentio/kafka-go#Writer
w := &kafka.Writer{ w := &kafka.Writer{
Addr: kafka.TCP(k.brokerAddrs()...), Addr: kafka.TCP(k.brokerAddrs()...),

View File

@ -17,6 +17,7 @@ type logfmt struct {
} }
func newLogFmtHandler(next slog.Handler) slog.Handler { func newLogFmtHandler(next slog.Handler) slog.Handler {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
h := &logfmt{ h := &logfmt{

View File

@ -9,6 +9,7 @@ import (
) )
func TestLogFmt(t *testing.T) { func TestLogFmt(t *testing.T) {
var buf bytes.Buffer var buf bytes.Buffer
jsonh := slog.NewJSONHandler(&buf, nil) jsonh := slog.NewJSONHandler(&buf, nil)
h := newLogFmtHandler(jsonh) h := newLogFmtHandler(jsonh)
@ -38,4 +39,5 @@ func TestLogFmt(t *testing.T) {
t.Log("didn't find message in output") t.Log("didn't find message in output")
t.Fail() t.Fail()
} }
} }

View File

@ -15,21 +15,17 @@ import (
var ConfigPrefix = "" var ConfigPrefix = ""
var ( var textLogger *slog.Logger
textLogger *slog.Logger var otlpLogger *slog.Logger
otlpLogger *slog.Logger var multiLogger *slog.Logger
multiLogger *slog.Logger
)
var ( var setupText sync.Once // this sets the default
setupText sync.Once // this sets the default var setupOtlp sync.Once // this never sets the default
setupOtlp sync.Once // this never sets the default var setupMulti sync.Once // this sets the default, and will always run after the others
setupMulti sync.Once // this sets the default, and will always run after the others var mu sync.Mutex
mu sync.Mutex
)
func setupStdErrHandler() slog.Handler { func setupStdErrHandler() slog.Handler {
programLevel := new(slog.LevelVar) // Info by default var programLevel = new(slog.LevelVar) // Info by default
envVar := "DEBUG" envVar := "DEBUG"
if len(ConfigPrefix) > 0 { if len(ConfigPrefix) > 0 {

View File

@ -27,15 +27,15 @@ func NewStdLog(key string, debug bool, log *slog.Logger) *stdLoggerish {
return sl return sl
} }
func (l stdLoggerish) Println(msg ...any) { func (l stdLoggerish) Println(msg ...interface{}) {
l.f(l.key, "msg", msg) l.f(l.key, "msg", msg)
} }
func (l stdLoggerish) Printf(msg string, args ...any) { func (l stdLoggerish) Printf(msg string, args ...interface{}) {
l.f(l.key, "msg", fmt.Sprintf(msg, args...)) l.f(l.key, "msg", fmt.Sprintf(msg, args...))
} }
func (l stdLoggerish) Fatalf(msg string, args ...any) { func (l stdLoggerish) Fatalf(msg string, args ...interface{}) {
l.log.Error(l.key, "msg", fmt.Sprintf(msg, args...)) l.log.Error(l.key, "msg", fmt.Sprintf(msg, args...))
panic("fatal error") // todo: does this make sense at all? panic("fatal error") // todo: does this make sense at all?
} }

View File

@ -32,6 +32,7 @@ func (m *Metrics) Registry() *prometheus.Registry {
} }
func (m *Metrics) Handler() http.Handler { func (m *Metrics) Handler() http.Handler {
log := logger.NewStdLog("prom http", false, nil) log := logger.NewStdLog("prom http", false, nil)
return promhttp.HandlerFor(m.r, promhttp.HandlerOpts{ return promhttp.HandlerFor(m.r, promhttp.HandlerOpts{
@ -45,6 +46,7 @@ func (m *Metrics) Handler() http.Handler {
// the specified port. The server will shutdown and return when // the specified port. The server will shutdown and return when
// the provided context is done // the provided context is done
func (m *Metrics) ListenAndServe(ctx context.Context, port int) error { func (m *Metrics) ListenAndServe(ctx context.Context, port int) error {
log := logger.Setup() log := logger.Setup()
srv := &http.Server{ srv := &http.Server{

View File

@ -15,7 +15,7 @@ func (d Duration) MarshalJSON() ([]byte, error) {
} }
func (d *Duration) UnmarshalJSON(b []byte) error { func (d *Duration) UnmarshalJSON(b []byte) error {
var v any var v interface{}
if err := json.Unmarshal(b, &v); err != nil { if err := json.Unmarshal(b, &v); err != nil {
return err return err
} }

View File

@ -18,4 +18,5 @@ func TestDuration(t *testing.T) {
if foo.Foo.Seconds() != 30 { if foo.Foo.Seconds() != 30 {
t.Fatalf("parsed time.Duration wasn't 30 seconds: %s", foo.Foo) t.Fatalf("parsed time.Duration wasn't 30 seconds: %s", foo.Foo)
} }
} }

View File

@ -237,7 +237,7 @@ func newOLTPExporter(ctx context.Context, cfg *TracerConfig) (sdktrace.SpanExpor
} }
client = otlptracegrpc.NewClient(opts...) client = otlptracegrpc.NewClient(opts...)
case "http/protobuf", "http/json": case "http/protobuf":
opts := []otlptracehttp.Option{ opts := []otlptracehttp.Option{
otlptracehttp.WithCompression(otlptracehttp.GzipCompression), otlptracehttp.WithCompression(otlptracehttp.GzipCompression),
} }

View File

@ -7,6 +7,7 @@ import (
) )
func TestInit(t *testing.T) { func TestInit(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
@ -17,4 +18,5 @@ func TestInit(t *testing.T) {
t.FailNow() t.FailNow()
} }
defer shutdownFn(ctx) defer shutdownFn(ctx)
} }

View File

@ -29,7 +29,7 @@ func (lsa *LogScoreAttributes) Value() (driver.Value, error) {
return json.Marshal(lsa) return json.Marshal(lsa)
} }
func (lsa *LogScoreAttributes) Scan(value any) error { func (lsa *LogScoreAttributes) Scan(value interface{}) error {
var source []byte var source []byte
_t := LogScoreAttributes{} _t := LogScoreAttributes{}

View File

@ -14,7 +14,8 @@ import (
) )
var monotonicPool = sync.Pool{ var monotonicPool = sync.Pool{
New: func() any { New: func() interface{} {
log := logger.Setup() log := logger.Setup()
var seed int64 var seed int64
@ -38,6 +39,7 @@ var monotonicPool = sync.Pool{
} }
func MakeULID(t time.Time) (*oklid.ULID, error) { func MakeULID(t time.Time) (*oklid.ULID, error) {
mono := monotonicPool.Get().(io.Reader) mono := monotonicPool.Get().(io.Reader)
id, err := oklid.New(oklid.Timestamp(t), mono) id, err := oklid.New(oklid.Timestamp(t), mono)

View File

@ -168,9 +168,6 @@ func CheckVersion(version, minimumVersion string) bool {
if version == "dev-snapshot" { if version == "dev-snapshot" {
return true return true
} }
if idx := strings.Index(version, "/"); idx >= 0 {
version = version[0:idx]
}
if semver.Compare(version, minimumVersion) < 0 { if semver.Compare(version, minimumVersion) < 0 {
// log.Debug("version too old", "v", cl.Version.Version) // log.Debug("version too old", "v", cl.Version.Version)
return false return false

View File

@ -3,12 +3,14 @@ package fastlyxff
import "testing" import "testing"
func TestFastlyIPRanges(t *testing.T) { func TestFastlyIPRanges(t *testing.T) {
fastlyxff, err := New("fastly.json") fastlyxff, err := New("fastly.json")
if err != nil { if err != nil {
t.Fatalf("could not load test data: %s", err) t.Fatalf("could not load test data: %s", err)
} }
data, err := fastlyxff.EchoTrustOption() data, err := fastlyxff.EchoTrustOption()
if err != nil { if err != nil {
t.Fatalf("could not parse test data: %s", err) t.Fatalf("could not parse test data: %s", err)
} }
@ -17,4 +19,5 @@ func TestFastlyIPRanges(t *testing.T) {
t.Logf("only got %d prefixes, expected more", len(data)) t.Logf("only got %d prefixes, expected more", len(data))
t.Fail() t.Fail()
} }
} }