@@ -80,16 +80,6 @@ func (m *MetricVec) DeleteLabelValues(lvs ...string) bool {
80
80
return m .metricMap .deleteByHashWithLabelValues (h , lvs , m .curry )
81
81
}
82
82
83
- // DeletePartialMatchLabelValues deletes all metrics where the variable labels
84
- // contain all of the values passed. The order of the passed values does not matter.
85
- // It returns the number of metrics deleted.
86
-
87
- // This method deletes a metric if the given value is present for any label.
88
- // To delete a metric based on a partial match for a particular label, use DeletePartialMatch().
89
- func (m * MetricVec ) DeletePartialMatchLabelValues (lvs ... string ) int {
90
- return m .metricMap .deleteByLabelValues (lvs )
91
- }
92
-
93
83
// Delete deletes the metric where the variable labels are the same as those
94
84
// passed in as labels. It returns true if a metric was deleted.
95
85
//
@@ -116,7 +106,7 @@ func (m *MetricVec) Delete(labels Labels) bool {
116
106
// This method deletes a metric if the given label: value pair is found in that metric.
117
107
// To delete a metric if a particular value is found associated with any label, use DeletePartialMatchLabelValues().
118
108
func (m * MetricVec ) DeletePartialMatch (labels Labels ) int {
119
- return m .metricMap .deleteByLabels (labels )
109
+ return m .metricMap .deleteByLabels (labels , m . curry )
120
110
}
121
111
122
112
// Without explicit forwarding of Describe, Collect, Reset, those methods won't
@@ -373,51 +363,6 @@ func (m *metricMap) deleteByHashWithLabelValues(
373
363
return true
374
364
}
375
365
376
- // deleteByLabelValues deletes a metric if the given values (lvs) are present in the metric.
377
- func (m * metricMap ) deleteByLabelValues (lvs []string ) int {
378
- m .mtx .Lock ()
379
- defer m .mtx .Unlock ()
380
-
381
- var numDeleted int
382
-
383
- for h , metrics := range m .metrics {
384
- i := findMetricWithPartialLabelValues (metrics , lvs )
385
- if i >= len (metrics ) {
386
- // Didn't find matching label values in this metric slice.
387
- continue
388
- }
389
- delete (m .metrics , h )
390
- numDeleted ++
391
- }
392
-
393
- return numDeleted
394
- }
395
-
396
- // findMetricWithPartialLabelValues returns the index of the matching metric or
397
- // len(metrics) if not found.
398
- func findMetricWithPartialLabelValues (
399
- metrics []metricWithLabelValues , lvs []string ,
400
- ) int {
401
- for i , metric := range metrics {
402
- if matchPartialLabelValues (metric .values , lvs ) {
403
- return i
404
- }
405
- }
406
- return len (metrics )
407
- }
408
-
409
- // matchPartialLabelValues searches the current metric values and returns whether all of the target values are present.
410
- func matchPartialLabelValues (values []string , lvs []string ) bool {
411
- for _ , v := range lvs {
412
- // Check if the target value exists in our metrics and get the index.
413
- if _ , validValue := indexOf (v , values ); validValue {
414
- continue
415
- }
416
- return false
417
- }
418
- return true
419
- }
420
-
421
366
// deleteByHashWithLabels removes the metric from the hash bucket h. If there
422
367
// are multiple matches in the bucket, use lvs to select a metric and remove
423
368
// only that metric.
@@ -447,14 +392,14 @@ func (m *metricMap) deleteByHashWithLabels(
447
392
}
448
393
449
394
// deleteByLabels deletes a metric if the given labels are present in the metric.
450
- func (m * metricMap ) deleteByLabels (labels Labels ) int {
395
+ func (m * metricMap ) deleteByLabels (labels Labels , curry [] curriedLabelValue ) int {
451
396
m .mtx .Lock ()
452
397
defer m .mtx .Unlock ()
453
398
454
399
var numDeleted int
455
400
456
401
for h , metrics := range m .metrics {
457
- i := findMetricWithPartialLabels (m .desc , metrics , labels )
402
+ i := findMetricWithPartialLabels (m .desc , metrics , labels , curry )
458
403
if i >= len (metrics ) {
459
404
// Didn't find matching labels in this metric slice.
460
405
continue
@@ -469,10 +414,10 @@ func (m *metricMap) deleteByLabels(labels Labels) int {
469
414
// findMetricWithPartialLabel returns the index of the matching metric or
470
415
// len(metrics) if not found.
471
416
func findMetricWithPartialLabels (
472
- desc * Desc , metrics []metricWithLabelValues , labels Labels ,
417
+ desc * Desc , metrics []metricWithLabelValues , labels Labels , curry [] curriedLabelValue ,
473
418
) int {
474
419
for i , metric := range metrics {
475
- if matchPartialLabels (desc , metric .values , labels ) {
420
+ if matchPartialLabels (desc , metric .values , labels , curry ) {
476
421
return i
477
422
}
478
423
}
@@ -490,13 +435,28 @@ func indexOf(target string, items []string) (int, bool) {
490
435
return len (items ), false
491
436
}
492
437
438
+ // valueOrCurriedValue determines if a value was previously curried,
439
+ // and returns either the "base" value or the curried value accordingly.
440
+ func valueOrCurriedValue (index int , values []string , curry []curriedLabelValue ) string {
441
+ for _ , curriedValue := range curry {
442
+ if curriedValue .index == index {
443
+ return curriedValue .value
444
+ }
445
+ }
446
+ return values [index ]
447
+ }
448
+
493
449
// matchPartialLabels searches the current metric and returns whether all of the target label:value pairs are present.
494
- func matchPartialLabels (desc * Desc , values []string , labels Labels ) bool {
450
+ func matchPartialLabels (desc * Desc , values []string , labels Labels , curry [] curriedLabelValue ) bool {
495
451
for l , v := range labels {
496
452
// Check if the target label exists in our metrics and get the index.
497
453
varLabelIndex , validLabel := indexOf (l , desc .variableLabels )
498
454
if validLabel {
499
455
// Check the value of that label against the target value.
456
+ // if valueOrCurriedValue(varLabelIndex, values, curry) == v {
457
+ // continue
458
+ // }
459
+
500
460
if values [varLabelIndex ] == v {
501
461
continue
502
462
0 commit comments