Skip to content

Bug 1843703: Deleting a CSV removes related CSV metrics #1569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
2 changes: 2 additions & 0 deletions pkg/controller/operators/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,8 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) {
"phase": clusterServiceVersion.Status.Phase,
})

metrics.DeleteCSVMetric(clusterServiceVersion)

defer func(csv v1alpha1.ClusterServiceVersion) {
if clusterServiceVersion.IsCopied() {
logger.Debug("deleted csv is copied. skipping operatorgroup requeue")
Expand Down
6 changes: 6 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ func CounterForSubscription(name, installedCSV, channelName, packageName string)
return SubscriptionSyncCount.WithLabelValues(name, installedCSV, channelName, packageName)
}

// DeleteCSVMetric deletes old CSV metrics
func DeleteCSVMetric(oldCSV *olmv1alpha1.ClusterServiceVersion) {
csvAbnormal.DeleteLabelValues(oldCSV.Namespace, oldCSV.Name, oldCSV.Spec.Version.String(), string(oldCSV.Status.Phase), string(oldCSV.Status.Reason))
csvSucceeded.DeleteLabelValues(oldCSV.Namespace, oldCSV.Name, oldCSV.Spec.Version.String())
}

func EmitCSVMetric(oldCSV *olmv1alpha1.ClusterServiceVersion, newCSV *olmv1alpha1.ClusterServiceVersion) {
if oldCSV == nil || newCSV == nil {
return
Expand Down
13 changes: 10 additions & 3 deletions test/e2e/metrics_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func TestMetricsEndpoint(t *testing.T) {

cleanupCSV, err := createCSV(t, c, crc, failingCSV, testNamespace, false, false)
require.NoError(t, err)
defer cleanupCSV()

_, err = fetchCSV(t, crc, failingCSV.Name, testNamespace, csvFailedChecker)
require.NoError(t, err)
Expand All @@ -53,9 +52,17 @@ func TestMetricsEndpoint(t *testing.T) {
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)

cleanupCSV()

rawOutput, err = getMetricsFromPod(t, c, getOLMPodName(t, c), operatorNamespace, "8081")
if err != nil {
t.Fatalf("Failed to retrieve metrics from OLM pod because of: %v\n", err)
}
require.NotContains(t, rawOutput, "csv_abnormal{name=\""+failingCSV.Name+"\"")
require.NotContains(t, rawOutput, "csv_succeeded{name=\""+failingCSV.Name+"\"")

}

func getOLMPodName(t *testing.T, client operatorclient.ClientInterface) string {
Expand Down