-
Notifications
You must be signed in to change notification settings - Fork 562
Bug 1822396: Delete subscription metric when an operator is uninstalled #1519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package metrics | |
|
||
import ( | ||
"context" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
|
@@ -168,8 +169,19 @@ var ( | |
}, | ||
[]string{NAMESPACE_LABEL, NAME_LABEL, VERSION_LABEL, PHASE_LABEL, REASON_LABEL}, | ||
) | ||
|
||
// subscriptionSyncCounters keeps a record of the promethues counters emitted by | ||
// Subscription objects. The key of a record is the Subscription name, while the value | ||
// is struct containing label values used in the counter | ||
subscriptionSyncCounters = make(map[string]subscriptionSyncLabelValues) | ||
) | ||
|
||
type subscriptionSyncLabelValues struct { | ||
installedCSV string | ||
pkg string | ||
channel string | ||
} | ||
|
||
func RegisterOLM() { | ||
prometheus.MustRegister(csvCount) | ||
prometheus.MustRegister(csvSucceeded) | ||
|
@@ -217,3 +229,43 @@ func EmitCSVMetric(oldCSV *olmv1alpha1.ClusterServiceVersion, newCSV *olmv1alpha | |
csvAbnormal.WithLabelValues(newCSV.Namespace, newCSV.Name, newCSV.Spec.Version.String(), string(newCSV.Status.Phase), string(newCSV.Status.Reason)).Set(1) | ||
} | ||
} | ||
|
||
func EmitSubMetric(sub *olmv1alpha1.Subscription) { | ||
if sub.Spec == nil { | ||
return | ||
} | ||
SubscriptionSyncCount.WithLabelValues(sub.GetName(), sub.Status.InstalledCSV, sub.Spec.Channel, sub.Spec.Package).Inc() | ||
awgreene marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason the namespace isn't included? Since it's possible to have two subs with the same name, there's potential for collision. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can potentially fix this in a separate bug. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if _, present := subscriptionSyncCounters[sub.GetName()]; !present { | ||
subscriptionSyncCounters[sub.GetName()] = subscriptionSyncLabelValues{ | ||
installedCSV: sub.Status.InstalledCSV, | ||
pkg: sub.Spec.Package, | ||
channel: sub.Spec.Channel, | ||
} | ||
} | ||
} | ||
|
||
func DeleteSubsMetric(sub *olmv1alpha1.Subscription) { | ||
if sub.Spec == nil { | ||
return | ||
} | ||
SubscriptionSyncCount.DeleteLabelValues(sub.GetName(), sub.Status.InstalledCSV, sub.Spec.Channel, sub.Spec.Package) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The should check for nil on sub.status and sub.spec |
||
} | ||
awgreene marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func UpdateSubsSyncCounterStorage(sub *olmv1alpha1.Subscription) { | ||
if sub.Spec == nil { | ||
return | ||
} | ||
counterValues := subscriptionSyncCounters[sub.GetName()] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sub.spec and sub.status can be nil |
||
if sub.Spec.Channel != counterValues.channel || | ||
sub.Spec.Package != counterValues.pkg || | ||
sub.Status.InstalledCSV != counterValues.installedCSV { | ||
|
||
// Delete metric will label values of old Subscription first | ||
SubscriptionSyncCount.DeleteLabelValues(sub.GetName(), counterValues.installedCSV, counterValues.channel, counterValues.pkg) | ||
|
||
counterValues.installedCSV = sub.Status.InstalledCSV | ||
counterValues.pkg = sub.Spec.Package | ||
counterValues.channel = sub.Spec.Channel | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.