mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-13 23:10:12 -08:00
textparse: Handle unknown metric types in protobuf gracefully
So far, the parser hasn't validated that the type is valid in the `Next()` call. Later, in the `Series()` call, however, it assumes that we will only see valid types and therefore panics with `encountered unexpected metric type, this is a bug`. This commit fixes said bug by adding validation to the `Next()` call. Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
parent
fa0f04bbc6
commit
e9d9bb1b08
|
@ -331,7 +331,7 @@ func (p *ProtobufParser) Next() (Entry, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are at the beginning of a metric family. Put only the name
|
// We are at the beginning of a metric family. Put only the name
|
||||||
// into metricBytes and validate only name and help for now.
|
// into metricBytes and validate only name, help, and type for now.
|
||||||
name := p.mf.GetName()
|
name := p.mf.GetName()
|
||||||
if !model.IsValidMetricName(model.LabelValue(name)) {
|
if !model.IsValidMetricName(model.LabelValue(name)) {
|
||||||
return EntryInvalid, errors.Errorf("invalid metric name: %s", name)
|
return EntryInvalid, errors.Errorf("invalid metric name: %s", name)
|
||||||
|
@ -339,6 +339,16 @@ func (p *ProtobufParser) Next() (Entry, error) {
|
||||||
if help := p.mf.GetHelp(); !utf8.ValidString(help) {
|
if help := p.mf.GetHelp(); !utf8.ValidString(help) {
|
||||||
return EntryInvalid, errors.Errorf("invalid help for metric %q: %s", name, help)
|
return EntryInvalid, errors.Errorf("invalid help for metric %q: %s", name, help)
|
||||||
}
|
}
|
||||||
|
switch p.mf.GetType() {
|
||||||
|
case dto.MetricType_COUNTER,
|
||||||
|
dto.MetricType_GAUGE,
|
||||||
|
dto.MetricType_HISTOGRAM,
|
||||||
|
dto.MetricType_SUMMARY,
|
||||||
|
dto.MetricType_UNTYPED:
|
||||||
|
// All good.
|
||||||
|
default:
|
||||||
|
return EntryInvalid, errors.Errorf("unknown metric type for metric %q: %s", name, p.mf.GetType())
|
||||||
|
}
|
||||||
p.metricBytes.Reset()
|
p.metricBytes.Reset()
|
||||||
p.metricBytes.WriteString(name)
|
p.metricBytes.WriteString(name)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue