mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 06:17:27 -08:00
api: Improve doc comments for v1.MinTime and v1.MaxTime (#14986)
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Build Prometheus for common architectures (0) (push) Waiting to run
CI / Build Prometheus for common architectures (1) (push) Waiting to run
CI / Build Prometheus for common architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (0) (push) Waiting to run
CI / Build Prometheus for all architectures (1) (push) Waiting to run
CI / Build Prometheus for all architectures (10) (push) Waiting to run
CI / Build Prometheus for all architectures (11) (push) Waiting to run
CI / Build Prometheus for all architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (3) (push) Waiting to run
CI / Build Prometheus for all architectures (4) (push) Waiting to run
CI / Build Prometheus for all architectures (5) (push) Waiting to run
CI / Build Prometheus for all architectures (6) (push) Waiting to run
CI / Build Prometheus for all architectures (7) (push) Waiting to run
CI / Build Prometheus for all architectures (8) (push) Waiting to run
CI / Build Prometheus for all architectures (9) (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Build Prometheus for common architectures (0) (push) Waiting to run
CI / Build Prometheus for common architectures (1) (push) Waiting to run
CI / Build Prometheus for common architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (0) (push) Waiting to run
CI / Build Prometheus for all architectures (1) (push) Waiting to run
CI / Build Prometheus for all architectures (10) (push) Waiting to run
CI / Build Prometheus for all architectures (11) (push) Waiting to run
CI / Build Prometheus for all architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (3) (push) Waiting to run
CI / Build Prometheus for all architectures (4) (push) Waiting to run
CI / Build Prometheus for all architectures (5) (push) Waiting to run
CI / Build Prometheus for all architectures (6) (push) Waiting to run
CI / Build Prometheus for all architectures (7) (push) Waiting to run
CI / Build Prometheus for all architectures (8) (push) Waiting to run
CI / Build Prometheus for all architectures (9) (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
api: Improve doc comments for v1.MinTime and v1.MaxTime While investigated something mostly unrelated, I got nerd-sniped by the calculation of v1.MinTime and v1.MaxTime. The seemingly magic number in there (62135596801) needed an explanation. While looking for it, I found out that the offsets used here are actually needlessly conservative. Since the timestamps are so far in the past or future, respectively, that there is no practical impact, except that the calculation is needlessly obfuscated. However, we won't change the values now to not cause any confusion for users of this code. Still, I think the doc comment should explain the circumstances so nobody gets nerd-sniped again as I did today. For the record: 62135596800 is the difference in seconds between 0001-01-01 00:00:00 (Unix time zero point) and 1971-01-01 00:00:00 (Go time zero point) in the Gregorian calendar. If "Prometheus time" were in seconds (not milliseconds), that difference would be relevant to prevent over-/underflow when converting from "Prometheus time" to "Go time". Signed-off-by: beorn7 <beorn@grafana.com> --------- Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
parent
c5c2566b8a
commit
4cb5f23c35
|
@ -834,12 +834,22 @@ func (api *API) labelValues(r *http.Request) (result apiFuncResult) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// MinTime is the default timestamp used for the begin of optional time ranges.
|
// MinTime is the default timestamp used for the start of optional time ranges.
|
||||||
// Exposed to let downstream projects to reference it.
|
// Exposed to let downstream projects reference it.
|
||||||
|
//
|
||||||
|
// Historical note: This should just be time.Unix(math.MinInt64/1000, 0).UTC(),
|
||||||
|
// but it was set to a higher value in the past due to a misunderstanding.
|
||||||
|
// The value is still low enough for practical purposes, so we don't want
|
||||||
|
// to change it now, avoiding confusion for importers of this variable.
|
||||||
MinTime = time.Unix(math.MinInt64/1000+62135596801, 0).UTC()
|
MinTime = time.Unix(math.MinInt64/1000+62135596801, 0).UTC()
|
||||||
|
|
||||||
// MaxTime is the default timestamp used for the end of optional time ranges.
|
// MaxTime is the default timestamp used for the end of optional time ranges.
|
||||||
// Exposed to let downstream projects to reference it.
|
// Exposed to let downstream projects to reference it.
|
||||||
|
//
|
||||||
|
// Historical note: This should just be time.Unix(math.MaxInt64/1000, 0).UTC(),
|
||||||
|
// but it was set to a lower value in the past due to a misunderstanding.
|
||||||
|
// The value is still high enough for practical purposes, so we don't want
|
||||||
|
// to change it now, avoiding confusion for importers of this variable.
|
||||||
MaxTime = time.Unix(math.MaxInt64/1000-62135596801, 999999999).UTC()
|
MaxTime = time.Unix(math.MaxInt64/1000-62135596801, 999999999).UTC()
|
||||||
|
|
||||||
minTimeFormatted = MinTime.Format(time.RFC3339Nano)
|
minTimeFormatted = MinTime.Format(time.RFC3339Nano)
|
||||||
|
|
Loading…
Reference in a new issue