Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
51 changes: 40 additions & 11 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ 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"
NAMESPACE_LABEL = "namespace"
VERSION_LABEL = "version"
PHASE_LABEL = "phase"
PHASE_LABEL = "phase"
REASON_LABEL = "reason"
)

Expand Down Expand Up @@ -151,18 +151,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_succeeded",
Help: "Successful CSV install",
},
[]string{NAMESPACE_LABEL, NAME_LABEL, VERSION_LABEL},
)

csvAbnormal = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "csv_abnormal",
Help: "CSV is not installed",
},
[]string{NAME_LABEL, VERSION_LABEL, PHASE_LABEL, REASON_LABEL},
[]string{NAMESPACE_LABEL, 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 +186,26 @@ 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) {
if oldCSV == nil || newCSV == nil {
return
}

// Don't update the metric for copies
if newCSV.Status.Reason == olmv1alpha1.CSVReasonCopied {
return
}

// Delete the old CSV metrics
csvAbnormal.DeleteLabelValues(oldCSV.Namespace, 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.Namespace, newCSV.Name, newCSV.Spec.Version.String())
if newCSVPhase == string(olmv1alpha1.CSVPhaseSucceeded) {
csvSucceededGauge.Set(1)
} else {
csvSucceededGauge.Set(0)
csvAbnormal.WithLabelValues(newCSV.Namespace, newCSV.Name, newCSV.Spec.Version.String(), string(newCSV.Status.Phase), string(newCSV.Status.Reason)).Set(1)
}
}
4 changes: 3 additions & 1 deletion test/e2e/metrics_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ func TestMetricsEndpoint(t *testing.T) {
}

// Verify metrics have been emitted for packageserver csv
require.Contains(t, rawOutput, "csv_sync_total")
require.Contains(t, rawOutput, "csv_abnormal")
require.Contains(t, rawOutput, "name=\""+failingCSV.Name+"\"")
require.Contains(t, rawOutput, "phase=\"Failed\"")
require.Contains(t, rawOutput, "reason=\"UnsupportedOperatorGroup\"")
require.Contains(t, rawOutput, "version=\"0.0.0\"")

require.Contains(t, rawOutput, "csv_succeeded")
log.Info(rawOutput)
}

Expand Down