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 #3144

Merged
merged 1 commit into from
May 29, 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
21 changes: 21 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package metrics
import (
"context"
"net/http"
"runtime"

"github.com/prometheus/client_golang/prometheus/collectors"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"

argoevents "github.com/argoproj/argo-events"
"github.com/argoproj/argo-events/common/logging"
)

Expand All @@ -23,6 +25,16 @@ const (
labelTriggerName = "trigger_name"
)

var (
buildInfo = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "build_info",
Help: "A metric with a constant '1' value labeled by version from which Argo-Events was built.",
},
[]string{"version", "goversion", "goarch", "commit"},
)
)

// Metrics represents EventSource metrics information
type Metrics struct {
namespace string
Expand Down Expand Up @@ -170,10 +182,19 @@ func (m *Metrics) Run(ctx context.Context, addr string) {
log := logging.FromContext(ctx)
metricsRegistry := prometheus.NewRegistry()
metricsRegistry.MustRegister(collectors.NewGoCollector(), m)
metricsRegistry.MustRegister(buildInfo)
recordBuildInfo()

http.Handle("/metrics", promhttp.HandlerFor(metricsRegistry, promhttp.HandlerOpts{}))

log.Info("starting metrics server")
if err := http.ListenAndServe(addr, nil); err != nil {
log.Fatalw("failed to start metrics server", zap.Error(err))
}
}

// recordBuildInfo publishes information about Argo-Rollouts version and runtime info through an info metric (gauge).
func recordBuildInfo() {
vers := argoevents.GetVersion()
buildInfo.WithLabelValues(vers.Version, runtime.Version(), runtime.GOARCH, vers.GitCommit).Set(1)
}