Skip to content

Commit

Permalink
feat: new Prometheus metrics build_info (#3144)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
  • Loading branch information
nlamirault committed May 29, 2024
1 parent 2bcb845 commit 6d71abd
Showing 1 changed file with 21 additions and 0 deletions.
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)
}

0 comments on commit 6d71abd

Please sign in to comment.