Fix Prometheus query timestamp formatting - #2397
Open
Pybsama wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Prometheus range-query timestamp serialization so start/end are always sent as plain decimal seconds (not scientific notation), improving compatibility with stricter Prometheus-compatible backends (e.g., VictoriaMetrics).
Changes:
- Serialize
startandendfrom epoch milliseconds usingBigDecimal.toPlainString()to avoid exponent formatting. - Add a regression test that captures and parses the actual URL-encoded POST body to assert timestamp formatting.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cruise-control/src/main/java/com/linkedin/kafka/cruisecontrol/monitor/sampling/prometheus/PrometheusAdapter.java | Replaces double-based timestamp stringification with BigDecimal plain-decimal serialization for start/end. |
| cruise-control/src/test/java/com/linkedin/kafka/cruisecontrol/monitor/sampling/prometheus/PrometheusAdapterTest.java | Adds a regression test that inspects the real form body to ensure start/end are not in scientific notation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Pybsama
force-pushed
the
codex/plain-prometheus-query-timestamps
branch
from
August 28, 2026 20:38
a495a4a to
a5efc47
Compare
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.
Summary
PrometheusAdapterserializes Unix timestamps throughDouble.toString(), which emits scientific notation for current epoch values. Scientific notation is outside the documented Prometheus range-query timestamp format and is rejected by stricter compatible backends such as VictoriaMetrics.startandenddirectly from epoch milliseconds withBigDecimal.toPlainString(), and add a regression test that inspects the real URL-encoded POST body.Expected Behavior
PrometheusMetricSamplersends exact plain-decimal Unix timestamps, such as1784144612.388, so Prometheus-compatible range-query backends can parse them.Actual Behavior
The previous implementation sent values such as
1.784144612388E9.VictoriaMetrics rejects that value with HTTP 422, so sampling fails and no monitored
windows are populated.
Steps to Reproduce
prometheus.server.endpointto use a VictoriaMetrics endpoint.PrometheusMetricSampler./api/v1/query_rangereceive an exponent-formstart/endvalue andreturn HTTP 422.
The added regression test reproduces the serialization issue without requiring an
external Prometheus-compatible service.
Known Workarounds
Use a backend that leniently accepts exponent-form timestamps. There is no Cruise
Control configuration that changes the previous timestamp serialization.
Additional evidence
expected
1784144612.388, but received1.784144612388E9.a clean run from a fresh clone of the public branch.
JaCoCo report generation successfully.
Categorization
This PR resolves #2389.