Skip to content

Commit

Permalink
feat: add prometheus metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Dec 18, 2023
1 parent fc85693 commit 4ff1438
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 9 deletions.
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ require (
github.com/onsi/gomega v1.30.0
github.com/open-component-model/ocm v0.4.0
github.com/open-component-model/ocm-e2e-framework v0.6.1-0.20230913082321-d7050cc55939
github.com/open-component-model/pkg/metrics v0.0.0-20231218095050-514b73c0703c
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc5
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
Expand Down Expand Up @@ -342,10 +343,10 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,8 @@ github.com/open-component-model/ocm v0.4.0 h1:S+rPJGoDnSvxhBn3QS2HXURxugTjCM4XWE
github.com/open-component-model/ocm v0.4.0/go.mod h1:7RAqaUMmA4BlwW5ZEUBm8amWIb1TL9FhNigNXQ6wiu0=
github.com/open-component-model/ocm-e2e-framework v0.6.1-0.20230913082321-d7050cc55939 h1:OnT3xCv7bqu5oFt701occb9dYYa1ow3YhI7A5zu055A=
github.com/open-component-model/ocm-e2e-framework v0.6.1-0.20230913082321-d7050cc55939/go.mod h1:+JNqNksMIH03PxJ1LyEFbr+tYD2JZtpNMgumE3Gq1hg=
github.com/open-component-model/pkg/metrics v0.0.0-20231218095050-514b73c0703c h1:65oCzphTR71kLe8l7zSVF7B9uZVS85ad9LnQa1UmnxE=
github.com/open-component-model/pkg/metrics v0.0.0-20231218095050-514b73c0703c/go.mod h1:80SzqzaWEpRC0NE8wks/QAV+QxUrpKIhpk6r0s8qBTQ=
github.com/opencontainers/go-digest v1.0.1-0.20220411205349-bde1400a84be h1:f2PlhC9pm5sqpBZFvnAoKj+KzXRzbjFMA+TqXfJdgho=
github.com/opencontainers/go-digest v1.0.1-0.20220411205349-bde1400a84be/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/go-digest/blake3 v0.0.0-20230815154656-802ce17c4f59 h1:PHIYPK2sf+Wfnsy6Sj8oHjLmPpbybrYBjxzSZckHjDQ=
Expand Down Expand Up @@ -1721,15 +1723,15 @@ github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDf
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8=
github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc=
github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY=
github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY=
github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 h1:v7DLqVdK4VrYkVD5diGdl4sxJurKJEMnODWRJlxV9oM=
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
github.com/prometheus/common v0.0.0-20180110214958-89604d197083/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
Expand All @@ -1749,8 +1751,8 @@ github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+Gx
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg=
github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/protocolbuffers/txtpbfmt v0.0.0-20220428173112-74888fd59c2b h1:zd/2RNzIRkoGGMjE+YIsZ85CnDIz672JK2F3Zl4vux4=
github.com/protocolbuffers/txtpbfmt v0.0.0-20220428173112-74888fd59c2b/go.mod h1:KjY0wibdYKc4DYkerHSbguaf3JeIPGhNJBp2BNiFH78=
Expand Down
90 changes: 90 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0

package metrics

import (
"sigs.k8s.io/controller-runtime/pkg/metrics"

mh "github.com/open-component-model/pkg/metrics"
)

const (
metricsComponent = "ocm_controller"
)

func init() {
metrics.Registry.MustRegister(
ComponentVersionReconciledTotal,
ComponentVersionReconcileFailed,
ConfigurationReconcileFailed,
LocalizationReconcileFailed,
ResourceReconcileFailed,
SnapshotNumberOfBytesReconciled,
MPASProductReconciledStatus,
)
}

// ComponentVersionReconciledTotal counts the number times a component version was reconciled.
var ComponentVersionReconciledTotal = mh.MustRegisterCounterVec(
"ocm_system",
metricsComponent,
"component_version_reconciled_total",
"Number of times a component version was reconciled",
"component", "version",
)

// ComponentVersionReconcileFailed counts the number times we failed to reconcile a component version.
var ComponentVersionReconcileFailed = mh.MustRegisterCounterVec(
"ocm_system",
metricsComponent,
"component_version_reconcile_failed",
"Number of times a component version failed to reconcile",
"component",
)

// ConfigurationReconcileFailed counts the number times we failed to reconcile a Configuration.
var ConfigurationReconcileFailed = mh.MustRegisterCounterVec(
"ocm_system",
metricsComponent,
"configuration_reconcile_failed",
"Number of times a configuration failed to reconcile",
"configuration",
)

// LocalizationReconcileFailed counts the number times we failed to reconcile a Localization.
var LocalizationReconcileFailed = mh.MustRegisterCounterVec(
"ocm_system",
metricsComponent,
"localization_reconcile_failed",
"Number of times a localization failed to reconcile",
"localization",
)

// ResourceReconcileFailed counts the number times we failed to reconcile a resource.
var ResourceReconcileFailed = mh.MustRegisterCounterVec(
"ocm_system",
metricsComponent,
"resource_reconcile_failed",
"Number of times a resource failed to reconcile",
"resource",
)

// SnapshotNumberOfBytesReconciled number of bytes reconciled through snapshots.
var SnapshotNumberOfBytesReconciled = mh.MustRegisterGaugeVec(
"ocm_system",
metricsComponent,
"snapshot_number_of_bytes_reconciled",
"Number of bytes reconciled by a snapshot",
"snapshot", "sha",
)

// MPASProductReconciledStatus updates the status of an MPAS product component.
var MPASProductReconciledStatus = mh.MustRegisterCounterVec(
"mpas_system",
metricsComponent,
mh.MPASProductInstallationCounterLabel,
"The status of an mpas product.",
"product", "status",
)

0 comments on commit 4ff1438

Please sign in to comment.