Skip to content

test(writer): hash with CityHash in writer tests, as deployments do - #1084

Merged
rita7lopes merged 1 commit into
metrico:masterfrom
Guess-Who-sec:test/writer-tests-cityhash-mode
Nov 24, 2026
Merged

rita7lopes merged 1 commit into
metrico:masterfrom
Guess-Who-sec:test/writer-tests-cityhash-mode

Conversation

@Guess-Who-sec

Copy link
Copy Markdown
Contributor

Follow-up 4 from #1060. No dependencies: branches from master.

Why

Writer tests that install a minimal global config leave FingerPrintType at its zero value, 0, which is Bernstein. A real deployment defaults to CityHash (FingerPrintType default 1). So these tests hashed every series with an algorithm production doesn't use by default.

What

Test files only. The helpers that install the config now select CityHash:

File Change
writer/utils/unmarshal/otlp_metrics_test.go collectMetrics calls useFingerprintType(t, clcwriter.FINGERPRINT_CityHash) (the helper #1060 added in the same package)
writer/utils/unmarshal/otlplogs_grpc_test.go same, in TestOTLPLogsFromData_EmitsSamples
writer/controller/ingest_test.go installConfig sets setting.FingerPrintType = clcwriter.FINGERPRINT_CityHash
writer/grpc/integration_test.go same in its installConfig

No assertion changes. None of these tests compare against fixed fingerprint values.

Verification

  • Which mode the tests hash with, measured with a temporary print in fingerprintLabels (not committed), excluding test(writer): pin label fingerprint values (M2 1/4, #991) #1060's own tests, which cover both modes on purpose:

    Package master this branch
    writer/controller 7 Bernstein 7 CityHash
    writer/grpc 2 Bernstein 2 CityHash
    writer/utils/unmarshal 115 Bernstein 115 CityHash
  • The tests now cover the default hash. With a bug planted in the CityHash branch of fingerprintLabels (every fingerprint 0), the tests above all pass on master and fail on this branch (8 TestOTLPMetrics_* tests and more). Not committed.

  • go test ./...: 36 packages pass; go test -race on the three packages passes; the affected tests pass 5 runs in a row

  • go vet ./... same as master; gofmt clean; build OK

Potential risks

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 metrico#1060.
@rita7lopes
rita7lopes merged commit 8e7cdaf into metrico:master Nov 24, 2026
10 checks passed
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