Skip to content

Commit

Permalink
Bump github.com/prometheus/exporter-toolkit from 0.12.0 to 0.13.0
Browse files Browse the repository at this point in the history
Bumps [github.com/prometheus/exporter-toolkit](https://github.com/prometheus/exporter-toolkit) from 0.12.0 to 0.13.0.
- [Release notes](https://github.com/prometheus/exporter-toolkit/releases)
- [Changelog](https://github.com/prometheus/exporter-toolkit/blob/master/CHANGELOG.md)
- [Commits](prometheus/exporter-toolkit@v0.12.0...v0.13.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/exporter-toolkit
dependency-type: direct:production
update-type: version-update:semver-minor
...
  • Loading branch information
agebhar1 committed Oct 3, 2024
1 parent 1f140a3 commit 5746736
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 68 deletions.
13 changes: 6 additions & 7 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ package collector

import (
"context"
"log/slog"
"sync"
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -56,7 +55,7 @@ type QueueMetrics struct {

type QueueCollector struct {
sync.Mutex
logger log.Logger
logger *slog.Logger
timeout time.Duration
queues []Queue

Expand All @@ -77,7 +76,7 @@ func (m *QueueMetadata) prometheusLabelValues() []string {
}
}

func NewQueueCollector(logger log.Logger, timeout time.Duration, queues []Queue) *QueueCollector {
func NewQueueCollector(logger *slog.Logger, timeout time.Duration, queues []Queue) *QueueCollector {

newQueueMetric := func(name string, help string) *prometheus.GaugeVec {
return prometheus.NewGaugeVec(prometheus.GaugeOpts{
Expand Down Expand Up @@ -150,7 +149,7 @@ func (c *QueueCollector) Collect(ch chan<- prometheus.Metric) {
c.requestDuration.Collect(ch)
}

func collect(logger log.Logger, timeout time.Duration, queues []Queue, ctx context.Context) *[]QueueMetrics {
func collect(logger *slog.Logger, timeout time.Duration, queues []Queue, ctx context.Context) *[]QueueMetrics {

metrics := make([]QueueMetrics, 0)

Expand All @@ -176,11 +175,11 @@ func collect(logger log.Logger, timeout time.Duration, queues []Queue, ctx conte
for {
select {
case metric := <-ch:
level.Debug(logger).Log("msg", "Got queue metrics", "queue", metric.Metadata.QueueName, "connection", metric.Metadata.ConnectionName, "queue_manager", metric.Metadata.QMgrName, "channel", metric.Metadata.ChannelName)
logger.Debug("Got queue metrics", "queue", metric.Metadata.QueueName, "connection", metric.Metadata.ConnectionName, "queue_manager", metric.Metadata.QMgrName, "channel", metric.Metadata.ChannelName)
metrics = append(metrics, metric)
case <-ctx.Done():
if ctx.Err() == context.DeadlineExceeded {
level.Error(logger).Log("msg", "Deadline exceeded while waiting for queue metrics", "timeout", timeout)
logger.Error("Deadline exceeded while waiting for queue metrics", "timeout", timeout)
}
return &metrics
}
Expand Down
5 changes: 3 additions & 2 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ package collector
import (
"context"
"errors"
"io"
"log/slog"
"runtime"
"strings"
"testing"
"time"

"github.com/go-kit/log"
"github.com/google/go-cmp/cmp"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
)

var logger = log.NewNopLogger()
var logger = slog.New(slog.NewTextHandler(io.Discard, nil))

type succeedingQueueMetricReader struct {
value QueueMetrics
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ module github.com/agebhar1/mq_exporter

require (
github.com/alecthomas/kingpin/v2 v2.4.0
github.com/go-kit/log v0.2.1
github.com/google/go-cmp v0.6.0
github.com/ibm-messaging/mq-golang/v5 v5.6.0
github.com/prometheus/client_golang v1.20.4
github.com/prometheus/common v0.60.0
github.com/prometheus/exporter-toolkit v0.12.0
github.com/prometheus/exporter-toolkit v0.13.0
gopkg.in/yaml.v2 v2.4.0
gotest.tools/v3 v3.5.1
)
Expand All @@ -17,7 +16,6 @@ require (
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/go-logfmt/logfmt v0.5.1 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/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.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
github.com/go-logfmt/logfmt v0.5.1/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=
Expand Down Expand Up @@ -46,8 +42,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA=
github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw=
github.com/prometheus/exporter-toolkit v0.12.0 h1:DkE5RcEZR3lQA2QD5JLVQIf41dFKNsVMXFhgqcif7fo=
github.com/prometheus/exporter-toolkit v0.12.0/go.mod h1:fQH0KtTn0yrrS0S82kqppRjDDiwMfIQUwT+RBRRhwUc=
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=
Expand Down
31 changes: 13 additions & 18 deletions mq/mq.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ package mq

import (
"fmt"
"log/slog"
"os"
"strings"
"sync/atomic"
"time"

"github.com/agebhar1/mq_exporter/collector"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/ibm-messaging/mq-golang/v5/ibmmq"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -113,12 +112,12 @@ func (cfg *MqConfiguration) validateReadFromYaml() error {
type MqConnection struct {
isConnecting *int64
cfg *MqConfiguration
logger log.Logger
logger *slog.Logger
qMgr ibmmq.MQQueueManager
queues map[string]ibmmq.MQObject
}

func NewMqConnection(logger log.Logger, cfgFilename string) (*MqConnection, error) {
func NewMqConnection(logger *slog.Logger, cfgFilename string) (*MqConnection, error) {

cfg, err := readConfigYaml(cfgFilename)
if err != nil {
Expand All @@ -131,7 +130,7 @@ func NewMqConnection(logger log.Logger, cfgFilename string) (*MqConnection, erro
c := MqConnection{
isConnecting: new(int64),
cfg: cfg,
logger: log.WithSuffix(logger, "connName", cfg.ConnName, "channel", cfg.Channel, "queueManager", cfg.QueueManager),
logger: logger.With("connName", cfg.ConnName, "channel", cfg.Channel, "queueManager", cfg.QueueManager),
}
*c.isConnecting = NO

Expand All @@ -150,7 +149,7 @@ func (c *MqConnection) connect() error {
}
defer func() {
atomic.StoreInt64(c.isConnecting, NO)
level.Info(c.logger).Log("msg", "connected to queue manager")
c.logger.Info("connected to queue manager")
}()

if len(c.cfg.Queues) > 0 {
Expand Down Expand Up @@ -208,7 +207,7 @@ func (c *MqConnection) handleReturnValue(mqret *ibmmq.MQReturn) {
go func() {
err := c.connect()
if err != nil {
level.Error(c.logger).Log("msg", "failed re-connect", "err", err)
c.logger.Error("failed re-connect", "err", err)
}
}()
}
Expand Down Expand Up @@ -240,7 +239,7 @@ func (c *MqConnection) Queues() []collector.Queue {
Metadata: metadata,
Reader: &MqQueue{
connection: c,
logger: log.WithSuffix(c.logger, "queue", queue),
logger: c.logger.With("queue", queue),
metadata: metadata,
},
})
Expand All @@ -249,23 +248,19 @@ func (c *MqConnection) Queues() []collector.Queue {
}

func (c *MqConnection) Close() {

logInfo := level.Info(c.logger).Log
logError := level.Error(c.logger).Log

for _, queue := range c.queues {
err := queue.Close(0)
if err == nil {
logInfo("msg", "closed queue", "queue", queue.Name)
c.logger.Info("closed queue", "queue", queue.Name)
} else {
logError("msg", "failed to close queue", "err", err, "queue", queue.Name)
c.logger.Error("failed to close queue", "err", err, "queue", queue.Name)
}
}
err := c.qMgr.Disc()
if err == nil {
logInfo("msg", "disconnected from queue manager")
c.logger.Info("disconnected from queue manager")
} else {
logError("msg", "failed to disconnect from queue manager", "err", err)
c.logger.Error("failed to disconnect from queue manager", "err", err)
}
}

Expand All @@ -275,7 +270,7 @@ func (c *MqConnection) Timeout() time.Duration {

type MqQueue struct {
connection *MqConnection
logger log.Logger
logger *slog.Logger
metadata collector.QueueMetadata
}

Expand All @@ -284,7 +279,7 @@ func (q *MqQueue) Read() (collector.QueueMetrics, error) {
values, err := q.connection.inqQueue(q, selectors)
if err != nil {
err := err.(*ibmmq.MQReturn)
level.Error(q.logger).Log("msg", "error inquire queue", "err", err, "mqcc", err.MQCC, "mqcr", err.MQRC)
q.logger.Error("error inquire queue", "err", err, "mqcc", err.MQCC, "mqcr", err.MQRC)
return collector.QueueMetrics{}, err
}
return collector.QueueMetrics{
Expand Down
30 changes: 13 additions & 17 deletions mq_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ package main
import (
"context"
versionc "github.com/prometheus/client_golang/prometheus/collectors/version"
"github.com/prometheus/common/promslog"
"github.com/prometheus/common/promslog/flag"
"io"
"log/slog"
"net/http"
"os"
"os/signal"
Expand All @@ -26,13 +29,9 @@ import (
"github.com/agebhar1/mq_exporter/collector"
"github.com/agebhar1/mq_exporter/mq"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
"github.com/prometheus/common/version"
"github.com/prometheus/exporter-toolkit/web"
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
Expand All @@ -41,15 +40,15 @@ import (
var name = "mq_exporter"

type appCtx struct {
logger log.Logger
logger *slog.Logger
sigs chan os.Signal

configFile *string
toolkitFlags *web.FlagConfig
webTelemetryPath *string
}

func newAppCtx(args []string, usageWriter io.Writer, errorWriter io.Writer, logger log.Logger) *appCtx {
func newAppCtx(args []string, usageWriter io.Writer, errorWriter io.Writer, logger *slog.Logger) *appCtx {

ctx := appCtx{}

Expand All @@ -64,15 +63,15 @@ func newAppCtx(args []string, usageWriter io.Writer, errorWriter io.Writer, logg
app.HelpFlag.Short('h')
app.VersionFlag.Short('v')

promlogConfig := &promlog.Config{}
flag.AddFlags(app, promlogConfig)
promslogConfig := &promslog.Config{Style: promslog.GoKitStyle}
flag.AddFlags(app, promslogConfig)

kingpin.MustParse(app.Parse(args))

if logger != nil {
ctx.logger = logger
} else {
ctx.logger = promlog.New(promlogConfig)
ctx.logger = promslog.New(promslogConfig)
}

ctx.sigs = make(chan os.Signal)
Expand All @@ -83,11 +82,8 @@ func newAppCtx(args []string, usageWriter io.Writer, errorWriter io.Writer, logg

func (app *appCtx) run() int {

logInfo := level.Info(app.logger).Log
logError := level.Error(app.logger).Log

logInfo("msg", "Starting", "app_name", name, "version", version.Version, "branch", version.Branch, "revision", version.Revision)
logInfo("msg", "Build context", "go", version.GoVersion, "build_user", version.BuildUser, "build_date", version.BuildDate)
app.logger.Info("Starting", "app_name", name, "version", version.Version, "branch", version.Branch, "revision", version.Revision)
app.logger.Info("Build context", "go", version.GoVersion, "build_user", version.BuildUser, "build_date", version.BuildDate)

reg := prometheus.NewRegistry()
reg.MustRegister(versionc.NewCollector(name))
Expand All @@ -96,7 +92,7 @@ func (app *appCtx) run() int {

mqConnection, err := mq.NewMqConnection(app.logger, *app.configFile)
if err != nil {
logError("msg", err)
app.logger.Error(err.Error())
return 1
}

Expand Down Expand Up @@ -128,12 +124,12 @@ func (app *appCtx) run() int {

mqConnection.Close()

logInfo("msg", "Shutdown server.")
app.logger.Info("Shutdown server.")
server.Shutdown(context.Background())
}()

if err := web.ListenAndServe(server, app.toolkitFlags, app.logger); err != http.ErrServerClosed {
logError("msg", "Serve error", "err", err)
app.logger.Error("Serve error", "err", err)
return 2
}
return 0
Expand Down
Loading

0 comments on commit 5746736

Please sign in to comment.