Skip to content

Commit 037ead3

Browse files
Merge pull request #951 from ecordell/metrics
feat(metrics): record sync count for Subscriptions, labeled with name and installedCSV
2 parents 4b7a384 + 8e9c523 commit 037ead3

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ build-linux: build_cmd=build
5656
build-linux: arch_flags=GOOS=linux GOARCH=386
5757
build-linux: clean $(CMDS)
5858

59-
$(CMDS): version_flags=-ldflags "-w -X $(PKG)/pkg/version.GitCommit=`git rev-parse --short HEAD` -X $(PKG)/pkg/version.OLMVersion=`cat OLM_VERSION`"
59+
$(CMDS): version_flags=-ldflags "-X $(PKG)/pkg/version.GitCommit=`git rev-parse --short HEAD` -X $(PKG)/pkg/version.OLMVersion=`cat OLM_VERSION`"
6060
$(CMDS):
6161
CGO_ENABLED=0 $(arch_flags) go $(build_cmd) $(MOD_FLAGS) $(version_flags) -o bin/$(shell basename $@) $@
6262

@@ -87,7 +87,7 @@ setup-bare: clean e2e.namespace
8787
. ./scripts/install_bare.sh $(shell cat ./e2e.namespace) test/e2e/resources
8888

8989
e2e:
90-
go test -v -failfast -timeout 70m ./test/e2e/... -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager
90+
go test -v $(MOD_FLAGS) -failfast -timeout 70m ./test/e2e/... -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager
9191

9292
e2e-local: build-linux
9393
. ./scripts/build_local.sh

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
1616
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/kubestate"
1717
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
18+
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
1819
)
1920

2021
var scheme = runtime.NewScheme()
@@ -49,6 +50,8 @@ func (s *subscriptionSyncer) Sync(ctx context.Context, event kubestate.ResourceE
4950
return err
5051
}
5152

53+
s.recordMetrics(res)
54+
5255
logger := s.logger.WithFields(logrus.Fields{
5356
"reconciling": fmt.Sprintf("%T", res),
5457
"selflink": res.GetSelfLink(),
@@ -82,6 +85,10 @@ func (s *subscriptionSyncer) Sync(ctx context.Context, event kubestate.ResourceE
8285
return nil
8386
}
8487

88+
func (o *subscriptionSyncer) recordMetrics(sub *v1alpha1.Subscription) {
89+
metrics.CounterForSubscription(sub.GetName(), sub.Status.InstalledCSV).Inc()
90+
}
91+
8592
func (s *subscriptionSyncer) Notify(event kubestate.ResourceEvent) {
8693
s.notify(event)
8794
}

pkg/metrics/metrics.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import (
99
v1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
1010
)
1111

12+
const (
13+
NAME_LABEL = "name"
14+
INSTALLED_LABEL = "installed"
15+
)
16+
1217
// TODO(alecmerdler): Can we use this to emit Kubernetes events?
1318
type MetricsProvider interface {
1419
HandleMetrics() error
@@ -132,6 +137,14 @@ var (
132137
Help: "Monotonic count of CSV upgrades",
133138
},
134139
)
140+
141+
SubscriptionSyncCount = prometheus.NewCounterVec(
142+
prometheus.CounterOpts{
143+
Name: "subscription_sync_total",
144+
Help: "Monotonic count of subscription syncs",
145+
},
146+
[]string{NAME_LABEL, INSTALLED_LABEL},
147+
)
135148
)
136149

137150
func RegisterOLM() {
@@ -143,4 +156,9 @@ func RegisterCatalog() {
143156
prometheus.MustRegister(installPlanCount)
144157
prometheus.MustRegister(subscriptionCount)
145158
prometheus.MustRegister(catalogSourceCount)
159+
prometheus.MustRegister(SubscriptionSyncCount)
160+
}
161+
162+
func CounterForSubscription(name, installedCSV string) prometheus.Counter {
163+
return SubscriptionSyncCount.WithLabelValues(name, installedCSV)
146164
}

test/e2e/metrics_e2e_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ package e2e
55
import (
66
"testing"
77

8-
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
98
log "github.com/sirupsen/logrus"
109
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1110
"k8s.io/apimachinery/pkg/util/net"
11+
12+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
1213
)
1314

1415
// TestMetrics tests the metrics endpoint of the OLM pod.
@@ -32,8 +33,7 @@ func TestMetricsEndpoint(t *testing.T) {
3233
if err != nil {
3334
t.Fatalf("Metrics test failed: %v\n", err)
3435
}
35-
36-
log.Debugf("Metrics:\n%v", rawOutput)
36+
log.Info(rawOutput)
3737
}
3838

3939
func getMetricsFromPod(t *testing.T, client operatorclient.ClientInterface, podName string, namespace string, port string) (string, error) {

0 commit comments

Comments
 (0)