From ac695f36bb64c129d6251b6696ec18c71fff4df5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 1 Feb 2023 12:00:50 -0800 Subject: [PATCH] lib/promscrape: add a comment explaining the logic behind adding `exported_` perfix to metric names This is a follow-up for 7b87fac8e7eaae9deef68a9812de5bd4aee292e7 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3557 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3406 --- lib/promscrape/scrapework.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/promscrape/scrapework.go b/lib/promscrape/scrapework.go index 95f068b807..98e564d8d1 100644 --- a/lib/promscrape/scrapework.go +++ b/lib/promscrape/scrapework.go @@ -904,14 +904,24 @@ func (sw *scrapeWork) addAutoTimeseries(wc *writeRequestCtx, name string, value func (sw *scrapeWork) addRowToTimeseries(wc *writeRequestCtx, r *parser.Row, timestamp int64, needRelabel bool) { metric := r.Metric - if needRelabel && isAutoMetric(metric) { - if !sw.Config.HonorLabels && len(r.Tags) == 0 { - bb := bbPool.Get() - bb.B = append(bb.B, "exported_"...) - bb.B = append(bb.B, metric...) - metric = bytesutil.InternBytes(bb.B) - bbPool.Put(bb) - } + + // Add `exported_` prefix to metrics, which clash with the automatically generated + // metric names only if the following conditions are met: + // + // - The `honor_labels` option isn't set to true in the scrape_config. + // If `honor_labels: true`, then the scraped metric name must remain unchanged + // because the user explicitly asked about it in the config. + // - The metric has no labels (tags). If it has labels, then the metric value + // will be written into a separate time series comparing to automatically generated time series. + // + // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3557 + // and https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3406 + if needRelabel && !sw.Config.HonorLabels && len(r.Tags) == 0 && isAutoMetric(metric) { + bb := bbPool.Get() + bb.B = append(bb.B, "exported_"...) + bb.B = append(bb.B, metric...) + metric = bytesutil.InternBytes(bb.B) + bbPool.Put(bb) } labelsLen := len(wc.labels) targetLabels := sw.Config.Labels.GetLabels()