fix: user status change chart accommodates DST (#22191)

closes https://github.com/coder/internal/issues/464

# Summary

This PR resolves a flaky test that was sensitive to DST transitions in
various time zones. The root of the flake was:
* a bug; the query and its tests assume 24 hours per day
* the tests used local system time, which resulted in failures for dates
proximal to DST transitions

# Changes

Query:

The original query assumed 24 hour intervals between each day, which is
not a valid assumption. It now increments `1 day` at a time.

Database tests:

Database level tests for the query all assumed 24 hour days. They now
increment in DST-aware days instead. Instead of using time.Now() as a
base for testing, the test uses a series of dates over the course of an
entire year, to ensure that DST transition dates are present in every
test run.

# API Endpoint

The endpoint that delivers the user status chart now accepts an IANA
timezone name as a parameter and passes it, keeping the existing offset
as a fallback, to the database query.

API level tests were added to ensure the correct response form and error
behaviour. Correctness of content is tested at the database level.
This commit is contained in:
Sas Swart
2026-03-04 12:54:39 +02:00
committed by GitHub
parent 2882e36222
commit cfcb81fb0f
13 changed files with 407 additions and 269 deletions
+5 -4
View File
@@ -266,7 +266,7 @@ To perform this operation, you must be authenticated. [Learn more](authenticatio
```shell
# Example request using curl
curl -X GET http://coder-server:8080/api/v2/insights/user-status-counts?tz_offset=0 \
curl -X GET http://coder-server:8080/api/v2/insights/user-status-counts \
-H 'Accept: application/json' \
-H 'Coder-Session-Token: API_KEY'
```
@@ -275,9 +275,10 @@ curl -X GET http://coder-server:8080/api/v2/insights/user-status-counts?tz_offse
### Parameters
| Name | In | Type | Required | Description |
|-------------|-------|---------|----------|----------------------------|
| `tz_offset` | query | integer | true | Time-zone offset (e.g. -2) |
| Name | In | Type | Required | Description |
|-------------|-------|---------|----------|---------------------------------------------------------------|
| `timezone` | query | string | false | IANA timezone name (e.g. America/St_Johns) |
| `tz_offset` | query | integer | false | Deprecated: Time-zone offset (e.g. -2). Use timezone instead. |
### Example responses