Skip to content

Commit 1878972

Browse files
Merge pull request #1100 from awgreene/increase-cardinality-on-csv-metrics
feat(metrics) Report subscription channel
2 parents a6e1e93 + eb6b0f8 commit 1878972

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pkg/controller/operators/catalog/subscription/syncer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ func (s *subscriptionSyncer) Sync(ctx context.Context, event kubestate.ResourceE
8585
return nil
8686
}
8787

88-
func (o *subscriptionSyncer) recordMetrics(sub *v1alpha1.Subscription) {
89-
metrics.CounterForSubscription(sub.GetName(), sub.Status.InstalledCSV).Inc()
88+
func (s *subscriptionSyncer) recordMetrics(sub *v1alpha1.Subscription) {
89+
// sub.Spec is not a required field.
90+
if sub.Spec == nil {
91+
return
92+
}
93+
94+
metrics.CounterForSubscription(sub.GetName(), sub.Status.InstalledCSV, sub.Spec.Channel).Inc()
9095
}
9196

9297
func (s *subscriptionSyncer) Notify(event kubestate.ResourceEvent) {

pkg/metrics/metrics.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const (
1414
NAME_LABEL = "name"
1515
INSTALLED_LABEL = "installed"
1616
NAMESPACE_LABEL = "namespace"
17+
CHANNEL_LABEL = "channel"
1718
VERSION_LABEL = "version"
1819
PHASE_LABEL = "phase"
1920
REASON_LABEL = "reason"
@@ -148,7 +149,7 @@ var (
148149
Name: "subscription_sync_total",
149150
Help: "Monotonic count of subscription syncs",
150151
},
151-
[]string{NAME_LABEL, INSTALLED_LABEL},
152+
[]string{NAME_LABEL, INSTALLED_LABEL, CHANNEL_LABEL},
152153
)
153154

154155
csvSucceeded = prometheus.NewGaugeVec(
@@ -182,8 +183,8 @@ func RegisterCatalog() {
182183
prometheus.MustRegister(SubscriptionSyncCount)
183184
}
184185

185-
func CounterForSubscription(name, installedCSV string) prometheus.Counter {
186-
return SubscriptionSyncCount.WithLabelValues(name, installedCSV)
186+
func CounterForSubscription(name, installedCSV, channelName string) prometheus.Counter {
187+
return SubscriptionSyncCount.WithLabelValues(name, installedCSV, channelName)
187188
}
188189

189190
func EmitCSVMetric(oldCSV *olmv1alpha1.ClusterServiceVersion, newCSV *olmv1alpha1.ClusterServiceVersion) {

0 commit comments

Comments
 (0)