Skip to content

Commit

Permalink
feat: New Prometheus metric: build_info (#3591)
Browse files Browse the repository at this point in the history
* new Prometheus metrics build_info

Signed-off-by: Nicolas Lamirault <[email protected]>

* fix: gofmt

Signed-off-by: Nicolas Lamirault <[email protected]>

---------

Signed-off-by: Nicolas Lamirault <[email protected]>
  • Loading branch information
nlamirault authored Dec 6, 2024
1 parent c335003 commit b3356a2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions controller/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metrics

import (
"net/http"
"runtime"
"time"

"github.com/argoproj/argo-rollouts/utils/defaults"
Expand All @@ -16,6 +17,7 @@ import (
"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
rolloutlister "github.com/argoproj/argo-rollouts/pkg/client/listers/rollouts/v1alpha1"
"github.com/argoproj/argo-rollouts/utils/log"
"github.com/argoproj/argo-rollouts/utils/version"
)

type MetricsServer struct {
Expand All @@ -39,6 +41,16 @@ const (
MetricsPath = "/metrics"
)

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

type ServerConfig struct {
Addr string
RolloutLister rolloutlister.RolloutLister
Expand Down Expand Up @@ -74,6 +86,9 @@ func NewMetricsServer(cfg ServerConfig) *MetricsServer {
reg.MustRegister(MetricNotificationFailedTotal)
reg.MustRegister(MetricNotificationSend)
reg.MustRegister(MetricVersionGauge)
reg.MustRegister(buildInfo)

recordBuildInfo()

mux.Handle(MetricsPath, promhttp.HandlerFor(prometheus.Gatherers{
// contains app controller specific metrics
Expand Down Expand Up @@ -174,6 +189,12 @@ func (m *MetricsServer) Remove(namespace string, name string, kind string) {

}

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

func boolFloat64(b bool) float64 {
if b {
return 1
Expand Down

0 comments on commit b3356a2

Please sign in to comment.