Skip to content

Commit

Permalink
feat(metrics) Limit Cardinality of CSV metrics
Browse files Browse the repository at this point in the history
This commit introduces a change that limits the number of metrics that
an OLM cluster reports at any given time for a CSV.

The first metric introduced is called csv_up, which tracks CSVs that
have reached the succeeded phase. The following information is
provided about the CSV via labels: name, version. The value of this
metric will always be 0 or 1.

The second metric introduced is called csv_abnormal, which is reported
whenever the CSV is updated and has not reached the succeeded phase. The
following information is provided about the CSV via labels: name,
version, phase, reason. Whenever a CSV is updated, the existing
timeseries is deleted and replaced by an updated version.
  • Loading branch information
awgreene committed Oct 30, 2019
1 parent 3255734 commit fba91bb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/operators/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,6 @@ func (a *Operator) syncClusterServiceVersion(obj interface{}) (syncError error)
})
logger.Debug("syncing CSV")

metrics.EmitCSVMetric(clusterServiceVersion)

if a.csvNotification != nil {
a.csvNotification.OnAddOrUpdate(clusterServiceVersion)
}
Expand Down Expand Up @@ -964,6 +962,8 @@ func (a *Operator) syncClusterServiceVersion(obj interface{}) (syncError error)
} else {
syncError = fmt.Errorf("error transitioning ClusterServiceVersion: %s and error updating CSV status: %s", syncError, updateErr)
}
} else {
metrics.EmitCSVMetric(clusterServiceVersion, outCSV)
}
}

Expand Down
39 changes: 29 additions & 10 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"

olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
v1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"

)

const (
NAME_LABEL = "name"
INSTALLED_LABEL = "installed"
VERSION_LABEL = "version"
PHASE_LABEL = "phase"
PHASE_LABEL = "phase"
REASON_LABEL = "reason"
)

Expand Down Expand Up @@ -151,18 +150,27 @@ var (
[]string{NAME_LABEL, INSTALLED_LABEL},
)

csvSyncCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "csv_sync_total",
Help: "Monotonic count of CSV syncs",
csvSucceeded = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "csv_up",
Help: "Successful CSV Install",
},
[]string{NAME_LABEL, VERSION_LABEL},
)

csvAbnormal = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "csv_abnormal",
Help: "The current state of a CSV not in the succeeded phase",
},
[]string{NAME_LABEL, VERSION_LABEL, PHASE_LABEL, REASON_LABEL},
)
)

func RegisterOLM() {
prometheus.MustRegister(csvCount)
prometheus.MustRegister(csvSyncCounter)
prometheus.MustRegister(csvSucceeded)
prometheus.MustRegister(csvAbnormal)
prometheus.MustRegister(CSVUpgradeCount)
}

Expand All @@ -177,6 +185,17 @@ func CounterForSubscription(name, installedCSV string) prometheus.Counter {
return SubscriptionSyncCount.WithLabelValues(name, installedCSV)
}

func EmitCSVMetric(csv *olmv1alpha1.ClusterServiceVersion){
csvSyncCounter.WithLabelValues(csv.Name, csv.Spec.Version.String(), string(csv.Status.Phase), string(csv.Status.Reason)).Inc()
func EmitCSVMetric(oldCSV *olmv1alpha1.ClusterServiceVersion, newCSV *olmv1alpha1.ClusterServiceVersion) {
// Delete the old CSV metrics
csvAbnormal.DeleteLabelValues(oldCSV.Name, oldCSV.Spec.Version.String(), string(oldCSV.Status.Phase), string(oldCSV.Status.Reason))

// Get the phase of the new CSV
newCSVPhase := string(newCSV.Status.Phase)
csvSucceededGauge := csvSucceeded.WithLabelValues(newCSV.Name, newCSV.Spec.Version.String())
if newCSVPhase == string(olmv1alpha1.CSVPhaseSucceeded) {
csvSucceededGauge.Set(1)
} else {
csvSucceededGauge.Set(0)
csvAbnormal.WithLabelValues(newCSV.Name, newCSV.Spec.Version.String(), string(newCSV.Status.Phase), string(newCSV.Status.Reason)).Set(1)
}
}

0 comments on commit fba91bb

Please sign in to comment.