diff --git a/cmd/dex/serve.go b/cmd/dex/serve.go index 9461a6220a..851f463aa4 100644 --- a/cmd/dex/serve.go +++ b/cmd/dex/serve.go @@ -51,6 +51,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{} @@ -116,6 +125,10 @@ func runServe(options serveOptions) error { logger.Infof("config issuer: %s", 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) @@ -707,3 +720,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) +}