@@ -145,6 +145,22 @@ func WithLabels(labels map[string]string) MetricsManagerOption {
145145 }
146146}
147147
148+ // WithProcessStartTime controlls whether process_start_time_seconds is registered
149+ // in the registry of the metrics manager. It's enabled by default out of convenience
150+ // (no need to do anything special in most sidecars) but should be disabled in more
151+ // complex scenarios (more than one metrics manager per process, metric already
152+ // provided elsewhere like via the Prometheus Golang collector).
153+ //
154+ // In particular, registering this metric via metric manager and thus the Kubernetes
155+ // component base conflicts with the Prometheus Golang collector (gathered metric family
156+ // process_start_time_seconds has help "[ALPHA] Start time of the process since unix epoch in seconds."
157+ // but should have "Start time of the process since unix epoch in seconds."
158+ func WithProcessStartTime (registerProcessStartTime bool ) MetricsManagerOption {
159+ return func (cmm * csiMetricsManager ) {
160+ cmm .registerProcessStartTime = registerProcessStartTime
161+ }
162+ }
163+
148164// NewCSIMetricsManagerForSidecar creates and registers metrics for CSI Sidecars and
149165// returns an object that can be used to trigger the metrics. It uses "csi_sidecar"
150166// as subsystem.
@@ -177,18 +193,22 @@ func NewCSIMetricsManagerForPlugin(driverName string) CSIMetricsManager {
177193// If unknown, leave empty, and use SetDriverName method to update later.
178194func NewCSIMetricsManagerWithOptions (driverName string , options ... MetricsManagerOption ) CSIMetricsManager {
179195 cmm := csiMetricsManager {
180- registry : metrics .NewKubeRegistry (),
181- subsystem : SubsystemSidecar ,
182- stabilityLevel : metrics .ALPHA ,
196+ registry : metrics .NewKubeRegistry (),
197+ subsystem : SubsystemSidecar ,
198+ stabilityLevel : metrics .ALPHA ,
199+ registerProcessStartTime : true ,
183200 }
184201
185- // https://github.com/open-telemetry/opentelemetry-collector/issues/969
186- // Add process_start_time_seconds into the metric to let the start time be parsed correctly
187- metrics .RegisterProcessStartTime (cmm .registry .Register )
188-
189202 for _ , option := range options {
190203 option (& cmm )
191204 }
205+
206+ if cmm .registerProcessStartTime {
207+ // https://github.com/open-telemetry/opentelemetry-collector/issues/969
208+ // Add process_start_time_seconds into the metric to let the start time be parsed correctly
209+ metrics .RegisterProcessStartTime (cmm .registry .Register )
210+ }
211+
192212 labels := []string {labelCSIDriverName , labelCSIOperationName , labelGrpcStatusCode }
193213 labels = append (labels , cmm .additionalLabelNames ... )
194214 for _ , label := range cmm .additionalLabels {
@@ -219,6 +239,7 @@ type csiMetricsManager struct {
219239 additionalLabelNames []string
220240 additionalLabels []label
221241 csiOperationsLatencyMetric * metrics.HistogramVec
242+ registerProcessStartTime bool
222243}
223244
224245type label struct {
0 commit comments