diff --git a/cmd/ns1_exporter/ns1_exporter.go b/cmd/ns1_exporter/ns1_exporter.go index 80d306a..0d2185f 100644 --- a/cmd/ns1_exporter/ns1_exporter.go +++ b/cmd/ns1_exporter/ns1_exporter.go @@ -17,7 +17,7 @@ package main import ( "context" "fmt" - stdlog "log" + "log/slog" "net/http" _ "net/http/pprof" "os" @@ -28,13 +28,11 @@ import ( "time" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/oklog/run" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/prometheus/common/promlog" - "github.com/prometheus/common/promlog/flag" + "github.com/prometheus/common/promslog" + "github.com/prometheus/common/promslog/flag" "github.com/prometheus/exporter-toolkit/web" "github.com/prometheus/exporter-toolkit/web/kingpinflag" @@ -132,31 +130,31 @@ var ( ) func main() { - promlogConfig := &promlog.Config{} - flag.AddFlags(kingpin.CommandLine, promlogConfig) + promslogConfig := &promslog.Config{} + flag.AddFlags(kingpin.CommandLine, promslogConfig) kingpin.Version(version.Print(programName)) kingpin.CommandLine.UsageWriter(os.Stdout) kingpin.HelpFlag.Short('h') kingpin.Parse() - logger := promlog.New(promlogConfig) + logger := promslog.New(promslogConfig) - level.Info(logger).Log("msg", "Starting "+programName, "version", version.Version, "build_date", version.BuildDate, "commit", version.Commit, "go_version", runtime.Version()) + logger.Info("Starting "+programName, "version", version.Version, "build_date", version.BuildDate, "commit", version.Commit, "go_version", runtime.Version()) // nicely yell at people needlessly running as root if os.Geteuid() == 0 { - level.Warn(logger).Log("msg", programName+"is running as root user. This exporter is designed to run as unprivileged user, root is not required.") + logger.Warn(programName + "is running as root user. This exporter is designed to run as unprivileged user, root is not required.") } runtime.GOMAXPROCS(*flagRuntimeGOMAXPROCS) - level.Debug(logger).Log("msg", "Go MAXPROCS", "procs", runtime.GOMAXPROCS(0)) + logger.Debug("Go MAXPROCS", "procs", runtime.GOMAXPROCS(0)) Run(logger) } -func Run(logger log.Logger) { +func Run(logger *slog.Logger) { token := os.Getenv("NS1_APIKEY") if token == "" { - level.Error(logger).Log("err", "NS1_APIKEY environment variable is not set") + logger.Error("NS1_APIKEY environment variable is not set") os.Exit(1) } @@ -178,7 +176,7 @@ func Run(logger log.Logger) { func() error { select { case sig := <-term: - level.Warn(logger).Log("msg", "Caught signal, exiting gracefully.", "signal", sig.String()) + logger.Warn("Caught signal, exiting gracefully.", "signal", sig.String()) case <-cancel: } @@ -232,7 +230,7 @@ func Run(logger log.Logger) { case true: ticker := time.NewTicker(*flagNS1SDRefreshInterval) defer ticker.Stop() - level.Info(logger).Log("msg", "Prometheus HTTP service discovery enabled", "sd_refresh_interval", strconv.FormatBool(*flagNS1EnableSD)) + logger.Info("Prometheus HTTP service discovery enabled", "sd_refresh_interval", strconv.FormatBool(*flagNS1EnableSD)) for { // work around the fact that tickers @@ -272,7 +270,7 @@ func Run(logger log.Logger) { g.Add( func() error { if err := web.ListenAndServe(server, toolkitFlags, logger); err != http.ErrServerClosed { - level.Error(logger).Log("err", err) + logger.Error("Failed to run webserver", "err", err) return err } @@ -283,7 +281,7 @@ func Run(logger log.Logger) { func(error) { if err := server.Shutdown(context.Background()); err != nil { // Error from closing listeners, or context timeout: - level.Error(logger).Log("err", err) + logger.Error("Failed to close listeners/context timeout", "err", err) } close(cancel) }, @@ -291,13 +289,13 @@ func Run(logger log.Logger) { } if err := g.Run(); err != nil { - level.Error(logger).Log("err", err) + logger.Error("Failed to run ok-log/run daemon goroutines", "err", err) os.Exit(1) } - level.Info(logger).Log("msg", programName+" finished. See you next time!") + logger.Info(programName + " finished. See you next time!") } -func setupServer(logger log.Logger, sdWorker *sd.Worker) *http.Server { +func setupServer(logger *slog.Logger, sdWorker *sd.Worker) *http.Server { server := &http.Server{ ReadTimeout: 30 * time.Second, WriteTimeout: 30 * time.Second, @@ -307,7 +305,7 @@ func setupServer(logger log.Logger, sdWorker *sd.Worker) *http.Server { metricsHandler := promhttp.HandlerFor( prometheus.Gatherers{metrics.Registry}, promhttp.HandlerOpts{ - ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(logger)), "", 0), + ErrorLog: slog.NewLogLogger(logger.Handler(), slog.LevelError), ErrorHandling: promhttp.ContinueOnError, MaxRequestsInFlight: *flagWebMaxRequests, Registry: metrics.Registry, @@ -345,7 +343,7 @@ func setupServer(logger log.Logger, sdWorker *sd.Worker) *http.Server { } landingPage, err := web.NewLandingPage(landingConfig) if err != nil { - level.Error(logger).Log("err", err) + logger.Error("Failed to create landing page", "err", err) os.Exit(1) } http.Handle("/", landingPage) diff --git a/go.mod b/go.mod index 62ec548..4758bbb 100644 --- a/go.mod +++ b/go.mod @@ -4,37 +4,38 @@ go 1.23.0 require ( github.com/alecthomas/kingpin/v2 v2.4.0 - github.com/go-kit/log v0.2.1 github.com/oklog/run v1.1.0 - github.com/prometheus/client_golang v1.20.2 - github.com/prometheus/common v0.57.0 - github.com/prometheus/exporter-toolkit v0.11.0 + github.com/prometheus/client_golang v1.20.4 + github.com/prometheus/common v0.59.1 + github.com/prometheus/exporter-toolkit v0.13.0 github.com/samber/lo v1.47.0 github.com/stretchr/testify v1.9.0 - gopkg.in/ns1/ns1-go.v2 v2.12.0 + gopkg.in/ns1/ns1-go.v2 v2.12.1 ) require ( - github.com/alecthomas/units v0.0.0-20240626203959-61d1e3462e30 // indirect + github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/jpillora/backoff v1.0.0 // indirect - github.com/klauspost/compress v1.17.9 // indirect + github.com/klauspost/compress v1.17.10 // indirect + github.com/kylelemons/godebug v1.1.0 // indirect + github.com/mdlayher/socket v0.5.1 // indirect + github.com/mdlayher/vsock v1.2.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/xhit/go-str2duration/v2 v2.1.0 // indirect - golang.org/x/crypto v0.26.0 // indirect - golang.org/x/net v0.28.0 // indirect - golang.org/x/oauth2 v0.22.0 // indirect + golang.org/x/crypto v0.27.0 // indirect + golang.org/x/net v0.29.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect golang.org/x/sync v0.8.0 // indirect - golang.org/x/sys v0.24.0 // indirect - golang.org/x/text v0.17.0 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.18.0 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 44dcd39..c0ffee4 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjHpqDjYY= github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE= -github.com/alecthomas/units v0.0.0-20240626203959-61d1e3462e30 h1:t3eaIm0rUkzbrIewtiFmMK5RXHej2XnoXNhxVsAYUfg= -github.com/alecthomas/units v0.0.0-20240626203959-61d1e3462e30/go.mod h1:fvzegU4vN3H1qMT+8wDmzjAcDONcgo2/SZ/TyfdUOFs= +github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b h1:mimo19zliBX/vSQ6PWWSL9lK8qwHozUj03+zLoEB8O0= +github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b/go.mod h1:fvzegU4vN3H1qMT+8wDmzjAcDONcgo2/SZ/TyfdUOFs= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -12,21 +12,23 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= -github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= -github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= -github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= -github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= -github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0= +github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos= +github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ= +github.com/mdlayher/vsock v1.2.1 h1:pC1mTJTvjo1r9n9fbm7S1j04rCgCzhCOS5DY0zqHlnQ= +github.com/mdlayher/vsock v1.2.1/go.mod h1:NRfCibel++DgeMD8z/hP+PPTjlNJsdPOmxcnENvE+SE= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= @@ -36,24 +38,18 @@ github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DV github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= -github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= -github.com/prometheus/client_golang v1.20.2 h1:5ctymQzZlyOON1666svgwn3s6IKWgfbjsejTMiXIyjg= -github.com/prometheus/client_golang v1.20.2/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI= +github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= -github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc= -github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= -github.com/prometheus/common v0.57.0 h1:Ro/rKjwdq9mZn1K5QPctzh+MA4Lp0BuYk5ZZEVhoNcY= -github.com/prometheus/common v0.57.0/go.mod h1:7uRPFSUTbfZWsJ7MHY56sqt7hLQu3bxXHDnNhl8E9qI= -github.com/prometheus/exporter-toolkit v0.11.0 h1:yNTsuZ0aNCNFQ3aFTD2uhPOvr4iD7fdBvKPAEGkNf+g= -github.com/prometheus/exporter-toolkit v0.11.0/go.mod h1:BVnENhnNecpwoTLiABx7mrPB/OLRIgN74qlQbV+FK1Q= +github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= +github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/exporter-toolkit v0.13.0 h1:lmA0Q+8IaXgmFRKw09RldZmZdnvu9wwcDLIXGmTPw1c= +github.com/prometheus/exporter-toolkit v0.13.0/go.mod h1:2uop99EZl80KdXhv/MxVI2181fMcwlsumFOqBecGkG0= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= -github.com/samber/lo v1.46.0 h1:w8G+oaCPgz1PoCJztqymCFaKwXt+5cCXn51uPxExFfQ= -github.com/samber/lo v1.46.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -68,25 +64,25 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc= github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU= -golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= -golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= -golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= -golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= -golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= -golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= -golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/ns1/ns1-go.v2 v2.12.0 h1:cqdqQoTx17JmTusfxh5m3e2b36jfUzFAZedv89pFX18= -gopkg.in/ns1/ns1-go.v2 v2.12.0/go.mod h1:pfaU0vECVP7DIOr453z03HXS6dFJpXdNRwOyRzwmPSc= +gopkg.in/ns1/ns1-go.v2 v2.12.1 h1:GiiZPB8JusUF/ruyUDzddd70b3HZGa5A3njtKUe84jA= +gopkg.in/ns1/ns1-go.v2 v2.12.1/go.mod h1:pfaU0vECVP7DIOr453z03HXS6dFJpXdNRwOyRzwmPSc= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/exporter/exporter.go b/pkg/exporter/exporter.go index 89863fa..6f8b269 100644 --- a/pkg/exporter/exporter.go +++ b/pkg/exporter/exporter.go @@ -16,10 +16,9 @@ package exporter import ( "fmt" + "log/slog" "regexp" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" api "gopkg.in/ns1/ns1-go.v2/rest" @@ -36,21 +35,21 @@ type Worker struct { ZoneBlacklist *regexp.Regexp ZoneWhitelist *regexp.Regexp - logger log.Logger + logger *slog.Logger client *api.Client zoneCache map[string]*ns1_internal.Zone qpsCache []*ns1_internal.QPS } // NewWorker creates a new Worker struct to collect data from the NS1 API -func NewWorker(logger log.Logger, client *api.Client, zoneEnabled, recordEnabled bool, blacklist, whitelist *regexp.Regexp) *Worker { +func NewWorker(logger *slog.Logger, client *api.Client, zoneEnabled, recordEnabled bool, blacklist, whitelist *regexp.Regexp) *Worker { worker := &Worker{ EnableZoneQPS: zoneEnabled, EnableRecordQPS: recordEnabled, ZoneBlacklist: blacklist, ZoneWhitelist: whitelist, client: client, - logger: log.With(logger, "worker", "exporter"), + logger: logger.With("worker", "exporter"), } // register exporter worker for metrics collection @@ -84,11 +83,11 @@ func (w *Worker) Collect(ch chan<- prometheus.Metric) { func (w *Worker) RefreshZoneData() { getRecords := w.EnableRecordQPS || w.EnableZoneQPS w.zoneCache = ns1_internal.RefreshZoneData(w.logger, w.client, getRecords, w.ZoneBlacklist, w.ZoneWhitelist) - level.Debug(w.logger).Log("msg", "Worker zone cache updated", "num_zones", len(w.zoneCache)) + w.logger.Debug("Worker zone cache updated", "num_zones", len(w.zoneCache)) if getRecords { for k, v := range w.zoneCache { - level.Debug(w.logger).Log("msg", "Worker zone record count", "zone", k, "num_records", len(v.Records)) + w.logger.Debug("Worker zone record count", "zone", k, "num_records", len(v.Records)) } } } @@ -117,10 +116,10 @@ func (w *Worker) RefreshQPSData() { func (w *Worker) RefreshQPSAccountData() { cache := make([]*ns1_internal.QPS, 1) - level.Debug(w.logger).Log("msg", "Refreshing account-level qps data from NS1 API") + w.logger.Debug("Refreshing account-level qps data from NS1 API") qpsRaw, _, err := w.client.Stats.GetQPS() if err != nil { - level.Error(w.logger).Log("msg", "Failed to get account-level qps data from NS1 API", "err", err.Error()) + w.logger.Error("Failed to get account-level qps data from NS1 API", "err", err) metrics.MetricExporterNS1APIFailures.Inc() } @@ -128,7 +127,7 @@ func (w *Worker) RefreshQPSAccountData() { Value: qpsRaw, } w.qpsCache = cache - level.Debug(w.logger).Log("msg", "Worker QPS cache updated", "qps_level", "account") + w.logger.Debug("Worker QPS cache updated", "qps_level", "account") } // RefreshQPSZoneData refreshes the worker's `[]*ns1_internal.QPS` cache array by using the zone/record information present in the worker's `map[string]*ns1_internal.Zone` cache map. @@ -136,10 +135,10 @@ func (w *Worker) RefreshQPSZoneData() { var cache []*ns1_internal.QPS for zName := range w.zoneCache { - level.Debug(w.logger).Log("msg", "Refreshing zone-level qps data from NS1 API", "zone_name", zName) + w.logger.Debug("Refreshing zone-level qps data from NS1 API", "zone_name", zName) zoneQPSRaw, _, err := w.client.Stats.GetZoneQPS(zName) if err != nil { - level.Error(w.logger).Log("msg", "Failed to get zone-level qps data from NS1 API", "err", err.Error(), "zone_name", zName) + w.logger.Error("Failed to get zone-level qps data from NS1 API", "err", err, "zone_name", zName) metrics.MetricExporterNS1APIFailures.Inc() } @@ -147,7 +146,7 @@ func (w *Worker) RefreshQPSZoneData() { Value: zoneQPSRaw, ZoneName: zName, }) - level.Debug(w.logger).Log("msg", "Worker QPS cache updated", "qps_level", "zone", "zone", zName) + w.logger.Debug("Worker QPS cache updated", "qps_level", "zone", "zone", zName) } w.qpsCache = cache } @@ -159,16 +158,16 @@ func (w *Worker) RefreshQPSRecordData() { for _, z := range w.zoneCache { numRecords += len(z.Records) } - level.Debug(w.logger).Log("msg", "updating worker qps cache", "zone_count", len(w.zoneCache), "record_count", fmt.Sprintf("%d", numRecords)) + w.logger.Debug("updating worker qps cache", "zone_count", len(w.zoneCache), "record_count", fmt.Sprintf("%d", numRecords)) var cache []*ns1_internal.QPS for zName, zData := range w.zoneCache { for _, r := range zData.Records { - level.Debug(w.logger).Log("msg", "Refreshing record-level qps data from NS1 API", "zone_name", zName, "record_domain", r.Domain, "record_type", r.Type) + w.logger.Debug("Refreshing record-level qps data from NS1 API", "zone_name", zName, "record_domain", r.Domain, "record_type", r.Type) recordQPSRaw, _, err := w.client.Stats.GetRecordQPS(zName, r.Domain, r.Type) if err != nil { - level.Error(w.logger).Log("msg", "Failed to get record-level qps data for from NS1 API", "err", err.Error(), "zone_name", zName, "record_name", r.Domain, "record_type", r.Type) + w.logger.Error("Failed to get record-level qps data for from NS1 API", "err", err, "zone_name", zName, "record_name", r.Domain, "record_type", r.Type) metrics.MetricExporterNS1APIFailures.Inc() } @@ -179,15 +178,15 @@ func (w *Worker) RefreshQPSRecordData() { RecordType: r.Type, }) } - level.Debug(w.logger).Log("msg", "Worker QPS cache updated", "qps_level", "zone", "zone", zName, "num_records", len(zData.Records)) + w.logger.Debug("Worker QPS cache updated", "qps_level", "zone", "zone", zName, "num_records", len(zData.Records)) } w.qpsCache = cache } // Refresh calls the other Refresh* functions as needed to update the worker's data from the NS1 API. func (w *Worker) Refresh() { - level.Info(w.logger).Log("msg", "Updating zone data from NS1 API") + w.logger.Info("Updating zone data from NS1 API") w.RefreshZoneData() - level.Info(w.logger).Log("msg", "Updating QPS data from NS1 API") + w.logger.Info("Updating QPS data from NS1 API") w.RefreshQPSData() } diff --git a/pkg/exporter/exporter_test.go b/pkg/exporter/exporter_test.go index 7571d34..467ede7 100644 --- a/pkg/exporter/exporter_test.go +++ b/pkg/exporter/exporter_test.go @@ -21,7 +21,7 @@ import ( "testing" prom_testutil "github.com/prometheus/client_golang/prometheus/testutil" - "github.com/prometheus/common/promlog" + "github.com/prometheus/common/promslog" "github.com/stretchr/testify/require" "gopkg.in/ns1/ns1-go.v2/mockns1" api "gopkg.in/ns1/ns1-go.v2/rest" @@ -31,7 +31,7 @@ import ( ) var ( - mockLogger = promlog.New(&promlog.Config{}) + mockLogger = promslog.New(&promslog.Config{}) mockZoneCache = map[string]*ns1_internal.Zone{ "foo.bar": {Zone: "foo.bar", Records: []*ns1_internal.ZoneRecord{ diff --git a/pkg/ns1/api.go b/pkg/ns1/api.go index ab91d12..f6c355f 100644 --- a/pkg/ns1/api.go +++ b/pkg/ns1/api.go @@ -16,12 +16,11 @@ package ns1 import ( "crypto/tls" + "log/slog" "net/http" "regexp" "time" - "github.com/go-kit/log" - "github.com/go-kit/log/level" api "gopkg.in/ns1/ns1-go.v2/rest" "gopkg.in/ns1/ns1-go.v2/rest/model/dns" @@ -90,12 +89,12 @@ func NewClient(config APIConfig) *api.Client { return c } -func RefreshZoneData(logger log.Logger, c *api.Client, getRecords bool, zoneBlacklist, zoneWhitelist *regexp.Regexp) map[string]*Zone { +func RefreshZoneData(logger *slog.Logger, c *api.Client, getRecords bool, zoneBlacklist, zoneWhitelist *regexp.Regexp) map[string]*Zone { zMap := make(map[string]*Zone) zones, _, err := c.Zones.List() if err != nil { - level.Error(logger).Log("msg", "Failed to list zones from NS1 API", "err", err.Error(), "worker", "exporter") + logger.Error("Failed to list zones from NS1 API", "err", err, "worker", "exporter") metrics.MetricExporterNS1APIFailures.Inc() return zMap } @@ -106,7 +105,7 @@ func RefreshZoneData(logger log.Logger, c *api.Client, getRecords bool, zoneBlac for _, z := range zones { if zoneBlacklist.MatchString(z.Zone) { // if zone in blacklist, log it and skip it - level.Debug(logger).Log("msg", "skipping zone because it matches blacklist regex", "zone", z.Zone, "blacklist_regex", zoneBlacklist.String()) + logger.Debug("skipping zone because it matches blacklist regex", "zone", z.Zone, "blacklist_regex", zoneBlacklist.String()) continue } @@ -122,7 +121,7 @@ func RefreshZoneData(logger log.Logger, c *api.Client, getRecords bool, zoneBlac for _, z := range zones { if !zoneWhitelist.MatchString(z.Zone) { // if zone not in whitelist, log it and skip it - level.Debug(logger).Log("msg", "skipping zone because it doesn't match whitelist regex", "zone", z.Zone, "whitelist_regex", zoneWhitelist.String()) + logger.Debug("skipping zone because it doesn't match whitelist regex", "zone", z.Zone, "whitelist_regex", zoneWhitelist.String()) continue } filteredZones = append(filteredZones, z) @@ -137,7 +136,7 @@ func RefreshZoneData(logger log.Logger, c *api.Client, getRecords bool, zoneBlac for _, z := range zones { zoneDataRaw, _, err := c.Zones.Get(z.Zone, true) if err != nil { - level.Error(logger).Log("msg", "Failed to get zone data from NS1 API", "err", err.Error(), "worker", "exporter", "zone_name", z.Zone) + logger.Error("Failed to get zone data from NS1 API", "err", err, "worker", "exporter", "zone_name", z.Zone) continue } diff --git a/pkg/ns1/api_test.go b/pkg/ns1/api_test.go index 806f29f..5b4a1b9 100644 --- a/pkg/ns1/api_test.go +++ b/pkg/ns1/api_test.go @@ -20,7 +20,7 @@ import ( "regexp" "testing" - "github.com/prometheus/common/promlog" + "github.com/prometheus/common/promslog" "github.com/stretchr/testify/require" "gopkg.in/ns1/ns1-go.v2/mockns1" api "gopkg.in/ns1/ns1-go.v2/rest" @@ -28,7 +28,7 @@ import ( ) var ( - mockLogger = promlog.New(&promlog.Config{}) + mockLogger = promslog.New(&promslog.Config{}) ) func TestRefreshZoneData(t *testing.T) { diff --git a/pkg/servicediscovery/sd.go b/pkg/servicediscovery/sd.go index 8fb46b8..d256e7d 100644 --- a/pkg/servicediscovery/sd.go +++ b/pkg/servicediscovery/sd.go @@ -17,6 +17,7 @@ package servicediscovery import ( "encoding/json" "fmt" + "log/slog" "net/http" "regexp" "sort" @@ -24,8 +25,6 @@ import ( "strings" "time" - "github.com/go-kit/log" - "github.com/go-kit/log/level" promModel "github.com/prometheus/common/model" "github.com/samber/lo" api "gopkg.in/ns1/ns1-go.v2/rest" @@ -69,7 +68,7 @@ type Worker struct { ZoneWhitelist *regexp.Regexp RecordTypeWhitelist *regexp.Regexp - logger log.Logger + logger *slog.Logger client *api.Client zoneCache map[string]*ns1_internal.Zone recordCache []*dns.Record @@ -78,13 +77,13 @@ type Worker struct { pollCount int } -func NewWorker(logger log.Logger, client *api.Client, blacklist, whitelist, recordType *regexp.Regexp) *Worker { +func NewWorker(logger *slog.Logger, client *api.Client, blacklist, whitelist, recordType *regexp.Regexp) *Worker { worker := Worker{ client: client, ZoneBlacklist: blacklist, ZoneWhitelist: whitelist, RecordTypeWhitelist: recordType, - logger: log.With(logger, "worker", "http_sd"), + logger: logger.With("worker", "http_sd"), } return &worker @@ -234,7 +233,7 @@ func (w *Worker) RefreshPrometheusTargetData() { } w.targetCache = data - level.Debug(w.logger).Log("msg", "Worker Prometheus target group updated", "num_targets", len(w.targetCache)) + w.logger.Debug("Worker Prometheus target group updated", "num_targets", len(w.targetCache)) } func (w *Worker) RefreshZoneData() { @@ -251,7 +250,7 @@ func (w *Worker) RefreshRecordData() { for _, r := range zData.Records { if !w.RecordTypeWhitelist.MatchString(r.Type) { // if record type not in whitelist, log it and skip it - level.Debug(w.logger).Log("msg", "skipping record because it doesn't match whitelist regex", "record", r.Domain, "record_type_regex", w.RecordTypeWhitelist.String()) + w.logger.Debug("skipping record because it doesn't match whitelist regex", "record", r.Domain, "record_type_regex", w.RecordTypeWhitelist.String()) continue } filteredRecords = append(filteredRecords, r) @@ -261,10 +260,10 @@ func (w *Worker) RefreshRecordData() { } for _, r := range zData.Records { - level.Debug(w.logger).Log("msg", "Refreshing record data from NS1 API", "zone_name", zName, "record_domain", r.Domain, "record_type", r.Type) + w.logger.Debug("Refreshing record data from NS1 API", "zone_name", zName, "record_domain", r.Domain, "record_type", r.Type) record, _, err := w.client.Records.Get(zData.Zone, r.Domain, r.Type) if err != nil { - level.Error(w.logger).Log("msg", "Failed to get record data from NS1 API", "err", err.Error(), "zone_name", zName, "record_domain", r.Domain, "record_type", r.Type) + w.logger.Error("Failed to get record data from NS1 API", "err", err, "zone_name", zName, "record_domain", r.Domain, "record_type", r.Type) metrics.MetricExporterNS1APIFailures.Inc() continue } @@ -273,14 +272,14 @@ func (w *Worker) RefreshRecordData() { } w.recordCache = records - level.Debug(w.logger).Log("msg", "Worker record cache updated", "num_records", len(w.recordCache)) + w.logger.Debug("Worker record cache updated", "num_records", len(w.recordCache)) } func (w *Worker) RefreshData() { - level.Info(w.logger).Log("msg", "Updating record data from NS1 API") + w.logger.Info("Updating record data from NS1 API") w.RefreshZoneData() w.RefreshRecordData() - level.Info(w.logger).Log("msg", "Updating prometheus target data from cached record data") + w.logger.Info("Updating prometheus target data from cached record data") w.RefreshPrometheusTargetData() } @@ -294,10 +293,10 @@ func (w *Worker) Refresh() { {Key: "start", Value: strconv.FormatInt(w.lastRefreshTimestamp.Unix(), 10)}, {Key: "limit", Value: "1000"}, } - level.Debug(w.logger).Log("msg", "Refreshing account activity from NS1 API") + w.logger.Debug("Refreshing account activity from NS1 API") activity, _, err := w.client.Activity.List(params...) if err != nil { - level.Error(w.logger).Log("msg", "Failed to get account activity from NS1 API", "err", err.Error()) + w.logger.Error("Failed to get account activity from NS1 API", "err", err) metrics.MetricExporterNS1APIFailures.Inc() } w.pollCount++ @@ -335,7 +334,7 @@ func (w *Worker) Refresh() { func (w *Worker) ServeHTTP(writer http.ResponseWriter, req *http.Request) { buf, err := json.MarshalIndent(w.targetCache, "", " ") if err != nil { - level.Error(w.logger).Log("msg", "Failed to convert DNS records from NS1 API into Prometheus Targets", "err", err.Error()) + w.logger.Error("Failed to convert DNS records from NS1 API into Prometheus Targets", "err", err) http.Error(writer, err.Error(), http.StatusInternalServerError) return } @@ -343,6 +342,6 @@ func (w *Worker) ServeHTTP(writer http.ResponseWriter, req *http.Request) { writer.Header().Set("content-type", "application/json; charset=utf-8") writer.WriteHeader(http.StatusOK) if bytesWritten, err := writer.Write(buf); err != nil { - level.Error(w.logger).Log("msg", "Failed to write full HTTP response", "err", err.Error(), "bytes", bytesWritten) + w.logger.Error("Failed to write full HTTP response", "err", err, "bytes", bytesWritten) } } diff --git a/pkg/servicediscovery/sd_test.go b/pkg/servicediscovery/sd_test.go index 0e60da6..e23defa 100644 --- a/pkg/servicediscovery/sd_test.go +++ b/pkg/servicediscovery/sd_test.go @@ -26,7 +26,7 @@ import ( "time" promModel "github.com/prometheus/common/model" - "github.com/prometheus/common/promlog" + "github.com/prometheus/common/promslog" "github.com/stretchr/testify/require" "gopkg.in/ns1/ns1-go.v2/mockns1" api "gopkg.in/ns1/ns1-go.v2/rest" @@ -38,7 +38,7 @@ import ( ) var ( - mockLogger = promlog.New(&promlog.Config{}) + mockLogger = promslog.New(&promslog.Config{}) mockZoneCache = map[string]*ns1_internal.Zone{ "foo.bar": {Zone: "foo.bar", Records: []*ns1_internal.ZoneRecord{