Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump github.com/prometheus/exporter-toolkit from 0.11.0 to 0.13.0 #322

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ dns names or ip addresses when configuring the CouchDB URI.

## Logging

The couchdb-exporter uses the [glog](https://godoc.org/github.com/golang/glog) library for logging.
With the default parameters everything will be logged to `/tmp/`.
Use `--logtostderr` to enable logging to stderr and `--help` to see all options.
The couchdb-exporter uses the [slog](https://pkg.go.dev/golang.org/x/exp/slog) module for logging.

## CouchDB 2+ clusters

Expand Down
91 changes: 12 additions & 79 deletions couchdb-exporter.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package main

import (
"flag"
"fmt"
"github.com/gesellix/couchdb-prometheus-exporter/v30/kitlog"
"log"
"log/slog"
"net/http"
"os"
"strconv"
"strings"
"time"

Expand All @@ -16,7 +14,6 @@ import (
"github.com/prometheus/exporter-toolkit/web"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
"k8s.io/klog/v2"

"github.com/gesellix/couchdb-prometheus-exporter/v30/fileutil"
"github.com/gesellix/couchdb-prometheus-exporter/v30/lib"
Expand Down Expand Up @@ -45,23 +42,12 @@ type exporterConfigType struct {
schedulerJobs bool
}

type loggingConfigType struct {
toStderr bool // The -logtostderr flag.
alsoToStderr bool // The -alsologtostderr flag.
verbosity int // V logging level, the value of the -v flag/
stderrThreshold int // The -stderrthreshold flag.
logDir string // The -log_dir flag.
}

var exporterConfig exporterConfigType
var webConfig webConfigType

var configFileFlagname = "config"
var webConfigFile = ""

// custom exposed (but hidden) logging config flags
var loggingConfig loggingConfigType

var appFlags []cli.Flag

// TODO graceful migration to new parameter names
Expand Down Expand Up @@ -171,41 +157,6 @@ func init() {
Hidden: false,
Destination: &exporterConfig.schedulerJobs,
}),

altsrc.NewBoolFlag(&cli.BoolFlag{
Name: "logtostderr",
Usage: "log to standard error instead of files",
Hidden: true,
Value: true,
Destination: &loggingConfig.toStderr,
}),
altsrc.NewBoolFlag(&cli.BoolFlag{
Name: "alsologtostderr",
Usage: "log to standard error as well as files",
Hidden: true,
Destination: &loggingConfig.alsoToStderr,
}),
// TODO `v` clashed with urfave/cli's "version" shortcut `-v`.
altsrc.NewIntFlag(&cli.IntFlag{
Name: "verbosity",
Usage: "log level for V logs",
Value: 0,
Hidden: true,
Destination: &loggingConfig.verbosity,
}),
altsrc.NewIntFlag(&cli.IntFlag{
Name: "stderrthreshold",
Usage: "logs at or above this threshold go to stderr",
Value: 2,
Hidden: true,
Destination: &loggingConfig.stderrThreshold,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "log_dir",
Usage: "If non-empty, write log files in this directory",
Hidden: true,
Destination: &loggingConfig.logDir,
}),
}
}

Expand All @@ -217,6 +168,9 @@ func ofString(i string) *string {
}

func main() {
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
gesellix marked this conversation as resolved.
Show resolved Hide resolved
slog.SetDefault(logger)

var appAction = func(c *cli.Context) error {
var databases []string
if exporterConfig.databases != "" {
Expand All @@ -242,7 +196,7 @@ func main() {
http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
_, err := fmt.Fprint(w, "OK")
if err != nil {
klog.Error(err)
slog.Error(fmt.Sprintf("%v", err))
}
})
redirectToMetricsHandler := func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -256,7 +210,7 @@ func main() {
</body>
</html>`))
if err != nil {
klog.Error(err)
slog.Error(fmt.Sprintf("%v", err))
}
}
landingPageHandler, err := web.NewLandingPage(web.LandingConfig{
Expand Down Expand Up @@ -293,15 +247,15 @@ func main() {
http.HandleFunc("/", landingPageHandler.ServeHTTP)
}

klog.Infof("Starting exporter version %s at '%s' to read from CouchDB at '%s'", version, webConfig.listenAddress, exporterConfig.couchdbURI)
slog.Info(fmt.Sprintf("Starting exporter version %s at '%s' to read from CouchDB at '%s'", version, webConfig.listenAddress, exporterConfig.couchdbURI))
server := &http.Server{Addr: webConfig.listenAddress}
flags := web.FlagConfig{
WebListenAddresses: &([]string{webConfig.listenAddress}),
WebSystemdSocket: ofBool(false),
WebConfigFile: ofString(webConfigFile),
}
if err := web.ListenAndServe(server, &flags, kitlog.NewKlogLogger()); err != nil {
klog.Error("msg", "Failed to start the server", "err", err)
if err := web.ListenAndServe(server, &flags, logger); err != nil {
slog.Error("Failed to start the server", "err", err)
os.Exit(1)
}
return nil
Expand All @@ -316,11 +270,11 @@ func main() {
app.Before = beforeApp(appFlags)
app.Action = appAction

defer klog.Flush()
//defer klog.Flush()

err := app.Run(os.Args)
if err != nil {
klog.Fatal(err)
slog.Error(fmt.Sprintf("%v", err))
}
}

Expand All @@ -333,27 +287,6 @@ func beforeApp(appFlags []cli.Flag) cli.BeforeFunc {
if err := altsrc.InitInputSourceWithContext(appFlags, inputSource)(context); err != nil {
return err
}
return initKlogFlags(context, loggingConfig)
}
}

func initKlogFlags(_ *cli.Context, loggingConfig loggingConfigType) error {
klogFlags := flag.NewFlagSet("klog", flag.ContinueOnError)
klog.InitFlags(klogFlags)

flags := map[string]string{
"logtostderr": strconv.FormatBool(loggingConfig.toStderr),
"alsologtostderr": strconv.FormatBool(loggingConfig.alsoToStderr),
"stderrthreshold": strconv.Itoa(loggingConfig.stderrThreshold),
"v": strconv.Itoa(loggingConfig.verbosity),
"log_dir": loggingConfig.logDir,
}
for k, v := range flags {
if err := klogFlags.Set(k, v); err != nil {
return err
}
return nil
}

klog.Infof("adopted logging config: %+v\n", loggingConfig)
return nil
}
22 changes: 10 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ toolchain go1.22.3

require (
github.com/gesellix/couchdb-cluster-config/v17 v17.5.0
github.com/go-kit/log v0.2.1
github.com/okeuday/erlang_go/v2 v2.0.7
github.com/prometheus/client_golang v1.20.5
github.com/prometheus/client_model v0.6.1
github.com/prometheus/exporter-toolkit v0.11.0
github.com/prometheus/exporter-toolkit v0.13.1
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.5
google.golang.org/protobuf v1.35.1
k8s.io/klog/v2 v2.130.1
)

require (
Expand All @@ -24,23 +22,23 @@ require (
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mdlayher/socket v0.4.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.0 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/common v0.60.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/crypto v0.28.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.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
44 changes: 20 additions & 24 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gesellix/couchdb-cluster-config/v17 v17.5.0 h1:ukaf1x2dnOb9Io04y9m/jcZdRSMAUujzylHi9IhNWVs=
github.com/gesellix/couchdb-cluster-config/v17 v17.5.0/go.mod h1:d7cV9fN1NZkZxLOdNA1dyrDviHJ4oWVQ/W8O8nA/EAQ=
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/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
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=
Expand All @@ -31,6 +25,10 @@ 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.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
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=
Expand All @@ -43,10 +41,10 @@ github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+
github.com/prometheus/client_golang v1.20.5/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/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.60.1 h1:FUas6GcOw66yB/73KC+BOZoFJmbo/1pojoILArPAaSc=
github.com/prometheus/common v0.60.1/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw=
github.com/prometheus/exporter-toolkit v0.13.1 h1:Evsh0gWQo2bdOHlnz9+0Nm7/OFfIwhE2Ws4A2jIlR04=
github.com/prometheus/exporter-toolkit v0.13.1/go.mod h1:ujdv2YIOxtdFxxqtloLpbqmxd5J0Le6IITUvIRSWjj0=
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=
Expand All @@ -59,18 +57,18 @@ github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
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.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand All @@ -80,5 +78,3 @@ 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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
22 changes: 0 additions & 22 deletions kitlog/klog_logger.go

This file was deleted.

60 changes: 0 additions & 60 deletions kitlog/klog_logger_test.go

This file was deleted.

Loading
Loading