Skip to content

Commit

Permalink
new Prometheus metrics build_info (#3558)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Lamirault <[email protected]>
  • Loading branch information
nlamirault authored Jul 15, 2024
1 parent 6fca251 commit bd73825
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/dex/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ type serveOptions struct {
grpcAddr string
}

var buildInfo = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "build_info",
Namespace: "dex",
Help: "A metric with a constant '1' value labeled by version from which Dex was built.",
},
[]string{"version", "go_version", "platform"},
)

func commandServe() *cobra.Command {
options := serveOptions{}

Expand Down Expand Up @@ -117,6 +126,10 @@ func runServe(options serveOptions) error {
logger.Info("config issuer", "issuer", c.Issuer)

prometheusRegistry := prometheus.NewRegistry()

prometheusRegistry.MustRegister(buildInfo)
recordBuildInfo()

err = prometheusRegistry.Register(collectors.NewGoCollector())
if err != nil {
return fmt.Errorf("failed to register Go runtime metrics: %v", err)
Expand Down Expand Up @@ -684,3 +697,8 @@ func loadTLSConfig(certFile, keyFile, caFile string, baseConfig *tls.Config) (*t
}
return loadedConfig, nil
}

// recordBuildInfo publishes information about Dex version and runtime info through an info metric (gauge).
func recordBuildInfo() {
buildInfo.WithLabelValues(version, runtime.Version(), fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)).Set(1)
}

0 comments on commit bd73825

Please sign in to comment.