Skip to content

expfmt: preserve the full range of sample timestamps - #1036

Open
ViktorBystrov72 wants to merge 1 commit into
prometheus:mainfrom
ViktorBystrov72:fix/extracted-sample-timestamps
Open

ViktorBystrov72 wants to merge 1 commit into
prometheus:mainfrom
ViktorBystrov72:fix/extracted-sample-timestamps

Conversation

@ViktorBystrov72

Copy link
Copy Markdown

ExtractSamples converts each explicit protobuf millisecond timestamp to nanoseconds before converting it to model.Time. The multiplication overflows outside the nanosecond range: 9223372036855 milliseconds becomes -9223372036854, and math.MaxInt64 becomes -1.

Both representations already use int64 milliseconds, so copy the timestamp directly for counters, gauges, untyped metrics, summaries, and both histogram types. Regression cases cover the overflow boundaries, int64 extremes, ordinary and negative timestamps, and the default timestamp when none is supplied. They fail on the parent commit and pass with this change.

Validation: root go test ./..., go test -race ./expfmt -count=1, make lint, license checks, module-tidy checks, and git diff --check passed with Go 1.27.3 and golangci-lint 2.14.0.

@roidelapluie @gotjosh

@ViktorBystrov72
ViktorBystrov72 force-pushed the fix/extracted-sample-timestamps branch 3 times, most recently from 2b719ad to a0df2a7 Compare November 13, 2026 08:39
Signed-off-by: Виктор Быстров <anatema@bk.ru>
@ViktorBystrov72
ViktorBystrov72 force-pushed the fix/extracted-sample-timestamps branch from a0df2a7 to ea43b11 Compare November 14, 2026 05:45

@ismailtrm ismailtrm left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I checked this against main (0675c9e).

  • The overflow values in the description are right: 9223372036855 becomes -9223372036854 and math.MaxInt64 becomes -1. On the negative side math.MinInt64/1000000 - 1 flips sign to 9223372036854, which the new test also covers.
  • For |ms| <= math.MaxInt64/1000000 the old TimeFromUnixNano(ms * 1000000) returns ms exactly, so the change only differs where the old code wrapped. Ordinary timestamps keep their value.
  • These five lines are the only millisecond to nanosecond round trip I found in expfmt and model (git grep TimestampMs).
  • I ran the new test on main with this PR's decode.go reverted: the four out-of-range timestamps fail for every metric type (24 of the 48 subtests). On ea43b11, go test -race ./expfmt/ passes.

Nit, optional: the nil case runs as subtest 42, because it is named after the default timestamp. A name like default would make a failure easier to read.

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