Repository navigation
test(writer): pin label fingerprint values (M2 1/4, #991) - #1060
Merged
Merged
Conversation
The label fingerprint is the join key between time_series and the samples tables and is persisted in every deployment. Nothing tested it, so a change to any of the hash implementations would silently detach new writes from historical series. Pin the exact output of each implementation, with values taken from the current code: - unmarshal.fingerprintLabels in both CityHash and Bernstein modes, plus its order independence (callers do not sort labels) and that moving characters between a label name and its value changes the series - utils.FingerprintLabels (FNV variant) - both copies of FingerprintLabelsDJBHashPrometheus (writer and ctrl), which key the same rows of the settings table and must agree
Guess-Who-sec
marked this pull request as draft
October 29, 2026 23:06
This was referenced Oct 30, 2026
Guess-Who-sec
marked this pull request as ready for review
October 30, 2026 16:51
rita7lopes
approved these changes
Nov 9, 2026
rita7lopes
left a comment
Contributor
There was a problem hiding this comment.
Thanks @Guess-Who-sec, this is a solid first piece of M2.
The fingerprint is stored permanently and is what links time_series to the samples tables. Until now, a change to any of these hashes would have passed CI and quietly cut new writes off from historical series, so these pins close a real gap. I traced each one back to its callers:
- fingerprintLabels is the hash every ingest path uses (via builder.go), and it's good to have both modes pinned.
- The label-order test matters most. builder.go hashes the filtered labels unsorted, so order independence relies entirely on the sum/xor/product combination. This test makes that guarantee explicit.
- Holding both DJB copies to the same values is right, since writer/chwrapper and ctrl/qryn/maintenance/rotate.go key the same settings rows.
The mutation table in the description makes this easy to trust. Thanks for doing that.
On your follow-ups:
- HashType: "bernstein": please open an issue on cloki-config. Any fix has to keep existing deployments on the hash they already use, so it's a config-compatibility decision first and a code fix second.
- DJB copies: agreed. The pins cover it for now.
- utils.FingerprintLabels: it has no callers, so it can go in a separate cleanup PR along with its pin.
- Unmarshal tests running in Bernstein mode: worth fixing. A follow-up that sets the mode explicitly in those tests (or defaults them to CityHash) would bring them in line with real deployments.
Approving. Over to #1061.
rita7lopes
pushed a commit
that referenced
this pull request
Nov 24, 2026
rita7lopes
pushed a commit
that referenced
this pull request
Nov 24, 2026
…1084) The writer tests that install a minimal global config left FingerPrintType at its zero value, which is Bernstein, while a real deployment defaults to CityHash. Set CityHash explicitly in those helpers (writer/controller, writer/grpc, writer/utils/unmarshal), so the tests hash the way production does. Follow-up from #1060.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of M2 (#920), PR 1 of 4. Closes #991. Epic: #917.
M2 is split into four PRs:
What
Value pins for every label-fingerprint implementation. Tests only: no production code changes.
writer/utils/unmarshal/fingerprint_test.gofingerprintLabels(used on every ingest path viabuilder.go) in both modes, CityHash and Bernstein. Also two behaviour checks: the result does not depend on label order (callers do not sort labels before hashing), and{ab="c"}and{a="bc"}get different fingerprintswriter/utils/fingerprint_test.goFingerprintLabels(FNV variant)writer/utils/helputils/fingerprint_test.goFingerprintLabelsDJBHashPrometheus(writer copy)ctrl/qryn/helputils/hash_test.goFingerprintLabelsDJBHashPrometheus(ctrl copy), pinned to the same values as the writer copyInputs: two labels, no labels, an empty value, a non-ASCII value (
→) and three labels. For DJB:nil, empty, single byte, a label pair, non-ASCII and a high byte.The expected values were generated once from the current implementations, since they are the contract. Each test says that a failure means data compatibility is broken, not that the expected values need updating.
Why
The fingerprint joins
time_seriesto the samples tables and is persisted in every deployment. If its value changed for a given label set, new writes would stop matching stored series and queries would silently return less data. Nothing in CI would catch it. This should land before #972, so each step of the table refactor can show it does not change fingerprints.How I checked the tests catch real changes
There is no bug to reproduce, so I mutated each implementation in a scratch copy and confirmed the matching test fails:
TestFingerprintLabelsIsStable(utils)fingerprintLabelsproduct constant +1TestFingerprintLabelsIsStable(both modes)fingerprintLabelssum made order-dependentTestFingerprintLabelsIgnoresLabelOrderfingerprintLabelshashing name+value as one stringTestFingerprintLabelsSeparatesNameAndValueTestFingerprintLabelsDJBHashPrometheusIsStable(writer)TestFingerprintLabelsDJBHashPrometheusIsStable(ctrl)Also ran:
gofmt -l .(clean),CGO_ENABLED=0 go build,go vet ./...(same output asmaster, nothing from the new files),go test ./..., andgo test -raceon the four touched packages.Findings worth a follow-up (not changed here)
HashType: "bernstein"silently keeps CityHash. Inmetrico/cloki-config(setFastConfigSettings),case "bernstein":is empty, and Go does not fall through, so only"default"selects Bernstein. The struct default isFingerPrintType: 1(CityHash).writer/chwrapper(GetSetting/PutSetting) andctrl/qryn/maintenance/rotate.gokey the samesettingsrows with the same string, so the pins hold both copies to the same values.FingerprintLabelsis not standard FNV-1a. It multiplies by the FNV offset basis instead of the FNV prime. It has no callers today. Is it still needed?ClokiBaseSettingServer, whereFingerPrintTypeis0= Bernstein, while real deployments default to CityHash. The new tests set the mode explicitly.