fix(serializers.prometheus): Use legacy validation for metric name (#16557)
This commit is contained in:
parent
3b83f6adc8
commit
0551f22bd3
|
|
@ -88,7 +88,7 @@ func sanitize(name string, table Table) (string, bool) {
|
||||||
// not, it attempts to replaces invalid runes with an underscore to create a
|
// not, it attempts to replaces invalid runes with an underscore to create a
|
||||||
// valid name.
|
// valid name.
|
||||||
func SanitizeMetricName(name string) (string, bool) {
|
func SanitizeMetricName(name string) (string, bool) {
|
||||||
if model.IsValidMetricName(model.LabelValue(name)) {
|
if model.IsValidLegacyMetricName(name) {
|
||||||
return name, true
|
return name, true
|
||||||
}
|
}
|
||||||
return sanitize(name, MetricNameTable)
|
return sanitize(name, MetricNameTable)
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,10 @@ func (s *Serializer) SerializeBatch(metrics []telegraf.Metric) ([]byte, error) {
|
||||||
var metrickey MetricKey
|
var metrickey MetricKey
|
||||||
var promts prompb.TimeSeries
|
var promts prompb.TimeSeries
|
||||||
for _, field := range metric.FieldList() {
|
for _, field := range metric.FieldList() {
|
||||||
metricName := prometheus.MetricName(metric.Name(), field.Key, metric.Type())
|
rawName := prometheus.MetricName(metric.Name(), field.Key, metric.Type())
|
||||||
metricName, ok := prometheus.SanitizeMetricName(metricName)
|
metricName, ok := prometheus.SanitizeMetricName(rawName)
|
||||||
if !ok {
|
if !ok {
|
||||||
traceAndKeepErr("failed to parse metric name %q", metricName)
|
traceAndKeepErr("failed to parse metric name %q", rawName)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -220,7 +220,7 @@ func TestRemoteWriteSerializeNegative(t *testing.T) {
|
||||||
|
|
||||||
m := testutil.MustMetric("@@!!", nil, map[string]interface{}{"!!": "@@"}, time.Unix(0, 0))
|
m := testutil.MustMetric("@@!!", nil, map[string]interface{}{"!!": "@@"}, time.Unix(0, 0))
|
||||||
_, err := s.Serialize(m)
|
_, err := s.Serialize(m)
|
||||||
assert("failed to parse \"@@!!_!!\"", err)
|
assert("failed to parse metric name \"@@!!_!!\"", err)
|
||||||
|
|
||||||
m = testutil.MustMetric("prometheus", nil,
|
m = testutil.MustMetric("prometheus", nil,
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue