Skip to content

feat: Add CLI Plugin for monitor-api#845

Open
pmajali wants to merge 12 commits intolinode:devfrom
pmajali:dev
Open

feat: Add CLI Plugin for monitor-api#845
pmajali wants to merge 12 commits intolinode:devfrom
pmajali:dev

Conversation

@pmajali
Copy link
Copy Markdown

@pmajali pmajali commented Jan 1, 2026

📝 Description

A CLI plugin for the ACLP metric-read-api

✔️ How to Test

What are the steps to reproduce the issue or verify the changes?
linode-cli get_metrics dbaas --entity-ids 123 --duration 15 --duration-unit min --metrics cpu_usage:avg --filters 'node_type:in:primary,secondary'

the help command prints the list of sample commands. A JWE token is required to be set to make these calls.
details on generating JWE token https://techdocs.akamai.com/linode-api/reference/post-get-token
API details: https://techdocs.akamai.com/linode-api/reference/post-read-metric

How do I run the relevant unit/integration tests?
python -m pytest tests/unit/test_plugin_get_metrics.py -v

for integration set, set a JWE_TOKEN env var for service type objectstorage
python -m pytest tests/integration/monitor/test_plugin_get_metrics.py -v

@pmajali pmajali requested a review from a team as a code owner January 1, 2026 10:26
@pmajali pmajali requested review from lgarber-akamai and zliang-akamai and removed request for a team January 1, 2026 10:26
@yec-akamai yec-akamai requested review from a team, Copilot, jriddle-linode, vshanthe and yec-akamai and removed request for a team January 7, 2026 14:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@yec-akamai yec-akamai requested a review from Copilot January 9, 2026 15:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@yec-akamai yec-akamai left a comment

Choose a reason for hiding this comment

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

The command looks not quite right in regards to the url call. Can you make changes according to the comments?

@susharma-beep susharma-beep requested a review from a team as a code owner April 8, 2026 05:47
@susharma-beep susharma-beep requested review from ckulinsk and removed request for a team and vshanthe April 8, 2026 05:47
@susharma-beep
Copy link
Copy Markdown

The cli command has been updated to below
linode-cli monitor-api get-metrics dbaas --entity-ids 123 --duration 15 --duration-unit min --metrics cpu_usage:avg --filters 'node_type:in:primary,secondary'

help commands
linode-cli monitor-api get-metrics --help

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +126 to +127
parsed_metrics.append(
{"aggregate_function": agg_func, "name": metric_name.strip()}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

parse_metrics accepts any aggregate function after : and sends it to the API without validation. Since AGGREGATE_FUNCTIONS is defined, validate agg_func (after .strip()/normalization) is one of the allowed values and fail fast with a clear error if not.

Suggested change
parsed_metrics.append(
{"aggregate_function": agg_func, "name": metric_name.strip()}
metric_name = metric_name.strip()
agg_func = agg_func.strip().lower()
if not metric_name:
print(
f"Metric name is required for metric '{metric}'",
file=sys.stderr,
)
print(
f"Format: 'metric_name:function' where function is one of: "
f"{', '.join(AGGREGATE_FUNCTIONS)}",
file=sys.stderr,
)
sys.exit(ExitCodes.REQUEST_FAILED)
if agg_func not in AGGREGATE_FUNCTIONS:
print(
f"Invalid aggregate function '{agg_func}' for metric '{metric}'",
file=sys.stderr,
)
print(
f"Aggregate function must be one of: "
f"{', '.join(AGGREGATE_FUNCTIONS)}",
file=sys.stderr,
)
sys.exit(ExitCodes.REQUEST_FAILED)
parsed_metrics.append(
{"aggregate_function": agg_func, "name": metric_name}

Copilot uses AI. Check for mistakes.
Comment on lines +435 to +454
# Validate time duration arguments
has_relative = (
parsed.duration is not None and parsed.duration_unit is not None
)
has_absolute = parsed.start_time is not None and parsed.end_time is not None

if not has_relative and not has_absolute:
print("Time duration required:", file=sys.stderr)
print(" Either: --duration and --duration-unit", file=sys.stderr)
print(" Or: --start-time and --end-time", file=sys.stderr)
return False

if has_relative and has_absolute:
print(
"Cannot specify both relative and absolute time duration",
file=sys.stderr,
)
return False

return True
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

validate_arguments enforces presence of relative vs absolute time params, but it never validates the allowed values for --duration-unit / --granularity-unit (help text says min/hr/day). Add validation to reject unsupported units (and also fail if only one of --granularity/--granularity-unit is provided) so errors are caught client-side instead of relying on API failures.

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +15
import pytest

from linodecli.exit_codes import ExitCodes
from tests.integration.helpers import (
exec_failing_test_command,
exec_test_command,
)

# Base command for monitor-api plugin
BASE_CMD = ["linode-cli", "monitor-api", "get-metrics"]

Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

These integration tests call the real service and will fail hard if JWE_TOKEN isn’t set. Consider adding a pytest.mark.skipif(not os.getenv('JWE_TOKEN'), ...) guard (or a fixture) for the success-path tests so running pytest tests/integration without credentials doesn’t produce unrelated failures.

Copilot uses AI. Check for mistakes.
@susharma-beep susharma-beep force-pushed the dev branch 2 times, most recently from d3cc043 to 87c3278 Compare April 9, 2026 06:27
pmajali and others added 6 commits April 9, 2026 17:28
- Changed plugin base from 'linode-cli get_metrics' to 'linode-cli monitor-api' with 'get-metrics' as a subcommand
- Refactored API_BASE_URL to be more generic, allowing API version specification
- Updated all help text and examples to reflect new command structure
- Updated unit and integration tests accordingly
…de#873)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 3.12.0 to 4.0.0.
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](docker/setup-buildx-action@8d2750c...4d04d5d)

---
updated-dependencies:
- dependency-name: docker/setup-buildx-action
  dependency-version: 4.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
ezilber-akamai and others added 5 commits April 9, 2026 17:29
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Add validation for aggregate function values (must be in AGGREGATE_FUNCTIONS)
- Add validation for duration-unit and granularity-unit (must be min/hr/day)
- Enforce entity-ids requirement for non-objectstorage services
- Validate that granularity and granularity-unit are provided together
- Add -h flag handling for help (in addition to --help)
- Make payload printing debug-only (only shown with --debug flag)
- Add @requires_jwe_token skip decorator for integration tests
- Add new test cases for validation improvements
@yec-akamai yec-akamai added new-feature for new features in the changelog. community-contribution for contributions made by a non-DX author labels Apr 9, 2026
@yec-akamai yec-akamai changed the title plugin for MR Add CLI Plugin for monitor-api Apr 9, 2026
@pmajali pmajali changed the title Add CLI Plugin for monitor-api feat: Add CLI Plugin for monitor-api Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution for contributions made by a non-DX author new-feature for new features in the changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants