Skip to content

model: replace the sample value type when decoding JSON - #1038

Open
ViktorBystrov72 wants to merge 1 commit into
prometheus:mainfrom
ViktorBystrov72:fix/reused-sample-json
Open

ViktorBystrov72 wants to merge 1 commit into
prometheus:mainfrom
ViktorBystrov72:fix/reused-sample-json

Conversation

@ViktorBystrov72

Copy link
Copy Markdown

Decoding a float sample into a Sample that previously held a histogram leaves the old histogram and timestamp in place. Reusing a Vector triggers the same problem because encoding/json reuses its sample pointers. For example, a histogram at timestamp 1 followed by a float value of 3 at timestamp 2 still marshals as the original histogram.

Select the value type from the incoming JSON fields, and clear the previous representation when it changes. An object without a value field still preserves the existing sample, and null histograms remain invalid. Regression tests cover repeated histogram/float transitions for both an individual sample and a vector; they fail on the parent commit.

Validation: make test GOOPTS=-race passed with Go 1.27.3 and golangci-lint 2.14.0, including all root tests, lint, license, and module-tidy checks. git diff --check passed.

@roidelapluie @gotjosh

@ViktorBystrov72
ViktorBystrov72 force-pushed the fix/reused-sample-json branch 3 times, most recently from 4cdbc93 to 968f4b9 Compare November 13, 2026 08:39
Signed-off-by: Виктор Быстров <anatema@bk.ru>
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.

1 participant