textparse: Add gauge histogram support to protobuf parsing
With this commit, the parser stops to see a gauge histogram (whether native or conventional) as an unexpected metric type. It ingests it normally, it even sets the `GaugeHistogram` type in the metadata (as it has already done for a conventional gauge histogram scraped using OpenMetrics), but it otherwise treats it as a normal counter-like histogram. Once #11783 is merged, though, it should be very easy to utilize the type information. Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
parent
e9d9bb1b08
commit
b5d4a94e9d
|
@ -105,7 +105,7 @@ func (p *ProtobufParser) Series() ([]byte, *int64, float64) {
|
||||||
default:
|
default:
|
||||||
v = s.GetQuantile()[p.fieldPos].GetValue()
|
v = s.GetQuantile()[p.fieldPos].GetValue()
|
||||||
}
|
}
|
||||||
case dto.MetricType_HISTOGRAM:
|
case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM:
|
||||||
// This should only happen for a legacy histogram.
|
// This should only happen for a legacy histogram.
|
||||||
h := m.GetHistogram()
|
h := m.GetHistogram()
|
||||||
switch p.fieldPos {
|
switch p.fieldPos {
|
||||||
|
@ -225,6 +225,8 @@ func (p *ProtobufParser) Type() ([]byte, MetricType) {
|
||||||
return n, MetricTypeGauge
|
return n, MetricTypeGauge
|
||||||
case dto.MetricType_HISTOGRAM:
|
case dto.MetricType_HISTOGRAM:
|
||||||
return n, MetricTypeHistogram
|
return n, MetricTypeHistogram
|
||||||
|
case dto.MetricType_GAUGE_HISTOGRAM:
|
||||||
|
return n, MetricTypeGaugeHistogram
|
||||||
case dto.MetricType_SUMMARY:
|
case dto.MetricType_SUMMARY:
|
||||||
return n, MetricTypeSummary
|
return n, MetricTypeSummary
|
||||||
}
|
}
|
||||||
|
@ -273,7 +275,7 @@ func (p *ProtobufParser) Exemplar(ex *exemplar.Exemplar) bool {
|
||||||
switch p.mf.GetType() {
|
switch p.mf.GetType() {
|
||||||
case dto.MetricType_COUNTER:
|
case dto.MetricType_COUNTER:
|
||||||
exProto = m.GetCounter().GetExemplar()
|
exProto = m.GetCounter().GetExemplar()
|
||||||
case dto.MetricType_HISTOGRAM:
|
case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM:
|
||||||
bb := m.GetHistogram().GetBucket()
|
bb := m.GetHistogram().GetBucket()
|
||||||
if p.fieldPos < 0 {
|
if p.fieldPos < 0 {
|
||||||
if p.state == EntrySeries {
|
if p.state == EntrySeries {
|
||||||
|
@ -343,6 +345,7 @@ func (p *ProtobufParser) Next() (Entry, error) {
|
||||||
case dto.MetricType_COUNTER,
|
case dto.MetricType_COUNTER,
|
||||||
dto.MetricType_GAUGE,
|
dto.MetricType_GAUGE,
|
||||||
dto.MetricType_HISTOGRAM,
|
dto.MetricType_HISTOGRAM,
|
||||||
|
dto.MetricType_GAUGE_HISTOGRAM,
|
||||||
dto.MetricType_SUMMARY,
|
dto.MetricType_SUMMARY,
|
||||||
dto.MetricType_UNTYPED:
|
dto.MetricType_UNTYPED:
|
||||||
// All good.
|
// All good.
|
||||||
|
@ -356,7 +359,8 @@ func (p *ProtobufParser) Next() (Entry, error) {
|
||||||
case EntryHelp:
|
case EntryHelp:
|
||||||
p.state = EntryType
|
p.state = EntryType
|
||||||
case EntryType:
|
case EntryType:
|
||||||
if p.mf.GetType() == dto.MetricType_HISTOGRAM &&
|
t := p.mf.GetType()
|
||||||
|
if (t == dto.MetricType_HISTOGRAM || t == dto.MetricType_GAUGE_HISTOGRAM) &&
|
||||||
isNativeHistogram(p.mf.GetMetric()[0].GetHistogram()) {
|
isNativeHistogram(p.mf.GetMetric()[0].GetHistogram()) {
|
||||||
p.state = EntryHistogram
|
p.state = EntryHistogram
|
||||||
} else {
|
} else {
|
||||||
|
@ -366,8 +370,11 @@ func (p *ProtobufParser) Next() (Entry, error) {
|
||||||
return EntryInvalid, err
|
return EntryInvalid, err
|
||||||
}
|
}
|
||||||
case EntryHistogram, EntrySeries:
|
case EntryHistogram, EntrySeries:
|
||||||
|
t := p.mf.GetType()
|
||||||
if p.state == EntrySeries && !p.fieldsDone &&
|
if p.state == EntrySeries && !p.fieldsDone &&
|
||||||
(p.mf.GetType() == dto.MetricType_SUMMARY || p.mf.GetType() == dto.MetricType_HISTOGRAM) {
|
(t == dto.MetricType_SUMMARY ||
|
||||||
|
t == dto.MetricType_HISTOGRAM ||
|
||||||
|
t == dto.MetricType_GAUGE_HISTOGRAM) {
|
||||||
p.fieldPos++
|
p.fieldPos++
|
||||||
} else {
|
} else {
|
||||||
p.metricPos++
|
p.metricPos++
|
||||||
|
@ -428,7 +435,7 @@ func (p *ProtobufParser) getMagicName() string {
|
||||||
if p.fieldPos == -1 {
|
if p.fieldPos == -1 {
|
||||||
return p.mf.GetName() + "_sum"
|
return p.mf.GetName() + "_sum"
|
||||||
}
|
}
|
||||||
if t == dto.MetricType_HISTOGRAM {
|
if t == dto.MetricType_HISTOGRAM || t == dto.MetricType_GAUGE_HISTOGRAM {
|
||||||
return p.mf.GetName() + "_bucket"
|
return p.mf.GetName() + "_bucket"
|
||||||
}
|
}
|
||||||
return p.mf.GetName()
|
return p.mf.GetName()
|
||||||
|
@ -446,7 +453,7 @@ func (p *ProtobufParser) getMagicLabel() (bool, string, string) {
|
||||||
q := qq[p.fieldPos]
|
q := qq[p.fieldPos]
|
||||||
p.fieldsDone = p.fieldPos == len(qq)-1
|
p.fieldsDone = p.fieldPos == len(qq)-1
|
||||||
return true, model.QuantileLabel, formatOpenMetricsFloat(q.GetQuantile())
|
return true, model.QuantileLabel, formatOpenMetricsFloat(q.GetQuantile())
|
||||||
case dto.MetricType_HISTOGRAM:
|
case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM:
|
||||||
bb := p.mf.GetMetric()[p.metricPos].GetHistogram().GetBucket()
|
bb := p.mf.GetMetric()[p.metricPos].GetHistogram().GetBucket()
|
||||||
if p.fieldPos >= len(bb) {
|
if p.fieldPos >= len(bb) {
|
||||||
p.fieldsDone = true
|
p.fieldsDone = true
|
||||||
|
|
Loading…
Reference in New Issue