Skip to content

Commit 2583f2c

Browse files
committed
Bug 1822396: Update metric when Subscription is updated
In #1519, the subscription_sync_total metric was updated when the related subscription object was updated. However, the PR had a bug, in which the map used to store metric related information was not being updated when the metric was udpated. As a result of which any update after the first update was not removing the old metric. This PR fixes that bug.
1 parent a6f90c9 commit 2583f2c

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

pkg/metrics/metrics.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,7 @@ func UpdateSubsSyncCounterStorage(sub *olmv1alpha1.Subscription) {
267267
counterValues.installedCSV = sub.Status.InstalledCSV
268268
counterValues.pkg = sub.Spec.Package
269269
counterValues.channel = sub.Spec.Channel
270+
271+
subscriptionSyncCounters[sub.GetName()] = counterValues
270272
}
271273
}

test/e2e/metrics_e2e_test.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,39 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
149149
}, time.Minute, 5*time.Second).Should(And(
150150
ContainSubstring("subscription_sync_total"),
151151
ContainSubstring(fmt.Sprintf("%s=\"%s\"", metrics.NAME_LABEL, "metric-subscription-for-update")),
152-
ContainSubstring(fmt.Sprintf("%s=\"%s\"", metrics.CHANNEL_LABEL, "beta")),
152+
ContainSubstring(fmt.Sprintf("%s=\"%s\"", metrics.CHANNEL_LABEL, betaChannel)),
153153
ContainSubstring(fmt.Sprintf("%s=\"%s\"", metrics.PACKAGE_LABEL, testPackageName))))
154154
})
155-
if subscriptionCleanup != nil {
156-
subscriptionCleanup()
157-
}
155+
When("The subscription object is updated again", func() {
156+
157+
BeforeEach(func() {
158+
updatedSubscription := getSubscription(GinkgoT(), crc, subscription.GetNamespace(), subscription.GetName())
159+
updatedSubscription.Spec.Channel = alphaChannel
160+
updateSubscription(GinkgoT(), crc, updatedSubscription)
161+
})
162+
163+
It("deletes the old subscription metric and emits the new metric(there is only one metric for the subscription)", func() {
164+
Eventually(func() string {
165+
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"), "8081")
166+
}, time.Minute, 5*time.Second).ShouldNot(And(
167+
ContainSubstring("subscription_sync_total{name=\"metric-subscription-for-update\""),
168+
ContainSubstring(fmt.Sprintf("%s=\"%s\"", metrics.CHANNEL_LABEL, stableChannel)),
169+
ContainSubstring(fmt.Sprintf("%s=\"%s\"", metrics.CHANNEL_LABEL, betaChannel))))
170+
171+
Eventually(func() string {
172+
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"), "8081")
173+
}, time.Minute, 5*time.Second).Should(And(
174+
ContainSubstring("subscription_sync_total"),
175+
ContainSubstring(fmt.Sprintf("%s=\"%s\"", metrics.NAME_LABEL, "metric-subscription-for-update")),
176+
ContainSubstring(fmt.Sprintf("%s=\"%s\"", metrics.CHANNEL_LABEL, alphaChannel)),
177+
ContainSubstring(fmt.Sprintf("%s=\"%s\"", metrics.PACKAGE_LABEL, testPackageName))))
178+
})
179+
})
180+
AfterEach(func() {
181+
if subscriptionCleanup != nil {
182+
subscriptionCleanup()
183+
}
184+
})
158185
})
159186

160187
When("A subscription object is deleted", func() {

test/e2e/subscription_e2e_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,12 @@ func updateSubscription(t GinkgoTInterface, crc versioned.Interface, subscriptio
18181818
Expect(err).ToNot(HaveOccurred())
18191819
}
18201820

1821+
func getSubscription(t GinkgoTInterface, crc versioned.Interface, namespace, name string) *v1alpha1.Subscription {
1822+
subscription, err := crc.OperatorsV1alpha1().Subscriptions(namespace).Get(context.TODO(), name, metav1.GetOptions{})
1823+
Expect(err).ToNot(HaveOccurred())
1824+
return subscription
1825+
}
1826+
18211827
func createSubscriptionForCatalog(crc versioned.Interface, namespace, name, catalog, packageName, channel, startingCSV string, approval v1alpha1.Approval) cleanupFunc {
18221828
subscription := &v1alpha1.Subscription{
18231829
TypeMeta: metav1.TypeMeta{

0 commit comments

Comments
 (0)