Avoid creating string for suffix, consider counters without _total suffix
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
This commit is contained in:
parent
9a664b515a
commit
8f07f9dd90
|
@ -425,11 +425,11 @@ func (p *ProtobufParser) Next() (Entry, error) {
|
||||||
}
|
}
|
||||||
unit := p.mf.GetUnit()
|
unit := p.mf.GetUnit()
|
||||||
if len(unit) > 0 {
|
if len(unit) > 0 {
|
||||||
sfx := fmt.Sprintf("_%s", unit)
|
if p.mf.GetType() == dto.MetricType_COUNTER && strings.HasSuffix(name, "_total") {
|
||||||
if p.mf.GetType() == dto.MetricType_COUNTER {
|
if !strings.HasSuffix(name[:len(name)-6], unit) || len(name)-6 < len(unit)+1 || name[len(name)-6-len(unit)-1] != '_' {
|
||||||
sfx = fmt.Sprintf("_%s_total", unit)
|
return EntryInvalid, fmt.Errorf("unit %q not a suffix of counter %q", unit, name)
|
||||||
}
|
}
|
||||||
if !strings.HasSuffix(name, sfx) {
|
} 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)
|
return EntryInvalid, fmt.Errorf("unit %q not a suffix of metric %q", unit, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue