Skip to content

fix(nhcb): do not return nhcb from parse if exponential is present - #15209

Merged
krajorama merged 1 commit into
mainfrom
nhcb-scrape-impl
Oct 24, 2024
Merged

krajorama merged 1 commit into
mainfrom
nhcb-scrape-impl

Conversation

@krajorama

@krajorama krajorama commented Oct 24, 2024 •

Copy link
Copy Markdown
Member

From: #14978 (comment)
Also encode the requirement table set in #13532

This relies on protobuf parser exposing native histograms before classic series and that text format exposers follow the requirement about ordering: proposals/2024-01-29_native_histograms_text_format.md.

From: #14978 (comment)
Also encode the requirement table set in #13532

Signed-off-by: György Krajcsovits <[email protected]>

@jesusvazquez jesusvazquez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Very clear code to me

{Labels: labels.FromStrings("id", "something-test"), Value: 0.5},
{Labels: labels.FromStrings("id", "something-test"), Value: 8.0},
},
// TODO(krajorama): ct: int64p(1520430001000),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to reviewers: input doesn't have created timestamp, copy paste error to have this comment.

{Labels: labels.FromStrings("id", "something-test"), Value: 0.0, HasTs: true, Ts: 123321},
{Labels: labels.FromStrings("id", "something-test"), Value: 2e100, HasTs: true, Ts: 123000},
},
// TODO(krajorama): ct: int64p(1520430002000),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to reviewers: input doesn't have created timestamp, copy paste error to have this comment.

@krajorama
krajorama merged commit 469573b into main Oct 24, 2024
@krajorama
krajorama deleted the nhcb-scrape-impl branch October 24, 2024 16:14
julienduchesne pushed a commit to julienduchesne/prometheus that referenced this pull request Dec 13, 2024
krajorama pushed a commit that referenced this pull request Jul 28, 2026
NHCBParser.hBuffer was added in #15209 as a scratch buffer for
labels.Labels.HashWithoutLabels, but it is never assigned: all three
call sites discard the returned slice with `_`.

HashWithoutLabels uses the pass-and-return buffer idiom, handing back
the possibly-reallocated slice so the caller can retain the grown
capacity. Because the return value is dropped, p.hBuffer stays nil
forever and every call replays the full append growth cascade
(16->32->64->128) from zero, costing ~4 allocations per call where an
amortised reuse costs none.

differentMetric() runs once per classic-histogram series, so this
scales with histogram cardinality.

hBuffer is pure scratch: it is never returned, stored or aliased, and
its only consumer is xxhash.Sum64. This is deliberately not the buffer
removed in 41c7f7d ("don't reuse the buffer"), which backed p.bytes -
that one *is* handed to callers via Series() and must not be reused.

No behaviour change. Using the existing BenchmarkParseOpenMetricsNHCB
unchanged (-benchtime 1s -count 6 -cpu 2 -benchmem), via benchstat:

                             B/op                      allocs/op
  omtext            22.39Ki -> 22.39Ki  ~         375 -> 375  ~
  omtext_with_nhcb  20.02Ki -> 14.89Ki  -25.61%   353 -> 181  -48.73%

The non-NHCB arm is bit-for-bit unchanged, confirming the fix is
confined to the NHCB path.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Shubh Gupta <[email protected]>
krajorama added a commit that referenced this pull request Jul 28, 2026
NHCBParser.hBuffer was added in #15209 as a scratch buffer for
labels.Labels.HashWithoutLabels, but it is never assigned: all three
call sites discard the returned slice with `_`.

HashWithoutLabels uses the pass-and-return buffer idiom, handing back
the possibly-reallocated slice so the caller can retain the grown
capacity. Because the return value is dropped, p.hBuffer stays nil
forever and every call replays the full append growth cascade
(16->32->64->128) from zero, costing ~4 allocations per call where an
amortised reuse costs none.

differentMetric() runs once per classic-histogram series, so this
scales with histogram cardinality.

hBuffer is pure scratch: it is never returned, stored or aliased, and
its only consumer is xxhash.Sum64. This is deliberately not the buffer
removed in 41c7f7d ("don't reuse the buffer"), which backed p.bytes -
that one *is* handed to callers via Series() and must not be reused.

No behaviour change. Using the existing BenchmarkParseOpenMetricsNHCB
unchanged (-benchtime 1s -count 6 -cpu 2 -benchmem), via benchstat:

                             B/op                      allocs/op
  omtext            22.39Ki -> 22.39Ki  ~         375 -> 375  ~
  omtext_with_nhcb  20.02Ki -> 14.89Ki  -25.61%   353 -> 181  -48.73%

The non-NHCB arm is bit-for-bit unchanged, confirming the fix is
confined to the NHCB path.

Signed-off-by: Shubh Gupta <[email protected]>
Co-authored-by: Shubh Gupta <[email protected]>
Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants