@@ -25,6 +25,7 @@ import (
2525 "strings"
2626 "time"
2727
28+ "github.com/prometheus/client_golang/prometheus"
2829 "google.golang.org/grpc/codes"
2930 "google.golang.org/grpc/status"
3031 "k8s.io/component-base/metrics"
@@ -91,6 +92,11 @@ type CSIMetricsManager interface {
9192 // value is defined in the metrics manager
9293 HaveAdditionalLabel (name string ) bool
9394
95+ // WithAdditionalRegistry can be used to ensure additional non-CSI registries are served through RegisterToServer
96+ //
97+ // registry - Any registry which implements Gather() (e.g. metrics.KubeRegistry, prometheus.Registry, etc.)
98+ WithAdditionalRegistry (registry prometheus.Gatherer ) CSIMetricsManager
99+
94100 // SetDriverName is called to update the CSI driver name. This should be done
95101 // as soon as possible, otherwise metrics recorded by this manager will be
96102 // recorded with an "unknown-driver" driver_name.
@@ -242,11 +248,6 @@ func NewCSIMetricsManagerWithOptions(driverName string, options ...MetricsManage
242248 // https://github.com/open-telemetry/opentelemetry-collector/issues/969
243249 // Add process_start_time_seconds into the metric to let the start time be parsed correctly
244250 metrics .RegisterProcessStartTime (cmm .registry .Register )
245- // TODO: This is a bug in component-base library. We need to remove this after upgrade component-base dependency
246- // BugFix: https://github.com/kubernetes/kubernetes/pull/96435
247- // The first call to RegisterProcessStartTime can only create the metric, so we need a second call to actually
248- // register the metric.
249- metrics .RegisterProcessStartTime (cmm .registry .Register )
250251 }
251252
252253 labels := []string {labelCSIDriverName , labelCSIOperationName , labelGrpcStatusCode }
@@ -266,6 +267,9 @@ func NewCSIMetricsManagerWithOptions(driverName string, options ...MetricsManage
266267 )
267268 cmm .SetDriverName (driverName )
268269 cmm .registerMetrics ()
270+ cmm .gatherers = prometheus.Gatherers {
271+ cmm .GetRegistry (),
272+ }
269273 return & cmm
270274}
271275
@@ -278,6 +282,7 @@ type csiMetricsManager struct {
278282 driverName string
279283 additionalLabelNames []string
280284 additionalLabels []label
285+ gatherers prometheus.Gatherers
281286 csiOperationsLatencyMetric * metrics.HistogramVec
282287 registerProcessStartTime bool
283288}
@@ -367,6 +372,14 @@ func (cmm *csiMetricsManager) HaveAdditionalLabel(name string) bool {
367372 return false
368373}
369374
375+ // WithAdditionalRegistry can be used to ensure additional non-CSI registries are served through RegisterToServer
376+ //
377+ // registry - Any registry which implements Gather() (e.g. metrics.KubeRegistry, prometheus.Registry, etc.)
378+ func (cmm * csiMetricsManager ) WithAdditionalRegistry (registry prometheus.Gatherer ) CSIMetricsManager {
379+ cmm .gatherers = append (cmm .gatherers , registry )
380+ return cmm
381+ }
382+
370383// RecordMetrics passes the stored values as to the implementation.
371384func (cmmv * csiMetricsManagerWithValues ) RecordMetrics (
372385 operationName string ,
@@ -390,7 +403,7 @@ func (cmm *csiMetricsManager) SetDriverName(driverName string) {
390403// given server at the specified address/path.
391404func (cmm * csiMetricsManager ) RegisterToServer (s Server , metricsPath string ) {
392405 s .Handle (metricsPath , metrics .HandlerFor (
393- cmm .GetRegistry () ,
406+ cmm .gatherers ,
394407 metrics.HandlerOpts {
395408 ErrorHandling : metrics .ContinueOnError }))
396409}
0 commit comments