Skip to content

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

Open
cwasicki wants to merge 5 commits into
frequenz-floss:v0.x.xfrom
cwasicki:times
Open

cwasicki wants to merge 5 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.

Comment thread src/frequenz/client/reporting/_client.py
Comment thread src/frequenz/client/reporting/_client.py
Comment thread src/frequenz/client/reporting/cli/__main__.py Outdated

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

Comment thread src/frequenz/client/reporting/_client.py Outdated
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>
@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

Comment thread src/frequenz/client/reporting/cli/__main__.py
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>
An inverted window is a legal but empty range, so the request still runs;
at the CLI it is almost always a typo, and the silent empty output gives
no hint why.

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

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>

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 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.

Comment on lines +112 to +116
if args.start and args.end and args.end < args.start:
print(
"warning: --end is before --start; no data will be returned",
file=sys.stderr,
)

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.

I wonder if it doesn't make more sense to just reject it? Do you want to allow it for any specific reason?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agreed, I think throwing an error makes sense here so that it can break scripts that manage to create invalid input parameters etc

This branch has not been deployed

No deployments
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.

4 participants