@@ -148,7 +148,7 @@ func (c *Controller[T]) reconcile(ctx context.Context, req reconcile.Request, o
148
148
MetricLabelName : req .Name ,
149
149
})
150
150
if deletionTS , ok := c .terminatingObjects .Load (req ); ok {
151
- c .observeHistogram (c .TerminationDuration , TerminationDuration , time .Since (deletionTS .(* metav1.Time ).Time ).Seconds (), c .toAdditionalMetricLabels (o ))
151
+ c .observeHistogram (c .TerminationDuration , TerminationDuration , time .Since (deletionTS .(* metav1.Time ).Time ).Seconds (), map [ string ] string {}, c .toAdditionalMetricLabels (o ))
152
152
}
153
153
if finalizers , ok := c .observedFinalizers .LoadAndDelete (req ); ok {
154
154
for _ , finalizer := range finalizers .([]string ) {
@@ -169,10 +169,10 @@ func (c *Controller[T]) reconcile(ctx context.Context, req reconcile.Request, o
169
169
}
170
170
171
171
if o .GetDeletionTimestamp () != nil {
172
- c .setGaugeMetric (c .TerminationCurrentTimeSeconds , TerminationCurrentTimeSeconds , time .Since (o .GetDeletionTimestamp ().Time ).Seconds (), lo . Assign ( map [string ]string {
172
+ c .setGaugeMetric (c .TerminationCurrentTimeSeconds , TerminationCurrentTimeSeconds , time .Since (o .GetDeletionTimestamp ().Time ).Seconds (), map [string ]string {
173
173
MetricLabelNamespace : req .Namespace ,
174
174
MetricLabelName : req .Name ,
175
- }, c .toAdditionalMetricLabels (o )))
175
+ }, c .toAdditionalMetricLabels (o ))
176
176
c .terminatingObjects .Store (req , o .GetDeletionTimestamp ())
177
177
}
178
178
@@ -185,32 +185,32 @@ func (c *Controller[T]) reconcile(ctx context.Context, req reconcile.Request, o
185
185
c .observedConditions .Store (req , currentConditions )
186
186
187
187
for _ , condition := range o .GetConditions () {
188
- c .setGaugeMetric (c .ConditionCount , ConditionCount , 1 , lo . Assign ( map [string ]string {
188
+ c .setGaugeMetric (c .ConditionCount , ConditionCount , 1 , map [string ]string {
189
189
MetricLabelNamespace : req .Namespace ,
190
190
MetricLabelName : req .Name ,
191
191
pmetrics .LabelType : condition .Type ,
192
192
MetricLabelConditionStatus : string (condition .Status ),
193
193
pmetrics .LabelReason : condition .Reason ,
194
- }, c .toAdditionalMetricLabels (o )))
195
- c .setGaugeMetric (c .ConditionCurrentStatusSeconds , ConditionCurrentStatusSeconds , time .Since (condition .LastTransitionTime .Time ).Seconds (), lo . Assign ( map [string ]string {
194
+ }, c .toAdditionalMetricLabels (o ))
195
+ c .setGaugeMetric (c .ConditionCurrentStatusSeconds , ConditionCurrentStatusSeconds , time .Since (condition .LastTransitionTime .Time ).Seconds (), map [string ]string {
196
196
MetricLabelNamespace : req .Namespace ,
197
197
MetricLabelName : req .Name ,
198
198
pmetrics .LabelType : condition .Type ,
199
199
MetricLabelConditionStatus : string (condition .Status ),
200
200
pmetrics .LabelReason : condition .Reason ,
201
- }, c .toAdditionalMetricLabels (o )))
201
+ }, c .toAdditionalMetricLabels (o ))
202
202
}
203
203
204
204
for _ , observedCondition := range observedConditions .List () {
205
205
if currentCondition := currentConditions .Get (observedCondition .Type ); currentCondition == nil || currentCondition .Status != observedCondition .Status {
206
- c .deleteGaugeMetric (c .ConditionCount , ConditionCount , map [string ]string {
206
+ c .deletePartialMatchGaugeMetric (c .ConditionCount , ConditionCount , map [string ]string {
207
207
MetricLabelNamespace : req .Namespace ,
208
208
MetricLabelName : req .Name ,
209
209
pmetrics .LabelType : observedCondition .Type ,
210
210
MetricLabelConditionStatus : string (observedCondition .Status ),
211
211
pmetrics .LabelReason : observedCondition .Reason ,
212
212
})
213
- c .deleteGaugeMetric (c .ConditionCurrentStatusSeconds , ConditionCurrentStatusSeconds , map [string ]string {
213
+ c .deletePartialMatchGaugeMetric (c .ConditionCurrentStatusSeconds , ConditionCurrentStatusSeconds , map [string ]string {
214
214
MetricLabelNamespace : req .Namespace ,
215
215
MetricLabelName : req .Name ,
216
216
pmetrics .LabelType : observedCondition .Type ,
@@ -241,19 +241,19 @@ func (c *Controller[T]) reconcile(ctx context.Context, req reconcile.Request, o
241
241
continue
242
242
}
243
243
// A condition transitions if it either didn't exist before or it has changed
244
- c .incCounterMetric (c .ConditionTransitionsTotal , ConditionTransitionsTotal , lo . Assign ( map [string ]string {
244
+ c .incCounterMetric (c .ConditionTransitionsTotal , ConditionTransitionsTotal , map [string ]string {
245
245
pmetrics .LabelType : condition .Type ,
246
246
MetricLabelConditionStatus : string (condition .Status ),
247
247
pmetrics .LabelReason : condition .Reason ,
248
- }, c .toAdditionalMetricLabels (o )))
248
+ }, c .toAdditionalMetricLabels (o ))
249
249
if observedCondition == nil {
250
250
continue
251
251
}
252
252
duration := condition .LastTransitionTime .Time .Sub (observedCondition .LastTransitionTime .Time ).Seconds ()
253
- c .observeHistogram (c .ConditionDuration , ConditionDuration , duration , lo . Assign ( map [string ]string {
253
+ c .observeHistogram (c .ConditionDuration , ConditionDuration , duration , map [string ]string {
254
254
pmetrics .LabelType : observedCondition .Type ,
255
255
MetricLabelConditionStatus : string (observedCondition .Status ),
256
- }, c .toAdditionalMetricLabels (o )))
256
+ }, c .toAdditionalMetricLabels (o ))
257
257
c .eventRecorder .Event (o , v1 .EventTypeNormal , condition .Type , fmt .Sprintf ("Status condition transitioned, Type: %s, Status: %s -> %s, Reason: %s%s" ,
258
258
condition .Type ,
259
259
observedCondition .Status ,
@@ -265,33 +265,24 @@ func (c *Controller[T]) reconcile(ctx context.Context, req reconcile.Request, o
265
265
return reconcile.Result {RequeueAfter : time .Second * 10 }, nil
266
266
}
267
267
268
- func (c * Controller [T ]) incCounterMetric (current pmetrics.CounterMetric , deprecated pmetrics.CounterMetric , labels map [string ]string ) {
269
- current .Inc (labels )
268
+ func (c * Controller [T ]) incCounterMetric (current pmetrics.CounterMetric , deprecated pmetrics.CounterMetric , labels , additionalLabels map [string ]string ) {
269
+ current .Inc (lo . Assign ( labels , additionalLabels ) )
270
270
if c .emitDeprecatedMetrics {
271
271
labels [pmetrics .LabelKind ] = c .gvk .Kind
272
272
labels [pmetrics .LabelGroup ] = c .gvk .Group
273
273
deprecated .Inc (labels )
274
274
}
275
275
}
276
276
277
- func (c * Controller [T ]) setGaugeMetric (current pmetrics.GaugeMetric , deprecated pmetrics.GaugeMetric , value float64 , labels map [string ]string ) {
278
- current .Set (value , labels )
277
+ func (c * Controller [T ]) setGaugeMetric (current pmetrics.GaugeMetric , deprecated pmetrics.GaugeMetric , value float64 , labels , additionalLabels map [string ]string ) {
278
+ current .Set (value , lo . Assign ( labels , additionalLabels ) )
279
279
if c .emitDeprecatedMetrics {
280
280
labels [pmetrics .LabelKind ] = c .gvk .Kind
281
281
labels [pmetrics .LabelGroup ] = c .gvk .Group
282
282
deprecated .Set (value , labels )
283
283
}
284
284
}
285
285
286
- func (c * Controller [T ]) deleteGaugeMetric (current pmetrics.GaugeMetric , deprecated pmetrics.GaugeMetric , labels map [string ]string ) {
287
- current .DeletePartialMatch (labels )
288
- if c .emitDeprecatedMetrics {
289
- labels [pmetrics .LabelKind ] = c .gvk .Kind
290
- labels [pmetrics .LabelGroup ] = c .gvk .Group
291
- deprecated .Delete (labels )
292
- }
293
- }
294
-
295
286
func (c * Controller [T ]) deletePartialMatchGaugeMetric (current pmetrics.GaugeMetric , deprecated pmetrics.GaugeMetric , labels map [string ]string ) {
296
287
current .DeletePartialMatch (labels )
297
288
if c .emitDeprecatedMetrics {
@@ -301,8 +292,8 @@ func (c *Controller[T]) deletePartialMatchGaugeMetric(current pmetrics.GaugeMetr
301
292
}
302
293
}
303
294
304
- func (c * Controller [T ]) observeHistogram (current pmetrics.ObservationMetric , deprecated pmetrics.ObservationMetric , value float64 , labels map [string ]string ) {
305
- current .Observe (value , labels )
295
+ func (c * Controller [T ]) observeHistogram (current pmetrics.ObservationMetric , deprecated pmetrics.ObservationMetric , value float64 , labels , additionalLabels map [string ]string ) {
296
+ current .Observe (value , lo . Assign ( labels , additionalLabels ) )
306
297
if c .emitDeprecatedMetrics {
307
298
labels [pmetrics .LabelKind ] = c .gvk .Kind
308
299
labels [pmetrics .LabelGroup ] = c .gvk .Group
0 commit comments