Skip to content

Commit f783f16

Browse files
committed
Deleting a CSV removes related CSV metrics
Problem: Bug 1819308: When creating a CSV fails, deleting it did not clear the CSV metrics. So when the same CSV was created again and allowed to succeed, the olm pod still retained the old CSV metrics Solution: Deleting a CSV will now clear its related metrics from the olm pod Signed-off-by: Harish <[email protected]>
1 parent 34d6563 commit f783f16

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

pkg/controller/operators/olm/operator.go

+2
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,8 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) {
856856
"phase": clusterServiceVersion.Status.Phase,
857857
})
858858

859+
metrics.DeleteCSVMetric(clusterServiceVersion)
860+
859861
defer func(csv v1alpha1.ClusterServiceVersion) {
860862
if clusterServiceVersion.IsCopied() {
861863
logger.Debug("deleted csv is copied. skipping operatorgroup requeue")

pkg/metrics/metrics.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package metrics
22

33
import (
44
"context"
5-
65
"github.com/prometheus/client_golang/prometheus"
76
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
87
"k8s.io/apimachinery/pkg/labels"
@@ -189,6 +188,12 @@ func CounterForSubscription(name, installedCSV, channelName, packageName string)
189188
return SubscriptionSyncCount.WithLabelValues(name, installedCSV, channelName, packageName)
190189
}
191190

191+
func DeleteCSVMetric(oldCSV *olmv1alpha1.ClusterServiceVersion) {
192+
// Delete the old CSV metrics
193+
csvAbnormal.DeleteLabelValues(oldCSV.Namespace, oldCSV.Name, oldCSV.Spec.Version.String(), string(oldCSV.Status.Phase), string(oldCSV.Status.Reason))
194+
csvSucceeded.DeleteLabelValues(oldCSV.Namespace, oldCSV.Name, oldCSV.Spec.Version.String())
195+
}
196+
192197
func EmitCSVMetric(oldCSV *olmv1alpha1.ClusterServiceVersion, newCSV *olmv1alpha1.ClusterServiceVersion) {
193198
if oldCSV == nil || newCSV == nil {
194199
return

test/e2e/metrics_e2e_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ var _ = Describe("Metrics", func() {
4444

4545
cleanupCSV, err := createCSV(GinkgoT(), c, crc, failingCSV, testNamespace, false, false)
4646
Expect(err).ToNot(HaveOccurred())
47-
defer cleanupCSV()
4847

4948
_, err = fetchCSV(GinkgoT(), crc, failingCSV.Name, testNamespace, csvFailedChecker)
5049
Expect(err).ToNot(HaveOccurred())
@@ -58,6 +57,14 @@ var _ = Describe("Metrics", func() {
5857
ContainSubstring("version=\"0.0.0\""),
5958
ContainSubstring("csv_succeeded"),
6059
))
60+
61+
cleanupCSV()
62+
63+
// Verify that when the csv has been deleted, it deletes the corresponding CSV metrics
64+
Expect(getMetricsFromPod(c, getOLMPod(c), "8081")).ToNot(And(
65+
ContainSubstring("csv_abnormal{name=\"%s\"", failingCSV.Name),
66+
ContainSubstring("csv_succeeded{name=\"%s\"", failingCSV.Name),
67+
))
6168
})
6269
})
6370

0 commit comments

Comments
 (0)