When step is a multiple of 1 day, each point will offset multiple hours

Summary of Open Issue: Thanos-IO/Thanos - Timezone Offset in Range Queries

Issue Overview:

The issue raised by ChaoHsupin centers around the Thanos frontend’s handling of range queries with a step size of 1 day. Currently, when this step is specified, the resulting data points are aligned to UTC 00:00. Users in timezones that are significantly offset from UTC, such as Asia/Shanghai (UTC+8), experience misalignment, as their expected alignment point should be 08:00 local time.

Proposed Solution:

ChaoHsupin suggests a modification to handle timezones more flexibly:

  1. Modify the step_align.go code to apply timezone offsets when the step is a multiple of 1 day. This involves adjusting the start and end times by the timezone offset.
  2. Implement an optional timezone parameter that can be set as part of the API request from the frontend.

Example code modification shared:

if r.GetStep()%day.Milliseconds() == 0 {
start -= shanghai_offset_ms.Milliseconds()
end -= shanghai_offset_ms.Milliseconds()
}

Additional Contributions and Discussions:

  • Douglas Camata and Rita Canavarro suggest implementing timezone detection based on the user’s browser settings, allowing users the option to manually switch timezones (similar to Grafana).
  • Discussions include considerations on the impact of these changes on other components and compatibility with existing APIs, especially for Grafana users.
  • There is interest in understanding how similar projects like Cortex/Mimir handle timezone adjustments to avoid duplicating efforts in the Thanos framework.

Current Status:

There are active contributors interested in implementing these changes, with an invitation for collaboration and discussion for insights on feasibility and design. The issue is labeled as a bug and categorized as a good first issue for new contributors.

Next Steps:

  • Assess existing implementations in related projects.
  • Finalize the approach (including UI changes for timezone selection).
  • Develop the code, test it, and prepare for a pull request.