Skip to content

Commit fdfb411

Browse files
committed
feat: add OTel metrics with Prometheus exporter and ServiceMonitor auto-creation
Expose operator-level metrics using the OpenTelemetry SDK with a Prometheus exporter registered on controller-runtime's metrics registry. This adds webhook mutation and controller reconcile counters and duration histograms to the existing /metrics endpoint. Add --enable-service-monitor flag (ENABLE_SERVICE_MONITOR env var) that automatically creates a Prometheus ServiceMonitor CR at startup for OpenShift environments where scraping is the default discovery method. The operator checks for the monitoring.coreos.com/v1 API at startup and gracefully skips creation if the CRD is not installed. Signed-off-by: Nina Bongartz <pninak@web.de>
1 parent 79f6b05 commit fdfb411

16 files changed

Lines changed: 717 additions & 24 deletions

File tree

‎cmd/main.go‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package main
1717

1818
import (
19+
"context"
1920
"crypto/tls"
2021
"flag"
2122
"os"
@@ -24,6 +25,8 @@ import (
2425

2526
"github.com/sigstore/model-validation-operator/internal/constants"
2627
"github.com/sigstore/model-validation-operator/internal/controller"
28+
"github.com/sigstore/model-validation-operator/internal/metrics"
29+
"github.com/sigstore/model-validation-operator/internal/servicemonitor"
2730
"github.com/sigstore/model-validation-operator/internal/tracker"
2831
"github.com/sigstore/model-validation-operator/internal/utils"
2932
"github.com/sigstore/model-validation-operator/internal/webhooks"
@@ -33,6 +36,7 @@ import (
3336
// to ensure that exec-entrypoint and run can make use of them.
3437
_ "k8s.io/client-go/plugin/pkg/client/auth"
3538

39+
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
3640
"k8s.io/apimachinery/pkg/runtime"
3741
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3842
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
@@ -67,6 +71,7 @@ func init() {
6771
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
6872

6973
utilruntime.Must(mlv1alpha1.AddToScheme(scheme))
74+
utilruntime.Must(monitoringv1.AddToScheme(scheme))
7075
// +kubebuilder:scaffold:scheme
7176
}
7277

@@ -81,6 +86,7 @@ func main() {
8186
var enableHTTP2 bool
8287
var disableWebhook bool
8388
var forceLegacySidecar bool
89+
var enableServiceMonitor bool
8490
var tlsOpts []func(*tls.Config)
8591

8692
// Status tracker configuration
@@ -117,6 +123,9 @@ func main() {
117123
"VALIDATION_AGENT_IMAGE",
118124
constants.ModelValidationAgentImage,
119125
"Validation agent image to be used.")
126+
utils.BoolFlagOrEnv(&enableServiceMonitor, "enable-service-monitor",
127+
"ENABLE_SERVICE_MONITOR", false,
128+
"Automatically create a Prometheus ServiceMonitor for the operator metrics endpoint.")
120129

121130
// Status tracker configuration flags
122131
flag.DurationVar(&debounceDuration, "debounce-duration", defaultDebounceDuration,
@@ -139,6 +148,17 @@ func main() {
139148

140149
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
141150

151+
otelShutdown, err := metrics.SetupOTelMetrics()
152+
if err != nil {
153+
setupLog.Error(err, "unable to set up OTel metrics")
154+
os.Exit(1)
155+
}
156+
defer func() {
157+
if err := otelShutdown(context.Background()); err != nil {
158+
setupLog.Error(err, "error shutting down OTel metrics")
159+
}
160+
}()
161+
142162
// if the enable-http2 flag is false (the default), http/2 should be disabled
143163
// due to its vulnerabilities. More specifically, disabling http/2 will
144164
// prevent from being vulnerable to the HTTP/2 Stream Cancellation and
@@ -275,6 +295,19 @@ func main() {
275295
}
276296
}
277297

298+
if enableServiceMonitor {
299+
smCreator := servicemonitor.NewCreator(mgr.GetClient(), mgr.GetConfig(), servicemonitor.Options{
300+
Namespace: os.Getenv("POD_NAMESPACE"),
301+
PortName: "https",
302+
Path: "/metrics",
303+
Secure: secureMetrics,
304+
})
305+
if err := mgr.Add(smCreator); err != nil {
306+
setupLog.Error(err, "unable to add ServiceMonitor creator")
307+
os.Exit(1)
308+
}
309+
}
310+
278311
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
279312
setupLog.Error(err, "unable to set up health check")
280313
os.Exit(1)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: kustomize.config.k8s.io/v1alpha1
2+
kind: Component
3+
4+
# This component enables automatic ServiceMonitor creation for Prometheus/OpenShift.
5+
# It adds the --enable-service-monitor flag and POD_NAMESPACE env var to the controller manager,
6+
# and grants RBAC for managing ServiceMonitor resources.
7+
patches:
8+
- target:
9+
kind: Deployment
10+
name: controller-manager
11+
patch: |-
12+
- op: add
13+
path: /spec/template/spec/containers/0/args/-
14+
value: --enable-service-monitor
15+
- op: add
16+
path: /spec/template/spec/containers/0/env
17+
value:
18+
- name: POD_NAMESPACE
19+
valueFrom:
20+
fieldRef:
21+
fieldPath: metadata.namespace
22+
23+
resources:
24+
- servicemonitor_rbac.yaml
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: servicemonitor-manager-role
5+
rules:
6+
- apiGroups:
7+
- monitoring.coreos.com
8+
resources:
9+
- servicemonitors
10+
verbs:
11+
- get
12+
- list
13+
- watch
14+
- create
15+
- update
16+
- delete
17+
---
18+
apiVersion: rbac.authorization.k8s.io/v1
19+
kind: ClusterRoleBinding
20+
metadata:
21+
name: servicemonitor-manager-rolebinding
22+
roleRef:
23+
apiGroup: rbac.authorization.k8s.io
24+
kind: ClusterRole
25+
name: servicemonitor-manager-role
26+
subjects:
27+
- kind: ServiceAccount
28+
name: controller-manager
29+
namespace: system

‎config/overlays/production/kustomization.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ components:
99
- ../../components/certmanager
1010
- ../../components/metrics-port
1111
- ../../components/webhook-replacements
12+
- ../../components/service-monitor
1213

1314
namespace: model-validation-operator-system
1415

‎config/rbac/role.yaml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,14 @@ rules:
4343
- telemetryconfigs/status
4444
verbs:
4545
- update
46+
- apiGroups:
47+
- monitoring.coreos.com
48+
resources:
49+
- servicemonitors
50+
verbs:
51+
- create
52+
- delete
53+
- get
54+
- list
55+
- update
56+
- watch

‎go.mod‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ require (
88
github.com/go-logr/logr v1.4.3
99
github.com/onsi/ginkgo/v2 v2.29.0
1010
github.com/onsi/gomega v1.40.0
11+
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.79.2
1112
github.com/prometheus/client_golang v1.23.2
1213
github.com/prometheus/client_model v0.6.2
1314
github.com/prometheus/common v0.67.5
1415
github.com/sigstore/model-signing v0.0.0-00010101000000-000000000000
1516
github.com/sigstore/model-validation-operator/pkg/tracing v0.0.0
1617
github.com/stretchr/testify v1.11.1
17-
go.opentelemetry.io/otel v1.43.0
18-
go.opentelemetry.io/otel/trace v1.43.0
18+
go.opentelemetry.io/otel v1.44.0
19+
go.opentelemetry.io/otel/exporters/prometheus v0.60.0
20+
go.opentelemetry.io/otel/metric v1.44.0
21+
go.opentelemetry.io/otel/sdk/metric v1.44.0
22+
go.opentelemetry.io/otel/trace v1.44.0
1923
golang.org/x/time v0.15.0
2024
k8s.io/api v0.35.3
2125
k8s.io/apimachinery v0.35.3
@@ -81,6 +85,7 @@ require (
8185
github.com/google/go-containerregistry v0.21.1 // indirect
8286
github.com/google/pprof v0.0.0-20260402051712-545e8a4df936 // indirect
8387
github.com/google/uuid v1.6.0 // indirect
88+
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect
8489
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7 // indirect
8590
github.com/in-toto/attestation v1.1.2 // indirect
8691
github.com/in-toto/in-toto-golang v0.11.0 // indirect
@@ -93,7 +98,8 @@ require (
9398
github.com/opencontainers/go-digest v1.0.0 // indirect
9499
github.com/pkg/errors v0.9.1 // indirect
95100
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
96-
github.com/prometheus/procfs v0.17.0 // indirect
101+
github.com/prometheus/otlptranslator v0.0.2 // indirect
102+
github.com/prometheus/procfs v0.20.1 // indirect
97103
github.com/secure-systems-lab/go-securesystemslib v0.10.0 // indirect
98104
github.com/shibumi/go-pathspec v1.3.0 // indirect
99105
github.com/sigstore/protobuf-specs v0.5.0 // indirect
@@ -113,12 +119,11 @@ require (
113119
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0 // indirect
114120
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.34.0 // indirect
115121
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.43.0 // indirect
116-
go.opentelemetry.io/otel/metric v1.43.0 // indirect
117-
go.opentelemetry.io/otel/sdk v1.43.0 // indirect
122+
go.opentelemetry.io/otel/sdk v1.44.0 // indirect
118123
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
119124
go.uber.org/multierr v1.11.0 // indirect
120125
go.uber.org/zap v1.27.1 // indirect
121-
go.yaml.in/yaml/v2 v2.4.3 // indirect
126+
go.yaml.in/yaml/v2 v2.4.4 // indirect
122127
go.yaml.in/yaml/v3 v3.0.4 // indirect
123128
golang.org/x/crypto v0.54.0 // indirect
124129
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect

‎go.sum‎

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ github.com/googleapis/enterprise-certificate-proxy v0.3.14 h1:yh8ncqsbUY4shRD5dA
219219
github.com/googleapis/enterprise-certificate-proxy v0.3.14/go.mod h1:vqVt9yG9480NtzREnTlmGSBmFrA+bzb0yl0TxoBQXOg=
220220
github.com/googleapis/gax-go/v2 v2.19.0 h1:fYQaUOiGwll0cGj7jmHT/0nPlcrZDFPrZRhTsoCr8hE=
221221
github.com/googleapis/gax-go/v2 v2.19.0/go.mod h1:w2ROXVdfGEVFXzmlciUU4EdjHgWvB5h2n6x/8XSTTJA=
222+
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc h1:GN2Lv3MGO7AS6PrRoT6yV5+wkrOpcszoIsO4+4ds248=
223+
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc/go.mod h1:+JKpmjMGhpgPL+rXZ5nsZieVzvarn86asRlBg4uNGnk=
222224
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
223225
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
224226
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7 h1:X+2YciYSxvMQK0UZ7sg45ZVabVZBeBuvMkmuI2V3Fak=
@@ -315,14 +317,18 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
315317
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
316318
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
317319
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
320+
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.79.2 h1:DGv150w4UyxnjNHlkCw85R3+lspOxegtdnbpP2vKRrk=
321+
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.79.2/go.mod h1:AVMP4QEW8xuGWnxaWSpI3kKjP9fDA31nO68zsyREJZA=
318322
github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
319323
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
320324
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
321325
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
322326
github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4=
323327
github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw=
324-
github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0=
325-
github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw=
328+
github.com/prometheus/otlptranslator v0.0.2 h1:+1CdeLVrRQ6Psmhnobldo0kTp96Rj80DRXRd5OSnMEQ=
329+
github.com/prometheus/otlptranslator v0.0.2/go.mod h1:P8AwMgdD7XEr6QRUJ2QWLpiAZTgTE2UYgjlu3svompI=
330+
github.com/prometheus/procfs v0.20.1 h1:XwbrGOIplXW/AU3YhIhLODXMJYyC1isLFfYCsTEycfc=
331+
github.com/prometheus/procfs v0.20.1/go.mod h1:o9EMBZGRyvDrSPH1RqdxhojkuXstoe4UlK79eF5TGGo=
326332
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
327333
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
328334
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
@@ -407,22 +413,26 @@ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.6
407413
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.63.0/go.mod h1:fvPi2qXDqFs8M4B4fmJhE92TyQs9Ydjlg3RvfUp+NbQ=
408414
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 h1:RbKq8BG0FI8OiXhBfcRtqqHcZcka+gU3cskNuf05R18=
409415
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0/go.mod h1:h06DGIukJOevXaj/xrNjhi/2098RZzcLTbc0jDAUbsg=
410-
go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I=
411-
go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0=
416+
go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU=
417+
go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc=
412418
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0 h1:QKdN8ly8zEMrByybbQgv8cWBcdAarwmIPZ6FThrWXJs=
413419
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0/go.mod h1:bTdK1nhqF76qiPoCCdyFIV+N/sRHYXYCTQc+3VCi3MI=
414420
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.34.0 h1:tgJ0uaNS4c98WRNUEx5U3aDlrDOI5Rs+1Vifcw4DJ8U=
415421
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.34.0/go.mod h1:U7HYyW0zt/a9x5J1Kjs+r1f/d4ZHnYFclhYY2+YbeoE=
422+
go.opentelemetry.io/otel/exporters/prometheus v0.60.0 h1:cGtQxGvZbnrWdC2GyjZi0PDKVSLWP/Jocix3QWfXtbo=
423+
go.opentelemetry.io/otel/exporters/prometheus v0.60.0/go.mod h1:hkd1EekxNo69PTV4OWFGZcKQiIqg0RfuWExcPKFvepk=
416424
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.43.0 h1:mS47AX77OtFfKG4vtp+84kuGSFZHTyxtXIN269vChY0=
417425
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.43.0/go.mod h1:PJnsC41lAGncJlPUniSwM81gc80GkgWJWr3cu2nKEtU=
418-
go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM=
419-
go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY=
420-
go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg=
421-
go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg=
422-
go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw=
423-
go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A=
424-
go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A=
425-
go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0=
426+
go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc=
427+
go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo=
428+
go.opentelemetry.io/otel/metric/x v0.66.0 h1:YkCrx1zLOChi9ZcZ6euupOcsgzbVlec7D/xoEU1+cTA=
429+
go.opentelemetry.io/otel/metric/x v0.66.0/go.mod h1:d1+BDj9t96do0/1LoU1ayfCv79ZgNE41qbhBvnMOBZk=
430+
go.opentelemetry.io/otel/sdk v1.44.0 h1:nHYwb9lK+fJPU/dnT6s7W7Z8itMWyqrnVfbheVYrZ58=
431+
go.opentelemetry.io/otel/sdk v1.44.0/go.mod h1:Osuydd3Se74nqjAKxid74N5eC+jfEqfTegHRnq58oK0=
432+
go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRks6si09iEfI=
433+
go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA=
434+
go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk=
435+
go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE=
426436
go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A=
427437
go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4=
428438
go.step.sm/crypto v0.77.2 h1:qFjjei+RHc5kP5R7NW9OUWT7SqWIuAOvOkXqg4fNWj8=
@@ -433,8 +443,8 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
433443
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
434444
go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
435445
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
436-
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
437-
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
446+
go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
447+
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
438448
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
439449
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
440450
golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw=

‎internal/controller/helpers.go‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2025 The Sigstore Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package controller
16+
17+
func reconcileResult(err error) string {
18+
if err != nil {
19+
return "error"
20+
}
21+
return "success"
22+
}

‎internal/controller/modelvalidation_controller.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package controller
33

44
import (
55
"context"
6+
"time"
67

78
"github.com/sigstore/model-validation-operator/api/v1alpha1"
9+
"github.com/sigstore/model-validation-operator/internal/metrics"
810
"github.com/sigstore/model-validation-operator/internal/tracker"
911
"k8s.io/apimachinery/pkg/api/errors"
1012
"k8s.io/apimachinery/pkg/runtime"
@@ -25,7 +27,12 @@ type ModelValidationReconciler struct {
2527
// +kubebuilder:rbac:groups=ml.sigstore.dev,resources=modelvalidations/status,verbs=update
2628

2729
// Reconcile handles ModelValidation events to track creation/updates/deletion
28-
func (r *ModelValidationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
30+
func (r *ModelValidationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) {
31+
start := time.Now()
32+
defer func() {
33+
metrics.RecordReconcile(ctx, "modelvalidation", reconcileResult(err), time.Since(start))
34+
}()
35+
2936
logger := log.FromContext(ctx)
3037

3138
mv := &v1alpha1.ModelValidation{}

‎internal/controller/pod_controller.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package controller
33

44
import (
55
"context"
6+
"time"
67

78
"github.com/sigstore/model-validation-operator/internal/constants"
9+
"github.com/sigstore/model-validation-operator/internal/metrics"
810
"github.com/sigstore/model-validation-operator/internal/tracker"
911
corev1 "k8s.io/api/core/v1"
1012
"k8s.io/apimachinery/pkg/api/errors"
@@ -29,7 +31,12 @@ type PodReconciler struct {
2931
// +kubebuilder:rbac:groups=ml.sigstore.dev,resources=modelvalidations/status,verbs=update
3032

3133
// Reconcile handles pod events to update ModelValidation status
32-
func (r *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
34+
func (r *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) {
35+
start := time.Now()
36+
defer func() {
37+
metrics.RecordReconcile(ctx, "pod", reconcileResult(err), time.Since(start))
38+
}()
39+
3340
logger := log.FromContext(ctx)
3441

3542
pod := &corev1.Pod{}

0 commit comments

Comments
 (0)