Skip to content

Commit 3774ef8

Browse files
konsotiroptimflannagan
authored andcommitted
rebased
Upstream-repository: operator-lifecycle-manager Upstream-commit: 34e4bfdc6e9105eea1b006bd435ac4983c4e8395
1 parent ccd715c commit 3774ef8

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

staging/operator-lifecycle-manager/pkg/metrics/metrics.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323
Outcome = "outcome"
2424
Succeeded = "succeeded"
2525
Failed = "failed"
26+
APPROVAL_LABEL = "approval"
2627
)
2728

2829
type MetricsProvider interface {
@@ -153,7 +154,7 @@ var (
153154
Name: "subscription_sync_total",
154155
Help: "Monotonic count of subscription syncs",
155156
},
156-
[]string{NAME_LABEL, INSTALLED_LABEL, CHANNEL_LABEL, PACKAGE_LABEL},
157+
[]string{NAME_LABEL, INSTALLED_LABEL, CHANNEL_LABEL, PACKAGE_LABEL, APPROVAL_LABEL},
157158
)
158159

159160
csvSucceeded = prometheus.NewGaugeVec(
@@ -188,9 +189,10 @@ var (
188189
)
189190

190191
type subscriptionSyncLabelValues struct {
191-
installedCSV string
192-
pkg string
193-
channel string
192+
installedCSV string
193+
pkg string
194+
channel string
195+
approvalStrategy string
194196
}
195197

196198
func RegisterOLM() {
@@ -208,8 +210,8 @@ func RegisterCatalog() {
208210
prometheus.MustRegister(dependencyResolutionSummary)
209211
}
210212

211-
func CounterForSubscription(name, installedCSV, channelName, packageName string) prometheus.Counter {
212-
return SubscriptionSyncCount.WithLabelValues(name, installedCSV, channelName, packageName)
213+
func CounterForSubscription(name, installedCSV, channelName, packageName, planApprovalStrategy string) prometheus.Counter {
214+
return SubscriptionSyncCount.WithLabelValues(name, installedCSV, channelName, packageName, planApprovalStrategy)
213215
}
214216

215217
func DeleteCSVMetric(oldCSV *olmv1alpha1.ClusterServiceVersion) {
@@ -246,12 +248,13 @@ func EmitSubMetric(sub *olmv1alpha1.Subscription) {
246248
if sub.Spec == nil {
247249
return
248250
}
249-
SubscriptionSyncCount.WithLabelValues(sub.GetName(), sub.Status.InstalledCSV, sub.Spec.Channel, sub.Spec.Package).Inc()
251+
SubscriptionSyncCount.WithLabelValues(sub.GetName(), sub.Status.InstalledCSV, sub.Spec.Channel, sub.Spec.Package, string(sub.Spec.InstallPlanApproval)).Inc()
250252
if _, present := subscriptionSyncCounters[sub.GetName()]; !present {
251253
subscriptionSyncCounters[sub.GetName()] = subscriptionSyncLabelValues{
252-
installedCSV: sub.Status.InstalledCSV,
253-
pkg: sub.Spec.Package,
254-
channel: sub.Spec.Channel,
254+
installedCSV: sub.Status.InstalledCSV,
255+
pkg: sub.Spec.Package,
256+
channel: sub.Spec.Channel,
257+
approvalStrategy: string(sub.Spec.InstallPlanApproval),
255258
}
256259
}
257260
}
@@ -260,25 +263,28 @@ func DeleteSubsMetric(sub *olmv1alpha1.Subscription) {
260263
if sub.Spec == nil {
261264
return
262265
}
263-
SubscriptionSyncCount.DeleteLabelValues(sub.GetName(), sub.Status.InstalledCSV, sub.Spec.Channel, sub.Spec.Package)
266+
SubscriptionSyncCount.DeleteLabelValues(sub.GetName(), sub.Status.InstalledCSV, sub.Spec.Channel, sub.Spec.Package, string(sub.Spec.InstallPlanApproval))
264267
}
265268

266269
func UpdateSubsSyncCounterStorage(sub *olmv1alpha1.Subscription) {
267270
if sub.Spec == nil {
268271
return
269272
}
270273
counterValues := subscriptionSyncCounters[sub.GetName()]
274+
approvalStrategy := string(sub.Spec.InstallPlanApproval)
271275

272276
if sub.Spec.Channel != counterValues.channel ||
273277
sub.Spec.Package != counterValues.pkg ||
274-
sub.Status.InstalledCSV != counterValues.installedCSV {
278+
sub.Status.InstalledCSV != counterValues.installedCSV ||
279+
approvalStrategy != counterValues.approvalStrategy {
275280

276281
// Delete metric will label values of old Subscription first
277-
SubscriptionSyncCount.DeleteLabelValues(sub.GetName(), counterValues.installedCSV, counterValues.channel, counterValues.pkg)
282+
SubscriptionSyncCount.DeleteLabelValues(sub.GetName(), counterValues.installedCSV, counterValues.channel, counterValues.pkg, counterValues.approvalStrategy)
278283

279284
counterValues.installedCSV = sub.Status.InstalledCSV
280285
counterValues.pkg = sub.Spec.Package
281286
counterValues.channel = sub.Spec.Channel
287+
counterValues.approvalStrategy = approvalStrategy
282288

283289
subscriptionSyncCounters[sub.GetName()] = counterValues
284290
}

staging/operator-lifecycle-manager/test/e2e/like_metric_matcher_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func WithReason(reason string) MetricPredicate {
6767
return WithLabel("reason", reason)
6868
}
6969

70+
func WithApproval(approvalStrategy string) MetricPredicate {
71+
return WithLabel("approval", approvalStrategy)
72+
}
73+
7074
func WithVersion(version string) MetricPredicate {
7175
return WithLabel("version", version)
7276
}

staging/operator-lifecycle-manager/test/e2e/metrics_e2e_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
136136
WithName("metric-subscription-for-create"),
137137
WithChannel(stableChannel),
138138
WithPackage(testPackageName),
139+
WithApproval(string(v1alpha1.ApprovalManual)),
139140
)))
140141
})
141142

@@ -187,12 +188,14 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
187188
WithName("metric-subscription-for-update"),
188189
WithChannel(stableChannel),
189190
WithPackage(testPackageName),
191+
WithApproval(string(v1alpha1.ApprovalManual)),
190192
))),
191193
ContainElement(LikeMetric(
192194
WithFamily("subscription_sync_total"),
193195
WithName("metric-subscription-for-update"),
194196
WithChannel(betaChannel),
195197
WithPackage(testPackageName),
198+
WithApproval(string(v1alpha1.ApprovalManual)),
196199
)),
197200
))
198201
})
@@ -224,12 +227,14 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
224227
WithName("metric-subscription-for-update"),
225228
WithChannel(betaChannel),
226229
WithPackage(testPackageName),
230+
WithApproval(string(v1alpha1.ApprovalManual)),
227231
))),
228232
ContainElement(LikeMetric(
229233
WithFamily("subscription_sync_total"),
230234
WithName("metric-subscription-for-update"),
231235
WithChannel(alphaChannel),
232236
WithPackage(testPackageName),
237+
WithApproval(string(v1alpha1.ApprovalManual)),
233238
))))
234239
})
235240
})

0 commit comments

Comments
 (0)