-
Notifications
You must be signed in to change notification settings - Fork 79
Python SDK for ACLP Alerts #589
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
Open
srbhaakamai
wants to merge
17
commits into
linode:dev
Choose a base branch
from
srbhaakamai:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Request @ketan Vaish to review this as internal reviwer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@yec-akamai @jriddle-linode Is you see this line, internal reviews are not yet complete. Will notify/inform once the internal reviews are complete.
📝 Description
Add Monitor alerting SDK + fix/harden monitor unit & integration tests
What does this PR do and why is this change necessary?
This change is necessary because:
SDK additions (high level)
Payload:
{
"label": "sdk-e2e-1234",
"severity": 3,
"type": "threshold",
"description": "Temporary alert created by SDK e2e test",
"channel_ids": [10000],
"trigger_conditions": {
"criteria_condition": "ALL",
"evaluation_period_seconds": 300,
"polling_interval_seconds": 300,
"trigger_occurrences": 1
},
"rule_criteria": {
"rules": [
{
"metric": "cpu_usage",
"operator": "gt",
"threshold": 90,
"aggregate_function": "avg",
"period": 300,
"unit": "percent",
"dimension_filters": []
}
]
},
"conditions": [],
"notification_groups": []
}
Note:
✔️ How to Test
create & activate venv (recommended)
python3 -m venv .venv
source .venv/bin/activate
install deps
python -m pip install --upgrade pip
python -m pip install -r requirements-dev.txt
Files changed (summary)
Modified (key):
linode_api4/groups/monitor.py — MonitorGroup CRUD methods
linode_api4/linode_client.py — client.monitor init
linode_api4/objects/monitor.py — objects for AlertDefinition, Metric, etc.
linode_api4/objects/serializable.py — Enum serialization fix
test/unit/base.py — added mock_get/_helpers
test/unit/groups/monitor_api_test.py — updated/added tests
test/integration/conftest.py — fixtures: skip behavior for insufficient token perms
test/integration/models/monitor/test_monitor.py — E2E create/update/delete test
How do I run the relevant tests?
Unit tests: python -m pytest test/unit -q
Single unit: python -m pytest test/unit/groups/monitor_api_test.py::MonitorAlertDefinitionsTest::test_alert_definitions_for_service_calls_endpoint -q -s
Single integration: python -m pytest test/integration/models/monitor/test_monitor.py::test_integration_create_get_update_delete_alert_definition -q -s
What are the steps to reproduce the issue or verify the changes?
How do I run the relevant unit/integration tests?
Unit tests (fast)
Run all monitor unit tests
python -m pytest test/unit/groups/monitor_api_test.py -q -s
Run a single unit test
python -m pytest test/unit/groups/monitor_api_test.py::MonitorAlertDefinitionsTest::test_alert_definitions_for_service_calls_endpoint -q -s
Integration tests (E2E)
Provide a Linode token with required scopes. For full E2E you need monitor:write and other service-specific scopes (networking:write / databases:write if fixtures create firewalls or DBs).
If you lack networking or DB scopes and want to run alert integration only, set SKIP_E2E_FIREWALL=1 (the test fixtures will skip firewall provisioning).
export LINODE_TOKEN="YOUR_REAL_TOKEN" # required for integration
export SKIP_E2E_FIREWALL=1 # optional: skip firewall autouse fixture
python -m pytest test/integration/models/monitor/test_monitor.py::test_integration_create_get_update_delete_alert_definition -q -s
📷 Preview