Skip to content

feat: support add Monitor api plugin - #879

Open
susharma-beep wants to merge 3 commits into
linode:devfrom
susharma-beep:monitor-api-plugin
Open

susharma-beep wants to merge 3 commits into
linode:devfrom
susharma-beep:monitor-api-plugin

Conversation

@susharma-beep

Copy link
Copy Markdown
Contributor

📝 Description

What does this PR do and why is this change necessary?

This PR adds a new monitor-api plugin for the Linode CLI that provides access to the Linode Monitor API for querying metrics across various services.

Key features:

Query metrics for multiple services: DBaaS, NodeBalancer, NetLoadBalancer, Linode, Firewall, ObjectStorage, BlockStorage, and LKE
Support for both relative time duration (--duration/--duration-unit) and absolute time ranges (--start-time/--end-time)
Mandatory aggregate functions for all metrics (sum, avg, max, min, count)
Optional filtering, grouping, and granularity controls
Region-based queries for services like ObjectStorage
Comprehensive validation for all input parameters

✔️ How to Test

What are the steps to reproduce the issue or verify the changes?
Set the authentication token:
export JWE_TOKEN='your_jwe_token_here'
Test basic metrics query:
linode-cli monitor-api get-metrics objectstorage
--entity-region us-east-1 --duration 15 --duration-unit min
--metrics obj_requests_num:sum
Test with filters:
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'
Test help command:
linode-cli monitor-api get-metrics --help

How do I run the relevant unit/integration tests?

Run unit tests (no authentication required)

pytest tests/unit/test_plugin_get_metrics.py -v

Run integration tests (requires JWE_TOKEN)

export JWE_TOKEN='your_token'
pytest tests/integration/monitor/test_plugin_get_metrics.py -v

Run linting

make lint

This plugin provides access to the Linode Monitor API, allowing users to query metrics for various services with options for filtering and time duration.
Add unit tests for monitor-api metrics functionality
Added integration tests for the get_metrics plugin, covering various scenarios including missing arguments, invalid service names, and handling of filters.
@susharma-beep
susharma-beep requested review from a team as code owners April 9, 2026 09:18
@susharma-beep
susharma-beep requested review from ckulinsk and jbilskiAkam and removed request for a team April 9, 2026 09:18
@zliang-akamai
zliang-akamai requested review from a team, jriddle-linode and mawilk90 and a balanced review from Copilot and removed request for a team, ckulinsk and jbilskiAkam September 17, 2026 16:14
@zliang-akamai

Copy link
Copy Markdown
Member

Is this PR still needed? @susharma-beep

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

🟡 Changes recommended

Service and time validation defects allow invalid requests, while several help examples and tests are misleading.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds a Monitor API plugin for querying service metrics with time ranges, aggregation, filtering, grouping, and regional parameters.

Changes:

  • Implements Monitor API request construction, validation, and output formatting.
  • Adds unit coverage for requests, parsing, and response handling.
  • Adds integration coverage for validation and authenticated queries.
File summaries
File Description
linodecli/plugins/monitor-api.py Implements the Monitor API plugin.
tests/unit/test_plugin_get_metrics.py Adds focused unit tests.
tests/integration/monitor/test_plugin_get_metrics.py Adds CLI and authenticated integration tests.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 7
  • Review effort level: Balanced

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

Comment on lines +384 to +389
parser.add_argument(
"service",
nargs="?",
help="Service name (Dbaas, Nodebalancer, NetLoadBalancer, Linode, "
"Firewall, ObjectStorage, Blockstorage, LKE)",
)
Comment on lines +450 to +453
parser.add_argument(
"--group_by",
help="Comma-separated list of fields to group by (default: entity_id)",
)
Comment on lines +467 to +477
# Validate entity_ids requirement (only objectstorage allows querying all entities)
if not parsed.entity_ids and parsed.service.lower() != "objectstorage":
print(
f"--entity-ids is required for service '{parsed.service}'",
file=sys.stderr,
)
print(
"Only 'objectstorage' service allows querying all entities without --entity-ids",
file=sys.stderr,
)
return False
Comment on lines +480 to +496
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
Comment on lines +65 to +81
def test_invalid_service():
"""Test error handling for invalid service name"""
exec_failing_test_command(
BASE_CMD
+ [
"invalid_service",
"--entity-ids",
"123",
"--metrics",
"cpu_usage:avg",
"--duration",
"15",
"--duration-unit",
"min",
],
expected_code=ExitCodes.REQUEST_FAILED,
)
print("\n # Get metrics with granularity")
print(
" linode-cli monitor-api get-metrics netloadbalancer --entity-ids 123 "
"--duration 1 --duration-unit hour --metrics nlb_ingress_traffic:sum "
Comment on lines +360 to +362
" linode-cli monitor-api get-metrics firewall --entity-region us-east-1 "
"--associated-entity-region us-west-1 --duration 15 "
"--duration-unit min --metrics fw_active_connections:sum"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants