Skip to content

fix: monitor time-based search timezone offset#12275

Open
jakub961241 wants to merge 1 commit into1Panel-dev:dev-v2from
jakub961241:fix/monitor-timezone-search-11891
Open

fix: monitor time-based search timezone offset#12275
jakub961241 wants to merge 1 commit into1Panel-dev:dev-v2from
jakub961241:fix/monitor-timezone-search-11891

Conversation

@jakub961241
Copy link

Summary

Fixes #11891 - Monitor time-based search is off by timezone offset (e.g., 8 hours for UTC+8 servers).

Root Cause

In agent/app/service/monitor.go, LoadMonitorData and LoadGPUMonitorData used:

req.StartTime = req.StartTime.In(loc)

time.In(loc) only changes the timezone label for display - it does NOT change the underlying moment in time. So the DB query still searched for the wrong time range.

Fix

When the frontend sends time in UTC but the server runs in a different timezone, reconstruct the time.Time with the server's local timezone. This treats the time values as "wall clock time":

if req.StartTime.Location() == time.UTC && loc != time.UTC {
    req.StartTime = time.Date(year, month, day, hour, min, sec, nsec, loc)
}

This shifts the actual moment to match what the user selected in the UI.

Changed file

  • agent/app/service/monitor.go - Fix both LoadMonitorData and LoadGPUMonitorData
fix: Monitor time-based search now correctly handles timezone offset (#11891)

When searching monitor data by time range, the results were off by the
server's timezone offset (e.g., 8 hours for UTC+8). The previous code
used time.In(loc) which only changes the display timezone but doesn't
adjust the actual moment in time for the DB query.

The fix: when the frontend sends time in UTC but the server is in a
different timezone, reconstruct the time.Time with the local timezone
so the DB query matches the correct time range. This treats the
frontend's time values as "wall clock time" in the server's timezone.

Applied to both LoadMonitorData and LoadGPUMonitorData.

Fixes 1Panel-dev#11891
@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Mar 22, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign wanghe-fit2cloud for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] The time-based search in Website Monitoring is incorrect

1 participant