Skip to content

Commit

Permalink
ROX-15587: Add basic Prometheus metrics (#1220)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom Martensen <tmartens@redhat.com>
  • Loading branch information
BradLugo and tommartensen authored Mar 13, 2024
1 parent a0e9821 commit 56941f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions service/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"sync"
"time"

"github.com/stackrox/infra/service/metrics"

argov3client "github.com/argoproj/argo-workflows/v3/cmd/argo/commands/client"
"github.com/argoproj/argo-workflows/v3/pkg/apiclient"
workflowpkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflow"
Expand Down Expand Up @@ -416,6 +418,8 @@ func (s *clusterImpl) create(req *v1.CreateClusterRequest, owner, eventID string
"cluster-id", clusterID,
)

metrics.FlavorsUsedCounter.WithLabelValues(flav.ID).Inc()

err = s.bqClient.InsertClusterCreationRecord(context.Background(), clusterID, created.GetName(), flav.GetID(), owner)
if err != nil {
log.Log(logging.WARN, "failed to record cluster creation", "cluster-id", clusterID, "error", err)
Expand Down
20 changes: 20 additions & 0 deletions service/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package metrics

import "github.com/prometheus/client_golang/prometheus"

var (
// FlavorsUsedCounter is a Prometheus metric, counting the number of clusters created per flavor
FlavorsUsedCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "infra",
Name: "flavors_used",
Help: "Number of clusters created by flavor",
},
[]string{"flavor"},
)
)

func init() {
// Metrics have to be registered to be exposed:
prometheus.MustRegister(FlavorsUsedCounter)
}

0 comments on commit 56941f0

Please sign in to comment.