Skip to content

Commit 24c91b5

Browse files
Merge pull request #73 from 7ing/metrics
Support prometheus metrics
2 parents 68ab00c + 139d714 commit 24c91b5

15 files changed

Lines changed: 1277 additions & 36 deletions

File tree

examples/simple/deploy/01_simple-csi-driver.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ spec:
5959
allowPrivilegeEscalation: false
6060
capabilities: { drop: [ "ALL" ] }
6161
readOnlyRootFilesystem: true
62-
image: registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.13.0
62+
image: registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.14.0
6363
args:
6464
- --v=5
6565
- --csi-address=/plugin/csi.sock
@@ -94,6 +94,10 @@ spec:
9494
fieldPath: spec.nodeName
9595
- name: CSI_ENDPOINT
9696
value: unix://plugin/csi.sock
97+
ports:
98+
- containerPort: 9402
99+
name: http-metrics
100+
protocol: TCP
97101
volumeMounts:
98102
- name: plugin-dir
99103
mountPath: /plugin

examples/simple/deploy/02_example-app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ spec:
4848
runAsUser: 2000
4949
containers:
5050
- name: my-frontend
51-
image: busybox:1.35.0
51+
image: busybox:1.36.1
5252
volumeMounts:
5353
- mountPath: "/tls"
5454
name: tls

examples/simple/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ replace github.com/cert-manager/csi-lib => ../../
77
require (
88
github.com/cert-manager/cert-manager v1.19.1
99
github.com/cert-manager/csi-lib v0.0.0-00010101000000-000000000000
10+
github.com/prometheus/client_golang v1.23.2
11+
golang.org/x/sync v0.17.0
1012
k8s.io/client-go v0.34.2
1113
k8s.io/klog/v2 v2.130.1
1214
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4
@@ -43,7 +45,6 @@ require (
4345
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
4446
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
4547
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
46-
github.com/prometheus/client_golang v1.23.2 // indirect
4748
github.com/prometheus/client_model v0.6.2 // indirect
4849
github.com/prometheus/common v0.66.1 // indirect
4950
github.com/prometheus/procfs v0.17.0 // indirect

examples/simple/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ golang.org/x/oauth2 v0.32.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwE
171171
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
172172
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
173173
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
174+
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
175+
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
174176
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
175177
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
176178
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

examples/simple/main.go

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,25 @@ import (
2828
"flag"
2929
"fmt"
3030
"net"
31+
"net/http"
3132
"net/url"
3233
"strings"
3334
"time"
3435

3536
cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
3637
cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
3738
cmclient "github.com/cert-manager/cert-manager/pkg/client/clientset/versioned"
39+
"github.com/cert-manager/cert-manager/pkg/client/informers/externalversions"
3840
"github.com/cert-manager/cert-manager/pkg/util/pki"
3941
"github.com/cert-manager/csi-lib/driver"
4042
"github.com/cert-manager/csi-lib/manager"
4143
"github.com/cert-manager/csi-lib/metadata"
44+
"github.com/cert-manager/csi-lib/metrics"
4245
"github.com/cert-manager/csi-lib/storage"
46+
"github.com/prometheus/client_golang/prometheus"
47+
"golang.org/x/sync/errgroup"
4348
"k8s.io/client-go/rest"
44-
"k8s.io/klog/v2/klogr"
49+
"k8s.io/klog/v2"
4550
"k8s.io/utils/clock"
4651
)
4752

@@ -89,7 +94,7 @@ func main() {
8994
panic("-data-root must be set")
9095
}
9196

92-
log := klogr.New()
97+
log := klog.TODO()
9398

9499
restConfig, err := rest.InClusterConfig()
95100
if err != nil {
@@ -103,13 +108,29 @@ func main() {
103108

104109
store.FSGroupVolumeAttributeKey = FsGroupKey
105110

106-
d, err := driver.New(context.Background(), *endpoint, log, driver.Options{
111+
cmClient := cmclient.NewForConfigOrDie(restConfig)
112+
113+
ctx, cancel := context.WithCancel(context.Background())
114+
defer cancel()
115+
116+
certRequestInformerFactory := externalversions.NewSharedInformerFactory(cmClient, 5*time.Second)
117+
certRequestInformer := certRequestInformerFactory.Certmanager().V1().CertificateRequests()
118+
metricsHandler := metrics.New(*nodeID, &log, prometheus.NewRegistry(), store, certRequestInformer.Lister())
119+
120+
go func() {
121+
err := startMetricsServer(ctx, metricsHandler, certRequestInformerFactory)
122+
if err != nil {
123+
panic("failed to setup metrics server: " + err.Error())
124+
}
125+
}()
126+
127+
d, err := driver.New(ctx, *endpoint, log, driver.Options{
107128
DriverName: "csi.cert-manager.io",
108129
DriverVersion: "v0.0.1",
109130
NodeID: *nodeID,
110131
Store: store,
111132
Manager: manager.NewManagerOrDie(manager.Options{
112-
Client: cmclient.NewForConfigOrDie(restConfig),
133+
Client: cmClient,
113134
MetadataReader: store,
114135
Clock: clock.RealClock{},
115136
Log: &log,
@@ -118,6 +139,7 @@ func main() {
118139
GenerateRequest: generateRequest,
119140
SignRequest: signRequest,
120141
WriteKeypair: (&writer{store: store}).writeKeypair,
142+
Metrics: metricsHandler,
121143
}),
122144
})
123145
if err != nil {
@@ -350,3 +372,49 @@ func keyUsagesFromAttributes(usagesCSV string) []cmapi.KeyUsage {
350372

351373
return keyUsages
352374
}
375+
376+
// startMetricsServer starts a server listening on port 9402, until the supplied context is cancelled,
377+
// after which the server will gracefully shutdown (within 5 seconds).
378+
func startMetricsServer(
379+
rootCtx context.Context,
380+
metricsHandler *metrics.Metrics,
381+
certRequestInformerFactory externalversions.SharedInformerFactory,
382+
) error {
383+
g, ctx := errgroup.WithContext(rootCtx)
384+
385+
listenConfig := &net.ListenConfig{}
386+
metricsLn, err := listenConfig.Listen(ctx, "tcp", ":9402")
387+
if err != nil {
388+
return err
389+
}
390+
metricsServer := &http.Server{
391+
Addr: metricsLn.Addr().String(),
392+
ReadTimeout: 8 * time.Second,
393+
WriteTimeout: 8 * time.Second,
394+
MaxHeaderBytes: 1 << 20, // 1 MiB
395+
Handler: metricsHandler.DefaultHandler(),
396+
}
397+
398+
g.Go(func() error {
399+
certRequestInformerFactory.Start(ctx.Done())
400+
certRequestInformerFactory.WaitForCacheSync(ctx.Done())
401+
return nil
402+
})
403+
g.Go(func() error {
404+
<-rootCtx.Done()
405+
// allow a timeout for graceful shutdown
406+
shutdownCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
407+
defer cancel()
408+
409+
// nolint: contextcheck
410+
return metricsServer.Shutdown(shutdownCtx)
411+
})
412+
g.Go(func() error {
413+
// starting metrics server
414+
if err := metricsServer.Serve(metricsLn); err != http.ErrServerClosed {
415+
return err
416+
}
417+
return nil
418+
})
419+
return g.Wait()
420+
}

go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/container-storage-interface/spec v1.12.0
88
github.com/go-logr/logr v1.4.3
99
github.com/kubernetes-csi/csi-lib-utils v0.23.0
10+
github.com/prometheus/client_golang v1.23.2
1011
github.com/stretchr/testify v1.11.1
1112
google.golang.org/grpc v1.77.0
1213
k8s.io/apimachinery v0.34.2
@@ -17,12 +18,15 @@ require (
1718
)
1819

1920
require (
21+
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
2022
github.com/beorn7/perks v1.0.1 // indirect
2123
github.com/blang/semver/v4 v4.0.0 // indirect
2224
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2325
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2426
github.com/emicklei/go-restful/v3 v3.13.0 // indirect
2527
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
28+
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 // indirect
29+
github.com/go-ldap/ldap/v3 v3.4.12 // indirect
2630
github.com/go-logr/zapr v1.3.0 // indirect
2731
github.com/go-openapi/jsonpointer v0.22.1 // indirect
2832
github.com/go-openapi/jsonreference v0.21.2 // indirect
@@ -35,13 +39,13 @@ require (
3539
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3640
github.com/josharian/intern v1.0.0 // indirect
3741
github.com/json-iterator/go v1.1.12 // indirect
42+
github.com/kylelemons/godebug v1.1.0 // indirect
3843
github.com/mailru/easyjson v0.9.0 // indirect
3944
github.com/moby/sys/mountinfo v0.7.2 // indirect
4045
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4146
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
4247
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
4348
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
44-
github.com/prometheus/client_golang v1.23.2 // indirect
4549
github.com/prometheus/client_model v0.6.2 // indirect
4650
github.com/prometheus/common v0.66.1 // indirect
4751
github.com/prometheus/procfs v0.17.0 // indirect
@@ -54,6 +58,7 @@ require (
5458
go.uber.org/zap v1.27.0 // indirect
5559
go.yaml.in/yaml/v2 v2.4.2 // indirect
5660
go.yaml.in/yaml/v3 v3.0.4 // indirect
61+
golang.org/x/crypto v0.43.0 // indirect
5762
golang.org/x/net v0.46.1-0.20251013234738-63d1a5100f82 // indirect
5863
golang.org/x/oauth2 v0.32.0 // indirect
5964
golang.org/x/sys v0.37.0 // indirect

go.sum

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 h1:mFRzDkZVAjdal+s7s0MwaRv9igoPqLRdzOLzw/8Xvq8=
2+
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU=
3+
github.com/alexbrainman/sspi v0.0.0-20250919150558-7d374ff0d59e h1:4dAU9FXIyQktpoUAgOJK3OTFc/xug0PCXYCqU0FgDKI=
4+
github.com/alexbrainman/sspi v0.0.0-20250919150558-7d374ff0d59e/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4=
15
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
26
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
37
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
@@ -17,6 +21,10 @@ github.com/emicklei/go-restful/v3 v3.13.0 h1:C4Bl2xDndpU6nJ4bc1jXd+uTmYPVUwkD6bF
1721
github.com/emicklei/go-restful/v3 v3.13.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
1822
github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM=
1923
github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
24+
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 h1:BP4M0CvQ4S3TGls2FvczZtj5Re/2ZzkV9VwqPHH/3Bo=
25+
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
26+
github.com/go-ldap/ldap/v3 v3.4.12 h1:1b81mv7MagXZ7+1r7cLTWmyuTqVqdwbtJSjC0DAp9s4=
27+
github.com/go-ldap/ldap/v3 v3.4.12/go.mod h1:+SPAGcTtOfmGsCb3h1RFiq4xpp4N636G75OEace8lNo=
2028
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
2129
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
2230
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
@@ -46,8 +54,22 @@ github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgY
4654
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
4755
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4856
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
57+
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
58+
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
4959
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
5060
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
61+
github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8=
62+
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
63+
github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo=
64+
github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
65+
github.com/jcmturner/gofork v1.7.6 h1:QH0l3hzAU1tfT3rZCnW5zXl+orbkNMMRGJfdJjHVETg=
66+
github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo=
67+
github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o=
68+
github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg=
69+
github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh687T8=
70+
github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs=
71+
github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY=
72+
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
5173
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
5274
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
5375
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
@@ -134,6 +156,8 @@ go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
134156
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
135157
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
136158
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
159+
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
160+
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
137161
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
138162
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
139163
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=

manager/manager.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747
internalapi "github.com/cert-manager/csi-lib/internal/api"
4848
internalapiutil "github.com/cert-manager/csi-lib/internal/api/util"
4949
"github.com/cert-manager/csi-lib/metadata"
50+
"github.com/cert-manager/csi-lib/metrics"
5051
"github.com/cert-manager/csi-lib/storage"
5152
)
5253

@@ -89,6 +90,9 @@ type Options struct {
8990

9091
// RenewalBackoffConfig configures the exponential backoff applied to certificate renewal failures.
9192
RenewalBackoffConfig *wait.Backoff
93+
94+
// Metrics is used for exposing Prometheus metrics
95+
Metrics *metrics.Metrics
9296
}
9397

9498
// NewManager constructs a new manager used to manage volumes containing
@@ -241,6 +245,7 @@ func NewManager(opts Options) (*Manager, error) {
241245
metadataReader: opts.MetadataReader,
242246
clock: opts.Clock,
243247
log: *opts.Log,
248+
metrics: opts.Metrics,
244249

245250
generatePrivateKey: opts.GeneratePrivateKey,
246251
generateRequest: opts.GenerateRequest,
@@ -368,25 +373,20 @@ type Manager struct {
368373
// Defaults to uuid.NewUUID() from k8s.io/apimachinery/pkg/util/uuid.
369374
requestNameGenerator func() string
370375

371-
// doNotUse_CallOnEachIssue is a field used SOLELY for testing, and cannot be configured by external package consumers.
372-
// It is used to perform some action (e.g. counting) each time issue() is called.
373-
// It will be removed as soon as we have actual metrics support in csi-lib, which will allow us to measure
374-
// things like the number of times issue() is called.
375-
// No thread safety is added around this field, and it MUST NOT be used for any implementation logic.
376-
// It should not be used full-stop :).
377-
doNotUse_CallOnEachIssue func()
376+
// metrics is used for Prometheus metrics collection
377+
metrics *metrics.Metrics
378378
}
379379

380380
// issue will step through the entire issuance flow for a volume.
381381
func (m *Manager) issue(ctx context.Context, volumeID string) error {
382-
// TODO: remove this code and replace with actual metrics support
383-
if m.doNotUse_CallOnEachIssue != nil {
384-
m.doNotUse_CallOnEachIssue()
385-
}
386-
387382
log := m.log.WithValues("volume_id", volumeID)
388383
log.Info("Processing issuance")
389384

385+
// Increase issue count
386+
if m.metrics != nil {
387+
m.metrics.IncrementIssueCallCountTotal(m.nodeNameHash, volumeID)
388+
}
389+
390390
if err := m.cleanupStaleRequests(ctx, log, volumeID); err != nil {
391391
return fmt.Errorf("cleaning up stale requests: %w", err)
392392
}
@@ -756,6 +756,10 @@ func (m *Manager) ManageVolumeImmediate(ctx context.Context, volumeID string) (m
756756
// If issuance fails, immediately return without retrying so the caller can decide
757757
// how to proceed depending on the context this method was called within.
758758
if err := m.issue(ctx, volumeID); err != nil {
759+
// Increase issue error count
760+
if m.metrics != nil {
761+
m.metrics.IncrementIssueErrorCountTotal(m.nodeNameHash, volumeID)
762+
}
759763
return true, err
760764
}
761765
}
@@ -835,6 +839,10 @@ func (m *Manager) startRenewalRoutine(volumeID string) (started bool) {
835839
defer issueCancel()
836840
if err := m.issue(issueCtx, volumeID); err != nil {
837841
log.Error(err, "Failed to issue certificate, retrying after applying exponential backoff")
842+
// Increase issue error count
843+
if m.metrics != nil {
844+
m.metrics.IncrementIssueErrorCountTotal(m.nodeNameHash, volumeID)
845+
}
838846
return false, nil
839847
}
840848
return true, nil

0 commit comments

Comments
 (0)