model/textparse: Remove unit validation in protobuf parsing (#16834)

Signed-off-by: Gregoire Verdier <gregoire.verdier@gmail.com>
This commit is contained in:
Grégoire 2025-11-19 14:03:32 +01:00 committed by GitHub
parent d943f445f0
commit 1174b0ce4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,7 +19,6 @@ import (
"fmt"
"io"
"math"
"strings"
"unicode/utf8"
"github.com/gogo/protobuf/types"
@ -466,16 +465,6 @@ func (p *ProtobufParser) Next() (Entry, error) {
default:
return EntryInvalid, fmt.Errorf("unknown metric type for metric %q: %s", name, p.dec.GetType())
}
unit := p.dec.GetUnit()
if len(unit) > 0 {
if p.dec.GetType() == dto.MetricType_COUNTER && strings.HasSuffix(name, "_total") {
if !strings.HasSuffix(name[:len(name)-6], unit) || len(name)-6 < len(unit)+1 || name[len(name)-6-len(unit)-1] != '_' {
return EntryInvalid, fmt.Errorf("unit %q not a suffix of counter %q", unit, name)
}
} else if !strings.HasSuffix(name, unit) || len(name) < len(unit)+1 || name[len(name)-len(unit)-1] != '_' {
return EntryInvalid, fmt.Errorf("unit %q not a suffix of metric %q", unit, name)
}
}
p.entryBytes.Reset()
p.entryBytes.WriteString(name)
p.state = EntryHelp