diff options
author | Ilya Mashchenko <ilya@netdata.cloud> | 2024-05-01 14:14:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-01 14:14:29 +0300 |
commit | 23a55c3bca42585e35df33d8d6150f9b70b954b8 (patch) | |
tree | 3383b5d7c22a277e710acea9f2140ecc38c142a7 | |
parent | 92c9fff172d5a4d78a9168a6792302b80dc7aaef (diff) |
go.d prometheus remove apostrophe in label values (#17570)
-rw-r--r-- | src/go/collectors/go.d.plugin/modules/prometheus/charts.go | 20 | ||||
-rw-r--r-- | src/go/collectors/go.d.plugin/modules/prometheus/collect.go | 8 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/prometheus/charts.go b/src/go/collectors/go.d.plugin/modules/prometheus/charts.go index 72d93020e2..f0e7226bb1 100644 --- a/src/go/collectors/go.d.plugin/modules/prometheus/charts.go +++ b/src/go/collectors/go.d.plugin/modules/prometheus/charts.go @@ -40,7 +40,10 @@ func (p *Prometheus) addGaugeChart(id, name, help string, labels labels.Labels) for _, lbl := range labels { chart.Labels = append(chart.Labels, - module.Label{Key: lbl.Name, Value: lbl.Value}, + module.Label{ + Key: lbl.Name, + Value: apostropheReplacer.Replace(lbl.Value), + }, ) } @@ -80,7 +83,10 @@ func (p *Prometheus) addCounterChart(id, name, help string, labels labels.Labels } for _, lbl := range labels { chart.Labels = append(chart.Labels, - module.Label{Key: lbl.Name, Value: lbl.Value}, + module.Label{ + Key: lbl.Name, + Value: apostropheReplacer.Replace(lbl.Value), + }, ) } @@ -147,7 +153,10 @@ func (p *Prometheus) addSummaryCharts(id, name, help string, labels labels.Label for _, chart := range charts { for _, lbl := range labels { - chart.Labels = append(chart.Labels, module.Label{Key: lbl.Name, Value: lbl.Value}) + chart.Labels = append(chart.Labels, module.Label{ + Key: lbl.Name, + Value: apostropheReplacer.Replace(lbl.Value), + }) } if err := p.Charts().Add(chart); err != nil { p.Warning(err) @@ -212,7 +221,10 @@ func (p *Prometheus) addHistogramCharts(id, name, help string, labels labels.Lab for _, chart := range charts { for _, lbl := range labels { - chart.Labels = append(chart.Labels, module.Label{Key: lbl.Name, Value: lbl.Value}) + chart.Labels = append(chart.Labels, module.Label{ + Key: lbl.Name, + Value: apostropheReplacer.Replace(lbl.Value), + }) } if err := p.Charts().Add(chart); err != nil { p.Warning(err) diff --git a/src/go/collectors/go.d.plugin/modules/prometheus/collect.go b/src/go/collectors/go.d.plugin/modules/prometheus/collect.go index 7fa9044045..a6df302fac 100644 --- a/src/go/collectors/go.d.plugin/modules/prometheus/collect.go +++ b/src/go/collectors/go.d.plugin/modules/prometheus/collect.go @@ -209,6 +209,9 @@ func (p *Prometheus) joinLabels(labels labels.Labels) string { val = backslashReplacer.Replace(val) } } + if strings.IndexByte(val, '\'') != -1 { + val = apostropheReplacer.Replace(val) + } sb.WriteString("-" + name + "=" + val) } @@ -247,8 +250,9 @@ func decodeLabelValue(value string) string { } var ( - spaceReplacer = strings.NewReplacer(" ", "_") - backslashReplacer = strings.NewReplacer(`\`, "_") + spaceReplacer = strings.NewReplacer(" ", "_") + backslashReplacer = strings.NewReplacer(`\`, "_") + apostropheReplacer = strings.NewReplacer("'", "") ) func hasPrefix(mf map[string]*prometheus.MetricFamily, prefix string) bool { |