From 8b9a05fe8208499e63d6fc2fa5e5ba825f0c0b1f Mon Sep 17 00:00:00 2001 From: Han Kang Date: Mon, 19 Aug 2019 11:04:40 -0700 Subject: [PATCH] add delete to gaugeVec, histogramVec, summaryVec since kubelet requires it --- staging/src/k8s.io/component-base/metrics/gauge.go | 14 ++++++++++++++ .../src/k8s.io/component-base/metrics/histogram.go | 14 ++++++++++++++ .../src/k8s.io/component-base/metrics/summary.go | 14 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/staging/src/k8s.io/component-base/metrics/gauge.go b/staging/src/k8s.io/component-base/metrics/gauge.go index 1c54d408da6..82b982d9d6c 100644 --- a/staging/src/k8s.io/component-base/metrics/gauge.go +++ b/staging/src/k8s.io/component-base/metrics/gauge.go @@ -148,3 +148,17 @@ func (v *GaugeVec) With(labels prometheus.Labels) GaugeMetric { } return v.GaugeVec.With(labels) } + +// Delete deletes the metric where the variable labels are the same as those +// passed in as labels. It returns true if a metric was deleted. +// +// It is not an error if the number and names of the Labels are inconsistent +// with those of the VariableLabels in Desc. However, such inconsistent Labels +// can never match an actual metric, so the method will always return false in +// that case. +func (v *GaugeVec) Delete(labels prometheus.Labels) bool { + if !v.IsCreated() { + return false // since we haven't created the metric, we haven't deleted a metric with the passed in values + } + return v.GaugeVec.Delete(labels) +} diff --git a/staging/src/k8s.io/component-base/metrics/histogram.go b/staging/src/k8s.io/component-base/metrics/histogram.go index 2ca5849a24c..38d2d416477 100644 --- a/staging/src/k8s.io/component-base/metrics/histogram.go +++ b/staging/src/k8s.io/component-base/metrics/histogram.go @@ -143,3 +143,17 @@ func (v *HistogramVec) With(labels prometheus.Labels) ObserverMetric { } return v.HistogramVec.With(labels) } + +// Delete deletes the metric where the variable labels are the same as those +// passed in as labels. It returns true if a metric was deleted. +// +// It is not an error if the number and names of the Labels are inconsistent +// with those of the VariableLabels in Desc. However, such inconsistent Labels +// can never match an actual metric, so the method will always return false in +// that case. +func (v *HistogramVec) Delete(labels prometheus.Labels) bool { + if !v.IsCreated() { + return false // since we haven't created the metric, we haven't deleted a metric with the passed in values + } + return v.HistogramVec.Delete(labels) +} diff --git a/staging/src/k8s.io/component-base/metrics/summary.go b/staging/src/k8s.io/component-base/metrics/summary.go index 56d7fcc9d6d..ff573782245 100644 --- a/staging/src/k8s.io/component-base/metrics/summary.go +++ b/staging/src/k8s.io/component-base/metrics/summary.go @@ -150,3 +150,17 @@ func (v *SummaryVec) With(labels prometheus.Labels) ObserverMetric { } return v.SummaryVec.With(labels) } + +// Delete deletes the metric where the variable labels are the same as those +// passed in as labels. It returns true if a metric was deleted. +// +// It is not an error if the number and names of the Labels are inconsistent +// with those of the VariableLabels in Desc. However, such inconsistent Labels +// can never match an actual metric, so the method will always return false in +// that case. +func (v *SummaryVec) Delete(labels prometheus.Labels) bool { + if !v.IsCreated() { + return false // since we haven't created the metric, we haven't deleted a metric with the passed in values + } + return v.SummaryVec.Delete(labels) +}