Skip to content

Commit

Permalink
Merge pull request #21 from controllan/dependabot/go_modules/github.c…
Browse files Browse the repository at this point in the history
…om/prometheus/exporter-toolkit-0.13.0

chore(deps): bump github.com/prometheus/exporter-toolkit from 0.10.0 to 0.13.0
  • Loading branch information
pat-git authored Oct 6, 2024
2 parents bd7ec97 + 2a5a40d commit 3890a63
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 324 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@ build/
### Direnv
.direnv/

.idea
.idea

# Binary files
docker_state_exporter

# go sum file
go.sum
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ RUN apk update && apk add \
git \
ca-certificates

COPY *.go go.mod go.sum $GOPATH/src/docker_state_exporter/
COPY *.go go.mod $GOPATH/src/docker_state_exporter/

WORKDIR $GOPATH/src/docker_state_exporter/

RUN go mod tidy
RUN go mod vendor -v
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -installsuffix cgo -ldflags="-w -s" -o /go/bin/docker_state_exporter

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ For Docker compose.

```yaml
---
version: '3.8'
services:
docker_state_exporter:
image: ghcr.io/controllan/docker-state-exporter:latest
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
version: '3.8'
services:
docker_state_exporter:
image: ${IMAGE_TAG:-ghcr.io/controllan/docker-state-exporter:latest}
Expand Down
21 changes: 10 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ toolchain go1.23.1
require (
github.com/alecthomas/kingpin/v2 v2.4.0
github.com/docker/docker v27.3.1+incompatible
github.com/go-kit/log v0.2.1
github.com/prometheus/client_golang v1.20.4
github.com/prometheus/exporter-toolkit v0.10.0
github.com/prometheus/exporter-toolkit v0.13.0
)

require (
Expand All @@ -23,14 +22,14 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mdlayher/socket v0.4.1 // indirect
github.com/mdlayher/vsock v1.2.1 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
Expand All @@ -40,7 +39,7 @@ require (
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/common v0.58.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
Expand All @@ -50,12 +49,12 @@ require (
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/sdk v1.3.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // 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.26.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.34.2 // indirect
Expand Down
287 changes: 0 additions & 287 deletions go.sum

This file was deleted.

33 changes: 11 additions & 22 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"log/slog"
"net/http"
"os"
"os/signal"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/docker/docker/api/types/container"
tcontainer "github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -173,7 +173,7 @@ func (c *dockerHealthCollector) collectContainers() {
// Collect metrics for each container
info, err := c.containerClient.ContainerInspect(context.Background(), container.ID)
if err != nil {
errorLogger.Log("message", err)
errorLogger.Error(err.Error())
continue
}
// Append container name to known list of container names
Expand All @@ -192,23 +192,15 @@ func (c *dockerHealthCollector) collectContainers() {
}
}

type loggerWrapper struct {
Logger *log.Logger
}

func (l *loggerWrapper) Println(v ...interface{}) {
(*l.Logger).Log("messages", v)
}

// Define loggers.
var (
normalLogger = log.NewJSONLogger(log.NewSyncWriter(os.Stdout))
errorLogger = log.NewJSONLogger(log.NewSyncWriter(os.Stderr))
normalLogger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
errorLogger = slog.New(slog.NewJSONHandler(os.Stderr, nil))
)

func errCheck(err error) {
if err != nil {
errorLogger.Log("message", err)
errorLogger.Error(err.Error())
os.Exit(1)
}
}
Expand All @@ -219,10 +211,6 @@ var (
)

func init() {
normalLogger = log.With(normalLogger, "timestamp", log.DefaultTimestampUTC)
normalLogger = log.With(normalLogger, "severity", "info")
errorLogger = log.With(errorLogger, "timestamp", log.DefaultTimestampUTC)
errorLogger = log.With(errorLogger, "severity", "error")
prometheus.MustRegister(collectors.NewBuildInfoCollector())
}

Expand All @@ -239,7 +227,7 @@ func main() {

_, err = client.Ping(context.Background())
errCheck(err)
normalLogger.Log("message", fmt.Sprintf("Cache period is set to %v", *cachePeriod))
normalLogger.Info(fmt.Sprintf("Cache period is set to %v", *cachePeriod))

prometheus.MustRegister(&dockerHealthCollector{
containerClient: client,
Expand All @@ -255,7 +243,8 @@ func main() {

http.Handle("/metrics", promhttp.HandlerFor(
prometheus.DefaultGatherer,
promhttp.HandlerOpts{ErrorLog: &loggerWrapper{Logger: &errorLogger}, EnableOpenMetrics: true}))
promhttp.HandlerOpts{ErrorLog: slog.NewLogLogger(normalLogger.Handler(), slog.LevelError),
ErrorHandling: promhttp.ContinueOnError, EnableOpenMetrics: true}))

server := &http.Server{}

Expand All @@ -269,12 +258,12 @@ func main() {
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGTERM, os.Interrupt)
<-quit
normalLogger.Log("message", "Server shutting down...")
normalLogger.Info("Server shutting down...")

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
errorLogger.Log("message", fmt.Sprintf("Failed to gracefully shutdown: %d", err))
errorLogger.Error(fmt.Sprintf("Failed to gracefully shutdown: %d", err))
}
normalLogger.Log("message", "Server shutdown")
normalLogger.Info("Server shutdown")
}

0 comments on commit 3890a63

Please sign in to comment.