Skip to content

Commit

Permalink
ROX-22557: Count expired centrals (#1677)
Browse files Browse the repository at this point in the history
  • Loading branch information
parametalol authored Feb 27, 2024
1 parent 47ba50e commit 106155f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/services"
"github.com/stackrox/acs-fleet-manager/pkg/api"
serviceErr "github.com/stackrox/acs-fleet-manager/pkg/errors"
"github.com/stackrox/acs-fleet-manager/pkg/metrics"
"github.com/stackrox/acs-fleet-manager/pkg/workers"
)

Expand Down Expand Up @@ -112,7 +113,13 @@ func (k *ExpirationDateManager) reconcileCentralExpiredAt(centrals dbapi.Central
}
}
}

expiredInstances := 0
for _, central := range centrals {
if central.ExpiredAt != nil {
expiredInstances++
}
}
metrics.UpdateCentralsExpiredMetric(float64(expiredInstances))
return svcErrors
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (
ClusterOperationsTotalCount = "cluster_operations_total_count"
labelOperation = "operation"

expiredCentralsCount = "expired_centrals_count"

ReconcilerDuration = "reconciler_duration_in_seconds"
ReconcilerSuccessCount = "reconciler_success_count"
ReconcilerFailureCount = "reconciler_failure_count"
Expand Down Expand Up @@ -326,6 +328,20 @@ func UpdateCentralPerClusterCountMetric(clusterID string, clusterExternalID stri
centralPerClusterCountMetric.With(labels).Set(float64(count))
}

// create a new gaugeVec with the total number of expired centrals
var expiredCentralsMetric = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: FleetManager,
Name: expiredCentralsCount,
Help: "total number of expired centrals",
},
[]string{},
)

func UpdateCentralsExpiredMetric(n float64) {
expiredCentralsMetric.WithLabelValues().Set(n)
}

// #### Metrics for Dataplane clusters - End ####

// #### Metrics for Centrals - Start ####
Expand Down Expand Up @@ -723,6 +739,7 @@ func init() {
prometheus.MustRegister(centralOperationsTotalCountMetric)
prometheus.MustRegister(centralStatusSinceCreatedMetric)
prometheus.MustRegister(CentralStatusCountMetric)
prometheus.MustRegister(expiredCentralsMetric)

// metrics for reconcilers
prometheus.MustRegister(reconcilerDurationMetric)
Expand Down Expand Up @@ -791,6 +808,7 @@ func Reset() {
centralOperationsTotalCountMetric.Reset()
centralStatusSinceCreatedMetric.Reset()
CentralStatusCountMetric.Reset()
expiredCentralsMetric.Reset()

reconcilerDurationMetric.Reset()
reconcilerSuccessCountMetric.Reset()
Expand Down

0 comments on commit 106155f

Please sign in to comment.