Skip to content

Commit 2eb4c7d

Browse files
committed
Deleting a CSV removes related CSV metrics
Problem: Bug 1843678: 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 fd7b441 commit 2eb4c7d

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

pkg/controller/operators/olm/operator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) {
764764
"phase": clusterServiceVersion.Status.Phase,
765765
})
766766

767+
metrics.DeleteCSVMetric(clusterServiceVersion)
768+
767769
defer func(csv v1alpha1.ClusterServiceVersion) {
768770
if clusterServiceVersion.IsCopied() {
769771
logger.Debug("deleted csv is copied. skipping operatorgroup requeue")

pkg/metrics/metrics.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ func CounterForSubscription(name, installedCSV, channelName, packageName string)
188188
return SubscriptionSyncCount.WithLabelValues(name, installedCSV, channelName, packageName)
189189
}
190190

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+
191197
func EmitCSVMetric(oldCSV *olmv1alpha1.ClusterServiceVersion, newCSV *olmv1alpha1.ClusterServiceVersion) {
192198
if oldCSV == nil || newCSV == nil {
193199
return

test/e2e/metrics_e2e_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ func TestMetricsEndpoint(t *testing.T) {
3737

3838
cleanupCSV, err := createCSV(t, c, crc, failingCSV, testNamespace, false, false)
3939
require.NoError(t, err)
40-
defer cleanupCSV()
4140

4241
_, err = fetchCSV(t, crc, failingCSV.Name, testNamespace, csvFailedChecker)
4342
require.NoError(t, err)
@@ -53,9 +52,16 @@ func TestMetricsEndpoint(t *testing.T) {
5352
require.Contains(t, rawOutput, "phase=\"Failed\"")
5453
require.Contains(t, rawOutput, "reason=\"UnsupportedOperatorGroup\"")
5554
require.Contains(t, rawOutput, "version=\"0.0.0\"")
56-
5755
require.Contains(t, rawOutput, "csv_succeeded")
58-
log.Info(rawOutput)
56+
57+
cleanupCSV()
58+
59+
rawOutput, err = getMetricsFromPod(t, c, getOLMPodName(t, c), operatorNamespace, "8081")
60+
if err != nil {
61+
t.Fatalf("Failed to retrieve metrics from OLM pod because of: %v\n", err)
62+
}
63+
require.NotContains(t, rawOutput, "csv_abnormal{name=\""+failingCSV.Name+"\"")
64+
require.NotContains(t, rawOutput, "csv_succeeded{name=\""+failingCSV.Name+"\"")
5965
}
6066

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

0 commit comments

Comments
 (0)