Skip to content

Commit

Permalink
update mods, switch to slog (#21)
Browse files Browse the repository at this point in the history
* update mods, switch to slog

* update go version/tests
  • Loading branch information
karlhungus authored Aug 20, 2024
1 parent 5f9f245 commit ffa2c5e
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 299 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.21
- name: Set up Go 1.23
uses: actions/setup-go@v1
with:
go-version: 1.21
go-version: 1.23
id: go

- name: Check out code into the Go module directory
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: '1.23'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.54
version: v1.60.1

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
42 changes: 18 additions & 24 deletions cmd/kubelet-summary-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main

import (
"context"
"log/slog"
"net"
"net/http"
"os"
Expand All @@ -20,9 +21,6 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/salesforce/kubelet-summary-exporter/pkg/scraper"
"github.com/salesforce/kubelet-summary-exporter/pkg/utils"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

type CLI struct {
Expand All @@ -40,48 +38,44 @@ func main() {
_ = kong.Parse(cli)
ctx := context.Background()

zapConfig := zap.NewProductionConfig()
zapConfig.EncoderConfig.TimeKey = zapcore.OmitKey
zapConfig.EncoderConfig.MessageKey = "message"
logger := slog.Default().With(slog.String("app", "kubelet-stats-exporter"))

logger, err := zapConfig.Build()
if err != nil {
panic(err)
}
logger = logger.With(zap.String("app", "kubelet-stats-exporter"))

if err := utils.ConfigureTLS(logger, cli.CA, cli.Insecure, cli.NodeHost); err != nil {
logger.Fatal("unable to configure tls", zap.Error(err))
if err := utils.ConfigureTLS(cli.CA, cli.Insecure, cli.NodeHost); err != nil {
logger.Error("unable to configure tls", slog.Any("error", err))
os.Exit(1)
}

if _, err := os.Stat(cli.TokenPath); os.IsNotExist(err) {
logger.Error("token not found", zap.String("file", cli.TokenPath), zap.Error(err))
logger.Error("token not found", slog.String("file", cli.TokenPath), slog.Any("error", err))
}
serverAddr := cli.NodeHost
if cli.LookUpHostname {
//Handle downward API using a node name that isn't identical to the node's Hostname
name, err := utils.ServerAddrFromCluster(cli.NodeHost)
if err != nil {
logger.Fatal("failed to retrieve in node hostname", zap.Error(err))
logger.Error("failed to retrieve in node hostname", slog.Any("error", err))
os.Exit(1)
} else {
serverAddr = name
logger.Info("using updated serverAddr for certificate validation", zap.String("hostname", serverAddr), zap.String("original", cli.NodeHost))
logger.Info("using updated serverAddr for certificate validation", slog.String("hostname", serverAddr), slog.String("original", cli.NodeHost))
}
}
scraper := scraper.NewScraper(logger, serverAddr, cli.TokenPath, cli.Timeout)

promRegistry := prometheus.NewRegistry()
err = promRegistry.Register(scraper)
err := promRegistry.Register(scraper)
if err != nil {
logger.Fatal("failed to register storage metric")
logger.Error("failed to register storage metric")
os.Exit(1)
}

promLis, err := net.Listen("tcp", cli.PromListen)
if err != nil {
logger.Fatal("failed to open prometheus listener",
zap.String("prometheus-listen", cli.PromListen),
zap.Error(err),
logger.Error("failed to open prometheus listener",
slog.String("prometheus-listen", cli.PromListen),
slog.Any("error", err),
)
os.Exit(1)
}

promMux := http.NewServeMux()
Expand All @@ -105,11 +99,11 @@ func main() {
if err := g.Run(); err != nil {
if serr, ok := err.(run.SignalError); ok {
logger.Info("caught signal",
zap.String("signal", serr.Signal.String()),
slog.String("signal", serr.Signal.String()),
)
} else {
logger.Error("actor failed",
zap.Error(err),
slog.Any("error", err),
)

os.Exit(1)
Expand Down
71 changes: 35 additions & 36 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
module github.com/salesforce/kubelet-summary-exporter

go 1.21
go 1.23.0

require (
github.com/alecthomas/kong v0.7.1
github.com/google/go-cmp v0.5.9
github.com/alecthomas/kong v0.9.0
github.com/google/go-cmp v0.6.0
github.com/oklog/run v1.1.0
github.com/prometheus/client_golang v1.14.0
go.uber.org/zap v1.24.0
k8s.io/api v0.26.2
k8s.io/apimachinery v0.26.2
k8s.io/client-go v0.26.2
github.com/prometheus/client_golang v1.20.1
k8s.io/api v0.31.0
k8s.io/apimachinery v0.31.0
k8s.io/client-go v0.31.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.41.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.33.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.6.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230303024457-afdc3dddf62d // indirect
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240816214639-573285566f34 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit ffa2c5e

Please sign in to comment.