@@ -145,6 +145,22 @@ func WithLabels(labels map[string]string) MetricsManagerOption {
145
145
}
146
146
}
147
147
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
+
148
164
// NewCSIMetricsManagerForSidecar creates and registers metrics for CSI Sidecars and
149
165
// returns an object that can be used to trigger the metrics. It uses "csi_sidecar"
150
166
// as subsystem.
@@ -177,18 +193,22 @@ func NewCSIMetricsManagerForPlugin(driverName string) CSIMetricsManager {
177
193
// If unknown, leave empty, and use SetDriverName method to update later.
178
194
func NewCSIMetricsManagerWithOptions (driverName string , options ... MetricsManagerOption ) CSIMetricsManager {
179
195
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 ,
183
200
}
184
201
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
-
189
202
for _ , option := range options {
190
203
option (& cmm )
191
204
}
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
+
192
212
labels := []string {labelCSIDriverName , labelCSIOperationName , labelGrpcStatusCode }
193
213
labels = append (labels , cmm .additionalLabelNames ... )
194
214
for _ , label := range cmm .additionalLabels {
@@ -219,6 +239,7 @@ type csiMetricsManager struct {
219
239
additionalLabelNames []string
220
240
additionalLabels []label
221
241
csiOperationsLatencyMetric * metrics.HistogramVec
242
+ registerProcessStartTime bool
222
243
}
223
244
224
245
type label struct {
0 commit comments