mirror of https://github.com/prometheus/prometheus
perf(nhcbparse): unroll recursion (#15776)
https://github.com/prometheus/prometheus/pull/15467#issuecomment-2563585979 Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>pull/15467/head
parent
1e420ef373
commit
cfcb00a716
|
@ -177,61 +177,63 @@ func (p *NHCBParser) CreatedTimestamp() *int64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NHCBParser) Next() (Entry, error) {
|
func (p *NHCBParser) Next() (Entry, error) {
|
||||||
if p.state == stateEmitting {
|
for {
|
||||||
p.state = stateStart
|
if p.state == stateEmitting {
|
||||||
if p.entry == EntrySeries {
|
p.state = stateStart
|
||||||
isNHCB := p.handleClassicHistogramSeries(p.lset)
|
if p.entry == EntrySeries {
|
||||||
if isNHCB && !p.keepClassicHistograms {
|
isNHCB := p.handleClassicHistogramSeries(p.lset)
|
||||||
// Do not return the classic histogram series if it was converted to NHCB and we are not keeping classic histograms.
|
if isNHCB && !p.keepClassicHistograms {
|
||||||
return p.Next()
|
// Do not return the classic histogram series if it was converted to NHCB and we are not keeping classic histograms.
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return p.entry, p.err
|
||||||
}
|
}
|
||||||
return p.entry, p.err
|
|
||||||
}
|
|
||||||
|
|
||||||
p.entry, p.err = p.parser.Next()
|
p.entry, p.err = p.parser.Next()
|
||||||
if p.err != nil {
|
if p.err != nil {
|
||||||
if errors.Is(p.err, io.EOF) && p.processNHCB() {
|
if errors.Is(p.err, io.EOF) && p.processNHCB() {
|
||||||
return EntryHistogram, nil
|
|
||||||
}
|
|
||||||
return EntryInvalid, p.err
|
|
||||||
}
|
|
||||||
switch p.entry {
|
|
||||||
case EntrySeries:
|
|
||||||
p.bytes, p.ts, p.value = p.parser.Series()
|
|
||||||
p.metricString = p.parser.Metric(&p.lset)
|
|
||||||
// Check the label set to see if we can continue or need to emit the NHCB.
|
|
||||||
var isNHCB bool
|
|
||||||
if p.compareLabels() {
|
|
||||||
// Labels differ. Check if we can emit the NHCB.
|
|
||||||
if p.processNHCB() {
|
|
||||||
return EntryHistogram, nil
|
return EntryHistogram, nil
|
||||||
}
|
}
|
||||||
isNHCB = p.handleClassicHistogramSeries(p.lset)
|
return EntryInvalid, p.err
|
||||||
} else {
|
|
||||||
// Labels are the same. Check if after an exponential histogram.
|
|
||||||
if p.lastHistogramExponential {
|
|
||||||
isNHCB = false
|
|
||||||
} else {
|
|
||||||
isNHCB = p.handleClassicHistogramSeries(p.lset)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if isNHCB && !p.keepClassicHistograms {
|
switch p.entry {
|
||||||
// Do not return the classic histogram series if it was converted to NHCB and we are not keeping classic histograms.
|
case EntrySeries:
|
||||||
return p.Next()
|
p.bytes, p.ts, p.value = p.parser.Series()
|
||||||
|
p.metricString = p.parser.Metric(&p.lset)
|
||||||
|
// Check the label set to see if we can continue or need to emit the NHCB.
|
||||||
|
var isNHCB bool
|
||||||
|
if p.compareLabels() {
|
||||||
|
// Labels differ. Check if we can emit the NHCB.
|
||||||
|
if p.processNHCB() {
|
||||||
|
return EntryHistogram, nil
|
||||||
|
}
|
||||||
|
isNHCB = p.handleClassicHistogramSeries(p.lset)
|
||||||
|
} else {
|
||||||
|
// Labels are the same. Check if after an exponential histogram.
|
||||||
|
if p.lastHistogramExponential {
|
||||||
|
isNHCB = false
|
||||||
|
} else {
|
||||||
|
isNHCB = p.handleClassicHistogramSeries(p.lset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isNHCB && !p.keepClassicHistograms {
|
||||||
|
// Do not return the classic histogram series if it was converted to NHCB and we are not keeping classic histograms.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return p.entry, p.err
|
||||||
|
case EntryHistogram:
|
||||||
|
p.bytes, p.ts, p.h, p.fh = p.parser.Histogram()
|
||||||
|
p.metricString = p.parser.Metric(&p.lset)
|
||||||
|
p.storeExponentialLabels()
|
||||||
|
case EntryType:
|
||||||
|
p.bName, p.typ = p.parser.Type()
|
||||||
|
}
|
||||||
|
if p.processNHCB() {
|
||||||
|
return EntryHistogram, nil
|
||||||
}
|
}
|
||||||
return p.entry, p.err
|
return p.entry, p.err
|
||||||
case EntryHistogram:
|
|
||||||
p.bytes, p.ts, p.h, p.fh = p.parser.Histogram()
|
|
||||||
p.metricString = p.parser.Metric(&p.lset)
|
|
||||||
p.storeExponentialLabels()
|
|
||||||
case EntryType:
|
|
||||||
p.bName, p.typ = p.parser.Type()
|
|
||||||
}
|
}
|
||||||
if p.processNHCB() {
|
|
||||||
return EntryHistogram, nil
|
|
||||||
}
|
|
||||||
return p.entry, p.err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if labels have changed and we should emit the NHCB.
|
// Return true if labels have changed and we should emit the NHCB.
|
||||||
|
|
Loading…
Reference in New Issue