From d654dbafac6ccfde77ba9611c7c36e09d6c4ca73 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 26 Mar 2020 11:55:44 -0400 Subject: [PATCH] Allow the id for cgroup metrics to be changed This makes the metrics package more extensible by allowing the default name of `container_id` to be changed by the package caller. Signed-off-by: Michael Crosby --- metrics/cgroups/v1/metric.go | 5 ++++- metrics/cgroups/v2/metric.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/metrics/cgroups/v1/metric.go b/metrics/cgroups/v1/metric.go index 14a9410b9249..dd9c303140f6 100644 --- a/metrics/cgroups/v1/metric.go +++ b/metrics/cgroups/v1/metric.go @@ -24,6 +24,9 @@ import ( "github.com/prometheus/client_golang/prometheus" ) +// IDName is the name that is used to identify the id being collected in the metric +var IDName = "container_id" + type value struct { v float64 l []string @@ -41,7 +44,7 @@ type metric struct { func (m *metric) desc(ns *metrics.Namespace) *prometheus.Desc { // the namespace label is for containerd namespaces - return ns.NewDesc(m.name, m.help, m.unit, append([]string{"container_id", "namespace"}, m.labels...)...) + return ns.NewDesc(m.name, m.help, m.unit, append([]string{IDName, "namespace"}, m.labels...)...) } func (m *metric) collect(id, namespace string, stats *v1.Metrics, ns *metrics.Namespace, ch chan<- prometheus.Metric, block bool) { diff --git a/metrics/cgroups/v2/metric.go b/metrics/cgroups/v2/metric.go index 1b8a8e13935a..ea995d243133 100644 --- a/metrics/cgroups/v2/metric.go +++ b/metrics/cgroups/v2/metric.go @@ -24,6 +24,9 @@ import ( "github.com/prometheus/client_golang/prometheus" ) +// IDName is the name that is used to identify the id being collected in the metric +var IDName = "container_id" + type value struct { v float64 l []string @@ -41,7 +44,7 @@ type metric struct { func (m *metric) desc(ns *metrics.Namespace) *prometheus.Desc { // the namespace label is for containerd namespaces - return ns.NewDesc(m.name, m.help, m.unit, append([]string{"container_id", "namespace"}, m.labels...)...) + return ns.NewDesc(m.name, m.help, m.unit, append([]string{IDName, "namespace"}, m.labels...)...) } func (m *metric) collect(id, namespace string, stats *v2.Metrics, ns *metrics.Namespace, ch chan<- prometheus.Metric, block bool) {