Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert ISO timestamp output from UTC to local time + offset in flux dmesg and eventlog commands #6423

Merged
merged 8 commits into from
Nov 10, 2024

Conversation

grondo
Copy link
Contributor

@grondo grondo commented Nov 8, 2024

This PR changes the default timestamp display for flux dmesg and the "iso" time format for flux job eventlog flux kvs eventlog and flux job wait-event to use local time instead of UTC. This better matches the behavior of most other system utilities and logfiles, and the old behavior can easily be restored if desired by setting TZ=UTC.

Fixes #6421

Problem: It would be useful to optionally append the TZ offset to
ISO 8601 timestamps in Flux, but no function exists to do that.

Add a new timestamp_tzoffset() function that takes a struct tm and
returns the current timezone TZ offset of the form [+-]HH:MM. Note
that this function is required in order to add the colon (:), which
aids in readability, because strftime(3) "%z" does not include a colon.
(The colon is optional in ISO 8601).

timestamp_tzoffset() also returns "Z" instead of "+00:00" for UTC for
backwards compatibility with existing timestamp formats.
Problem: There's no tests of timestamp_tzoffset() handling of invalid
arguments.

Add a couple tests to the libutil timestamp.c unit tests.
Problem: The eventlogger ISO formatter always outputs eventlog
timestamps in UTC. This can make it difficult to compare these
timestamps to system timestamps which are usually recorded in
localtime.

Convert the eventlog formatter ISO timestamp to use localtime plus
the timezone offset (e.g. +08:00). If UTC is desired, then TZ=UTC
can be used to get the old behavior.
src/cmd/builtin/dmesg.c Fixed Show fixed Hide fixed
t/t0009-dmesg.t Outdated
test_expect_success 'dmesg with TZ=America/Los_Angeles uses tz offset' '
TZ=America/Los_Angeles flux dmesg \
| grep -E \
"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]+-[0-9]{2}:[0-9]{2}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my memory isn't good on timezone stuff, but if we're fixing American/Los Angeles in the test, wouldn't the offset in the last chunk be known? -08:00?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be different depending on current daylight savings? Anyway, this was probably good enough and I didn't want a randomly failing test.

The test is failing anyway in some builders - I wonder if they don't support this timezeone

@grondo
Copy link
Contributor Author

grondo commented Nov 8, 2024

@chu11 noticed I dropped the actual conversion of the dmesg timestamp to local time here. Setting WIP until I fix that.

@grondo grondo changed the title convert ISO timestamp output from UTC to local time + offset in flux dmesg and eventlog commands WIP: convert ISO timestamp output from UTC to local time + offset in flux dmesg and eventlog commands Nov 8, 2024
Problem: flux-dmesg(1) logs ISO 8601 timestamps in UTC timezone only,
which makes it difficult to compare to other system timestamps,
which are usually displayed in localtime.

Convert timestamps by default to localtime+offset form in flux-dmesg(1)
output. If UTC is desired, the command may be run with TZ=UTC.
Problem: The timestamp print functions in the dmesg builtin command
pass a `struct stdlog_header` by value, but CodeQL rightly warns this
structure has a large size and would be better passed by address.

Pass a pointer to the stdlog_header in these functions instead of
the entire struct.
Problem: A missing colon breaks the display of :command:`flux-dmesg`.

Add the missing colon.
Copy link
Member

@chu11 chu11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@grondo grondo force-pushed the issue#6421 branch 2 times, most recently from 7d28d5d to 628375a Compare November 9, 2024 16:24
Problem: None of the tests in t0009-demsg.t test that flux-dmesg(1)
properly formats timestamps in the local time + timezone offset.

Add a couple tests that ensure the timestamp output of flux-dmesg(1)
is as expected.
Problem: No tests ensure `flux job eventlog` with `--time-format=iso`
shows timestamps in local time with a timezone offset.

Add a test to t2230-job-info-lookup.t.
@grondo grondo changed the title WIP: convert ISO timestamp output from UTC to local time + offset in flux dmesg and eventlog commands convert ISO timestamp output from UTC to local time + offset in flux dmesg and eventlog commands Nov 9, 2024
@grondo
Copy link
Contributor Author

grondo commented Nov 9, 2024

Removed WIP. Had to add a workaround in the tests for detecting missing tzdata on apline and jammy

@grondo
Copy link
Contributor Author

grondo commented Nov 10, 2024

setting MWP. Thanks!

@mergify mergify bot merged commit e1e59d7 into flux-framework:master Nov 10, 2024
34 checks passed
Copy link

codecov bot commented Nov 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.63%. Comparing base (3ad7986) to head (bf7fb79).
Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6423      +/-   ##
==========================================
- Coverage   83.64%   83.63%   -0.01%     
==========================================
  Files         524      524              
  Lines       87617    87637      +20     
==========================================
+ Hits        73286    73294       +8     
- Misses      14331    14343      +12     
Files with missing lines Coverage Δ
src/cmd/builtin/dmesg.c 94.95% <100.00%> (+0.94%) ⬆️
src/common/libeventlog/formatter.c 89.44% <100.00%> (+0.11%) ⬆️
src/common/libutil/timestamp.c 95.58% <100.00%> (+1.35%) ⬆️

... and 8 files with indirect coverage changes

@grondo grondo deleted the issue#6421 branch November 10, 2024 22:38
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.

consider using local time for eventlog formatter ISO 8601 format
2 participants