@cryptotaxi247 / netdata-1 / commits / 23a55c3bc

go.d prometheus remove apostrophe in label values (#17570)

Ilya Mashchenko committed May 1, 2024 at 14:14 UTC 23a55c3bca42585e35df33d8d6150f9b70b954b8
2 files changed +22 -6
src/go/collectors/go.d.plugin/modules/prometheus/charts.go
+16 -4
@@ -40,7 +40,10 @@ func (p *Prometheus) addGaugeChart(id, name, help string, labels labels.Labels)
40
41 for _, lbl := range labels {
42 chart.Labels = append(chart.Labels,
43 - module.Label{Key: lbl.Name, Value: lbl.Value},
43 + module.Label{
44 + Key: lbl.Name,
45 + Value: apostropheReplacer.Replace(lbl.Value),
46 + },
47 )
48 }
49
@@ -80,7 +83,10 @@ func (p *Prometheus) addCounterChart(id, name, help string, labels labels.Labels
83 }
84 for _, lbl := range labels {
85 chart.Labels = append(chart.Labels,
83 - module.Label{Key: lbl.Name, Value: lbl.Value},
86 + module.Label{
87 + Key: lbl.Name,
88 + Value: apostropheReplacer.Replace(lbl.Value),
89 + },
90 )
91 }
92
@@ -147,7 +153,10 @@ func (p *Prometheus) addSummaryCharts(id, name, help string, labels labels.Label
153
154 for _, chart := range charts {
155 for _, lbl := range labels {
150 - chart.Labels = append(chart.Labels, module.Label{Key: lbl.Name, Value: lbl.Value})
156 + chart.Labels = append(chart.Labels, module.Label{
157 + Key: lbl.Name,
158 + Value: apostropheReplacer.Replace(lbl.Value),
159 + })
160 }
161 if err := p.Charts().Add(chart); err != nil {
162 p.Warning(err)
@@ -212,7 +221,10 @@ func (p *Prometheus) addHistogramCharts(id, name, help string, labels labels.Lab
221
222 for _, chart := range charts {
223 for _, lbl := range labels {
215 - chart.Labels = append(chart.Labels, module.Label{Key: lbl.Name, Value: lbl.Value})
224 + chart.Labels = append(chart.Labels, module.Label{
225 + Key: lbl.Name,
226 + Value: apostropheReplacer.Replace(lbl.Value),
227 + })
228 }
229 if err := p.Charts().Add(chart); err != nil {
230 p.Warning(err)
src/go/collectors/go.d.plugin/modules/prometheus/collect.go
+6 -2
@@ -209,6 +209,9 @@ func (p *Prometheus) joinLabels(labels labels.Labels) string {
209 val = backslashReplacer.Replace(val)
210 }
211 }
212 + if strings.IndexByte(val, '\'') != -1 {
213 + val = apostropheReplacer.Replace(val)
214 + }
215
216 sb.WriteString("-" + name + "=" + val)
217 }
@@ -247,8 +250,9 @@ func decodeLabelValue(value string) string {
250 }
251
252 var (
250 - spaceReplacer = strings.NewReplacer(" ", "_")
251 - backslashReplacer = strings.NewReplacer(`\`, "_")
253 + spaceReplacer = strings.NewReplacer(" ", "_")
254 + backslashReplacer = strings.NewReplacer(`\`, "_")
255 + apostropheReplacer = strings.NewReplacer("'", "")
256 )
257
258 func hasPrefix(mf map[string]*prometheus.MetricFamily, prefix string) bool {