Skip to content

Validate start/end times in the reporting client and CLI - #335

Merged
cwasicki merged 4 commits into
frequenz-floss:v0.x.xfrom
cwasicki:times
Nov 2, 2026
Merged

cwasicki merged 4 commits into
frequenz-floss:v0.x.xfrom
cwasicki:times

Conversation

@cwasicki

@cwasicki cwasicki commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Guards the reporting request time range against two easy mistakes: ambiguous naive datetimes and an inverted window.

  • Reject timezone-naive start_time/end_time in the client. A naive value is ambiguous, the wire encoding reads it as UTC while datetime.timestamp() reads it as local time, so the same input would denote different instants. The
    client now raises rather than silently pick one meaning.
  • Require a timezone offset on the CLI --start/--end arguments, so a naive value fails at argument parsing with a clear message instead of surfacing as a ValueError later.
  • Warn on the CLI when --end precedes --start. The inverted window is still a legal, empty range and the request runs, but at the CLI it is almost always a typo, and the warning explains the otherwise silent empty output.

@cwasicki
cwasicki requested a balanced review from Copilot October 2, 2026 17:45
@github-actions github-actions Bot added the part:tests Affects the unit, integration and performance (benchmarks) tests label Oct 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The awareness check misses valid naive cases, and the new constraint leaves public documentation and examples inaccurate.

Review effort: Balanced
Findings: 3 Low severity

Open (3)
What changed in this PR

Adds timezone validation and inverted-window warnings to reporting requests.

Changes:

  • Rejects timezone-naive client inputs.
  • Validates CLI timestamps and warns about inverted ranges.
  • Adds client validation tests.
File Description
src/​frequenz/​client/​reporting/​_client.py Validates request timestamps.
src/​frequenz/​client/​reporting/​cli/​__main__.py Validates CLI timestamps and warns on inverted ranges.
tests/​test_client_reporting.py Tests client-side validation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The validator still accepts naive datetimes whose timezone returns no UTC offset, causing an unintended downstream exception.

2 open issues
2 resolved since last review

Review effort: Balanced

@cwasicki
cwasicki force-pushed the times branch 2 times, most recently from 45041d9 to 74589be Compare October 19, 2026 19:20
@cwasicki
cwasicki requested a balanced review from Copilot October 19, 2026 19:21
@github-actions github-actions Bot added the part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) label Oct 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The documented CLI timestamps still lack offsets and are rejected by the new validation.

2 open issues
1 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

Static review found no blocking issues, and the compatibility change is documented; tests were not run.

2 open issues

Review effort: Balanced

llucax
llucax previously approved these changes Oct 23, 2026

@llucax llucax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@cwasicki

Copy link
Copy Markdown
Contributor Author

Updated

@cwasicki

cwasicki commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Rebased

A naive datetime is ambiguous: the wire encoding assumes UTC while
datetime.timestamp() assumes local time, so the same value would denote
different instants. Reject it at the public request boundary rather than
silently pick one meaning.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
A naive datetime is ambiguous: the wire encoding assumes UTC while
datetime.timestamp() assumes local time. Reject it at the argparse boundary
so the CLI fails with a clear message instead of a ValueError.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
At the CLI an inverted window is almost always a typo, and failing makes
scripts that build bad arguments notice.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
AC_ACTIVE_POWER and AC_REACTIVE_POWER are not members of Metric. The CLI
validates --metrics against the enum, so the documented command errored out,
and the Python examples referenced attributes that do not exist. Use the
actual names AC_POWER_ACTIVE and AC_POWER_REACTIVE.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
@cwasicki

cwasicki commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Rebased again on latest head.

@cwasicki
cwasicki requested a review from llucax November 2, 2026 12:51
@cwasicki
cwasicki disabled auto-merge November 2, 2026 13:19
@cwasicki
cwasicki added this pull request to the merge queue Nov 2, 2026
Merged via the queue into frequenz-floss:v0.x.x with commit 0fb98bd Nov 2, 2026
9 checks passed
@cwasicki
cwasicki deleted the times branch November 2, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants