Skip to content

Commit

Permalink
feat(metrics) Report subscription channel
Browse files Browse the repository at this point in the history
This commit introduces a change that updates the sucription_sync_total
metric to include a channel label.
  • Loading branch information
awgreene committed Oct 31, 2019
1 parent 3255734 commit dd27cc0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 6 additions & 1 deletion pkg/controller/operators/catalog/subscription/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ func (s *subscriptionSyncer) Sync(ctx context.Context, event kubestate.ResourceE
}

func (o *subscriptionSyncer) recordMetrics(sub *v1alpha1.Subscription) {
metrics.CounterForSubscription(sub.GetName(), sub.Status.InstalledCSV).Inc()
// sub.Spec is not a required field.
if sub.Spec == nil {
return
}

metrics.CounterForSubscription(sub.GetName(), sub.Status.InstalledCSV, sub.Spec.Channel).Inc()
}

func (s *subscriptionSyncer) Notify(event kubestate.ResourceEvent) {
Expand Down
14 changes: 7 additions & 7 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"

olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
v1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"

)

const (
NAME_LABEL = "name"
INSTALLED_LABEL = "installed"
CHANNEL_LABEL = "channel"
VERSION_LABEL = "version"
PHASE_LABEL = "phase"
PHASE_LABEL = "phase"
REASON_LABEL = "reason"
)

Expand Down Expand Up @@ -148,7 +148,7 @@ var (
Name: "subscription_sync_total",
Help: "Monotonic count of subscription syncs",
},
[]string{NAME_LABEL, INSTALLED_LABEL},
[]string{NAME_LABEL, INSTALLED_LABEL, CHANNEL_LABEL},
)

csvSyncCounter = prometheus.NewCounterVec(
Expand All @@ -173,10 +173,10 @@ func RegisterCatalog() {
prometheus.MustRegister(SubscriptionSyncCount)
}

func CounterForSubscription(name, installedCSV string) prometheus.Counter {
return SubscriptionSyncCount.WithLabelValues(name, installedCSV)
func CounterForSubscription(name, installedCSV, channelName string) prometheus.Counter {
return SubscriptionSyncCount.WithLabelValues(name, installedCSV, channelName)
}

func EmitCSVMetric(csv *olmv1alpha1.ClusterServiceVersion){
func EmitCSVMetric(csv *olmv1alpha1.ClusterServiceVersion) {
csvSyncCounter.WithLabelValues(csv.Name, csv.Spec.Version.String(), string(csv.Status.Phase), string(csv.Status.Reason)).Inc()
}

0 comments on commit dd27cc0

Please sign in to comment.