Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new Prometheus metrics build_info #3558

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cmd/dex/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Loading