Skip to content
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

Bug 1737156: feat(metrics): record sync count for Subscriptions, labeled with name and installedCSV #976

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@);

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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)
}
6 changes: 3 additions & 3 deletions test/e2e/metrics_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down