Skip to content

Commit b57391e

Browse files
Merge pull request #1569 from harishsurf/csv-abnormal-4.3
Bug 1843703: Deleting a CSV removes related CSV metrics
2 parents c4def50 + d58967c commit b57391e

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

pkg/controller/operators/olm/operator.go

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

764+
metrics.DeleteCSVMetric(clusterServiceVersion)
765+
764766
defer func(csv v1alpha1.ClusterServiceVersion) {
765767
if clusterServiceVersion.IsCopied() {
766768
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+
// DeleteCSVMetric deletes old CSV metrics
192+
func DeleteCSVMetric(oldCSV *olmv1alpha1.ClusterServiceVersion) {
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: 10 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,17 @@ 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+"\"")
65+
5966
}
6067

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

0 commit comments

Comments
 (0)