Skip to content

Commit

Permalink
PTEUDO-1658: refining metrics. (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrorichardtoledo authored Nov 13, 2024
1 parent 600e772 commit 3127b4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pkg/databaseclaim/databaseclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ func (r *DatabaseClaimReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}
}

// Increment total claims count.
metrics.TotalDatabaseClaims.Inc()

// Track if the claim is using an existing source.
if dbClaim.Spec.UseExistingSource != nil && *dbClaim.Spec.UseExistingSource {
metrics.ExistingSourceClaims.WithLabelValues("true").Inc()
Expand Down Expand Up @@ -257,6 +254,13 @@ func (r *DatabaseClaimReconciler) Reconcile(ctx context.Context, req ctrl.Reques
metrics.ActiveDBState.WithLabelValues(string(dbClaim.Status.ActiveDB.DbState)).Inc()
}

var databaseClaims v1.DatabaseClaimList
if err := r.List(ctx, &databaseClaims); err != nil {
logr.Error(err, "unable to list database claims")
} else {
metrics.TotalDatabaseClaims.WithLabelValues("total_claims").Set(float64(len(databaseClaims.Items)))
}

return res, nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ var (
// -----------------------------------------------------------------------
// Database controller metrics

TotalDatabaseClaims = prometheus.NewGauge(
TotalDatabaseClaims = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "dbcontroller_total_database_claims",
Help: "Total number of database claims",
},
[]string{"total_claims"},
)
TotalDatabaseClaimsDeleted = prometheus.NewGauge(
prometheus.GaugeOpts{
Expand Down

0 comments on commit 3127b4e

Please sign in to comment.