perf(nhcbparse): unroll recursion (#15776)
Some checks failed
CI / Go tests (push) Has been cancelled
CI / More Go tests (push) Has been cancelled
CI / Go tests with previous Go version (push) Has been cancelled
CI / UI tests (push) Has been cancelled
CI / Go tests on Windows (push) Has been cancelled
CI / Mixins tests (push) Has been cancelled
CI / Build Prometheus for common architectures (0) (push) Has been cancelled
CI / Build Prometheus for common architectures (1) (push) Has been cancelled
CI / Build Prometheus for common architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (0) (push) Has been cancelled
CI / Build Prometheus for all architectures (1) (push) Has been cancelled
CI / Build Prometheus for all architectures (10) (push) Has been cancelled
CI / Build Prometheus for all architectures (11) (push) Has been cancelled
CI / Build Prometheus for all architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (3) (push) Has been cancelled
CI / Build Prometheus for all architectures (4) (push) Has been cancelled
CI / Build Prometheus for all architectures (5) (push) Has been cancelled
CI / Build Prometheus for all architectures (6) (push) Has been cancelled
CI / Build Prometheus for all architectures (7) (push) Has been cancelled
CI / Build Prometheus for all architectures (8) (push) Has been cancelled
CI / Build Prometheus for all architectures (9) (push) Has been cancelled
CI / Check generated parser (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
CI / fuzzing (push) Has been cancelled
CI / codeql (push) Has been cancelled
CI / Report status of build Prometheus for all architectures (push) Has been cancelled
CI / Publish main branch artifacts (push) Has been cancelled
CI / Publish release artefacts (push) Has been cancelled
CI / Publish UI on npm Registry (push) Has been cancelled

https://github.com/prometheus/prometheus/pull/15467#issuecomment-2563585979

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
This commit is contained in:
George Krajcsovits 2025-01-02 15:51:52 +01:00 committed by GitHub
parent 1e420ef373
commit cfcb00a716
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -177,13 +177,14 @@ func (p *NHCBParser) CreatedTimestamp() *int64 {
} }
func (p *NHCBParser) Next() (Entry, error) { func (p *NHCBParser) Next() (Entry, error) {
for {
if p.state == stateEmitting { if p.state == stateEmitting {
p.state = stateStart p.state = stateStart
if p.entry == EntrySeries { if p.entry == EntrySeries {
isNHCB := p.handleClassicHistogramSeries(p.lset) isNHCB := p.handleClassicHistogramSeries(p.lset)
if isNHCB && !p.keepClassicHistograms { if isNHCB && !p.keepClassicHistograms {
// Do not return the classic histogram series if it was converted to NHCB and we are not keeping classic histograms. // Do not return the classic histogram series if it was converted to NHCB and we are not keeping classic histograms.
return p.Next() continue
} }
} }
return p.entry, p.err return p.entry, p.err
@ -218,7 +219,7 @@ func (p *NHCBParser) Next() (Entry, error) {
} }
if isNHCB && !p.keepClassicHistograms { if isNHCB && !p.keepClassicHistograms {
// Do not return the classic histogram series if it was converted to NHCB and we are not keeping classic histograms. // Do not return the classic histogram series if it was converted to NHCB and we are not keeping classic histograms.
return p.Next() continue
} }
return p.entry, p.err return p.entry, p.err
case EntryHistogram: case EntryHistogram:
@ -232,6 +233,7 @@ func (p *NHCBParser) Next() (Entry, error) {
return EntryHistogram, nil return EntryHistogram, nil
} }
return p.entry, p.err 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.