-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Fix labels memory corruption when using protobuf encoding #16946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix labels memory corruption when using protobuf encoding #16946
Conversation
d5659d0
to
36f05e4
Compare
Signed-off-by: Piotr <17101802+thampiotr@users.noreply.github.com>
9bc4fbf
to
6c5ef02
Compare
Nice catch! Your intuition makes sense, thanks! Which one is the CHOSEN/better one in general If the stringlabels then simply copy for slicelabels here (only for that tag) would be preferable. |
Prometheus has built with "stringlabels" since v2.44 more than two years ago; it saves memory and runs faster. Since #16436 (three months ago) the code has used that mode by default. For people using Prometheus code as a library, it depends how what kind of label strings they have. If the average name/value length is more than 15 bytes, and they don't have a lot of copies of the same string, then (There is also
That is what the |
Signed-off-by: Piotr <17101802+thampiotr@users.noreply.github.com>
6c5ef02
to
be46837
Compare
I like this approach as it allows the implementation of Just added the last comment that @bboreham recommended and so it's ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, let's go, thanks!!!
TIL UnsafeAddBytes, like the approach @bboreham 👍🏽
@@ -40,7 +40,7 @@ jobs: | |||
- uses: prometheus/promci@443c7fc2397e946bc9f5029e313a9c3441b9b86d # v0.4.7 | |||
- uses: ./.github/promci/actions/setup_environment | |||
- run: go test --tags=dedupelabels ./... | |||
- run: go test --tags=slicelabels -race ./cmd/prometheus | |||
- run: go test --tags=slicelabels -race ./cmd/prometheus ./prompb/io/prometheus/client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we don't do ./... here, not sure.. but I guess let's keep it this way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember. Seems reasonable to swap with dedupelabels
which I don't know anyone is using.
The issue:
Proposed fix: Use
UnsafeAddBytes
in builder to handle the unsafe string correctly in each labels builder implementation.NOTE: Since bb76966 the stringlabels are default. This issue affects only
slicelabels
. Added the test to GH package.To reproduce locally, run with
slicelabels
tag: