mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-10 21:11:20 +00:00
Strip labels when writing metric metadata (#8149)
This is a fix for ```cache_total{target="acc_read"} counter it's invalid syntax of metric type. prometheus parsing error``` which does not remove the whole metadata tag
This commit is contained in:
parent
22bd173ab3
commit
077266606c
@ -20,6 +20,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/VictoriaMetrics/metrics"
|
||||
)
|
||||
@ -84,15 +85,23 @@ func (c *collector) addTimer(name string, m *metrics.Summary) {
|
||||
}
|
||||
|
||||
func (c *collector) writeGauge(name string, value interface{}) {
|
||||
//c.buff.WriteString(fmt.Sprintf(typeGaugeTpl, name))
|
||||
c.buff.WriteString(fmt.Sprintf(typeGaugeTpl, stripLabels(name)))
|
||||
c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value))
|
||||
}
|
||||
|
||||
func (c *collector) writeCounter(name string, value interface{}) {
|
||||
//c.buff.WriteString(fmt.Sprintf(typeCounterTpl, name))
|
||||
c.buff.WriteString(fmt.Sprintf(typeCounterTpl, stripLabels(name)))
|
||||
c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value))
|
||||
}
|
||||
|
||||
func stripLabels(name string) string {
|
||||
if labelsIndex := strings.IndexByte(name, '{'); labelsIndex >= 0 {
|
||||
return name[0:labelsIndex]
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
func (c *collector) writeSummaryCounter(name string, value interface{}) {
|
||||
name = name + "_count"
|
||||
c.buff.WriteString(fmt.Sprintf(keyCounterTpl, name, value))
|
||||
|
Loading…
Reference in New Issue
Block a user