diff --git a/Makefile b/Makefile index 0136ed5f7d..28b586521d 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ build-linux: build_cmd=build build-linux: arch_flags=GOOS=linux GOARCH=386 build-linux: clean $(CMDS) -$(CMDS): version_flags=-ldflags "-w -X $(PKG)/pkg/version.GitCommit=`git rev-parse --short HEAD` -X $(PKG)/pkg/version.OLMVersion=`cat OLM_VERSION`" +$(CMDS): version_flags=-ldflags "-X $(PKG)/pkg/version.GitCommit=`git rev-parse --short HEAD` -X $(PKG)/pkg/version.OLMVersion=`cat OLM_VERSION`" $(CMDS): CGO_ENABLED=0 $(arch_flags) go $(build_cmd) $(MOD_FLAGS) $(version_flags) -o $@ $(PKG)/cmd/$(shell basename $@); @@ -77,7 +77,7 @@ setup-bare: clean e2e.namespace . ./scripts/install_bare.sh $(shell cat ./e2e.namespace) test/e2e/resources e2e: - go test -v -failfast -timeout 70m ./test/e2e/... -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager + go test -v $(MOD_FLAGS) -failfast -timeout 70m ./test/e2e/... -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager e2e-local: build-linux . ./scripts/build_local.sh diff --git a/pkg/controller/operators/catalog/operator.go b/pkg/controller/operators/catalog/operator.go index c5cb6ae480..0c419c99f1 100644 --- a/pkg/controller/operators/catalog/operator.go +++ b/pkg/controller/operators/catalog/operator.go @@ -662,11 +662,16 @@ func (o *Operator) syncSubscriptions(obj interface{}) error { return fmt.Errorf("casting Subscription failed") } + o.recordMetrics(sub) o.resolveNamespace(sub.GetNamespace()) return nil } +func (o *Operator) recordMetrics(sub *v1alpha1.Subscription) { + metrics.CounterForSubscription(sub.GetName(), sub.Status.InstalledCSV).Inc() +} + func (o *Operator) resolveNamespace(namespace string) { o.namespaceResolveQueue.AddRateLimited(namespace) } diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 29a11bbc98..089c345b22 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -9,6 +9,11 @@ import ( v1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1" ) +const ( + NAME_LABEL = "name" + INSTALLED_LABEL = "installed" +) + // TODO(alecmerdler): Can we use this to emit Kubernetes events? type MetricsProvider interface { HandleMetrics() error @@ -132,6 +137,14 @@ var ( Help: "Monotonic count of CSV upgrades", }, ) + + SubscriptionSyncCount = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Name: "subscription_sync_total", + Help: "Monotonic count of subscription syncs", + }, + []string{NAME_LABEL, INSTALLED_LABEL}, + ) ) func RegisterOLM() { @@ -143,4 +156,9 @@ func RegisterCatalog() { prometheus.MustRegister(installPlanCount) prometheus.MustRegister(subscriptionCount) prometheus.MustRegister(catalogSourceCount) + prometheus.MustRegister(SubscriptionSyncCount) +} + +func CounterForSubscription(name, installedCSV string) prometheus.Counter { + return SubscriptionSyncCount.WithLabelValues(name, installedCSV) } diff --git a/test/e2e/metrics_e2e_test.go b/test/e2e/metrics_e2e_test.go index 6abe87a41a..42c270423b 100644 --- a/test/e2e/metrics_e2e_test.go +++ b/test/e2e/metrics_e2e_test.go @@ -5,10 +5,11 @@ package e2e import ( "testing" - "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient" log "github.com/sirupsen/logrus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/net" + + "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient" ) // TestMetrics tests the metrics endpoint of the OLM pod. @@ -32,8 +33,7 @@ func TestMetricsEndpoint(t *testing.T) { if err != nil { t.Fatalf("Metrics test failed: %v\n", err) } - - log.Debugf("Metrics:\n%v", rawOutput) + log.Info(rawOutput) } func getMetricsFromPod(t *testing.T, client operatorclient.ClientInterface, podName string, namespace string, port string) (string, error) {