Skip to content

Commit a1fed8a

Browse files
7ingwallrj-cyberark
authored andcommitted
Enable csi-lib metrics
Based on cert-manager/csi-lib#73 Signed-off-by: Jing Liu <jingliu@apple.com> Signed-off-by: Richard Wall <richard.wall@cyberark.com>
1 parent 17a2bfb commit a1fed8a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

cmd/app/app.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,21 @@ import (
2424
"encoding/pem"
2525
"fmt"
2626
"net/http"
27+
"time"
2728

29+
"github.com/cert-manager/cert-manager/pkg/client/informers/externalversions"
2830
"github.com/cert-manager/csi-lib/driver"
2931
"github.com/cert-manager/csi-lib/manager"
3032
"github.com/cert-manager/csi-lib/manager/util"
3133
"github.com/cert-manager/csi-lib/metadata"
34+
csimetrics "github.com/cert-manager/csi-lib/metrics"
3235
"github.com/cert-manager/csi-lib/storage"
36+
"github.com/prometheus/client_golang/prometheus"
3337
"github.com/spf13/cobra"
3438
"golang.org/x/sync/errgroup"
3539
"k8s.io/utils/clock"
3640
ctrl "sigs.k8s.io/controller-runtime"
41+
ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"
3742
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3843

3944
"github.com/cert-manager/csi-driver/cmd/app/options"
@@ -80,6 +85,16 @@ func NewCommand(ctx context.Context) *cobra.Command {
8085
clientForMeta = util.ClientForMetadataTokenRequestEmptyAud(opts.RestConfig)
8186
}
8287

88+
certRequestInformerFactory := externalversions.NewSharedInformerFactory(opts.CMClient, 5*time.Second)
89+
certRequestInformer := certRequestInformerFactory.Certmanager().V1().CertificateRequests()
90+
metricsHandler := csimetrics.New(
91+
opts.NodeID,
92+
&opts.Logr,
93+
ctrlmetrics.Registry.(*prometheus.Registry),
94+
store,
95+
certRequestInformer.Lister(),
96+
)
97+
8398
mngrlog := opts.Logr.WithName("manager")
8499
d, err := driver.New(ctx, opts.Endpoint, opts.Logr.WithName("driver"), driver.Options{
85100
DriverName: opts.DriverName,
@@ -97,6 +112,7 @@ func NewCommand(ctx context.Context) *cobra.Command {
97112
GenerateRequest: requestgen.RequestForMetadata,
98113
SignRequest: signRequest,
99114
WriteKeypair: writer.WriteKeypair,
115+
Metrics: metricsHandler,
100116
}),
101117
})
102118
if err != nil {
@@ -163,6 +179,12 @@ func NewCommand(ctx context.Context) *cobra.Command {
163179
g.Go(func() error {
164180
return metricsServer.Start(gCTX)
165181
})
182+
183+
g.Go(func() error {
184+
certRequestInformerFactory.Start(gCTX.Done())
185+
certRequestInformerFactory.WaitForCacheSync(gCTX.Done())
186+
return nil
187+
})
166188
}
167189
return g.Wait()
168190
},

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/go-logr/logr v1.4.3
99
github.com/onsi/ginkgo/v2 v2.27.3
1010
github.com/onsi/gomega v1.38.3
11+
github.com/prometheus/client_golang v1.23.2
1112
github.com/spf13/cobra v1.10.2
1213
github.com/spf13/pflag v1.0.10
1314
github.com/stretchr/testify v1.11.1
@@ -70,7 +71,6 @@ require (
7071
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
7172
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
7273
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
73-
github.com/prometheus/client_golang v1.23.2 // indirect
7474
github.com/prometheus/client_model v0.6.2 // indirect
7575
github.com/prometheus/common v0.66.1 // indirect
7676
github.com/prometheus/procfs v0.17.0 // indirect

0 commit comments

Comments
 (0)