Repository navigation
Adding email channel api support to python SDK - #709
mawasthy-lgtm wants to merge 12 commits into
Conversation
| "label": Property(), | ||
| "type": Property(), | ||
| "label": Property(mutable=True), | ||
| "type": Property(AlertChannelType), |
There was a problem hiding this comment.
The Property class doesn't support passing another class in as the first positional argument of its constructor.
| return PaginatedList( | ||
| self.client, | ||
| endpoint[1:], | ||
| page=result, | ||
| max_pages=response_json.get("pages", 1), | ||
| total_items=response_json.get("results", len(result)), | ||
| parent_id=None, | ||
| filters=parsed_filters, | ||
| ) |
There was a problem hiding this comment.
Doesn't seem to be the right way of creating a PaginatedList instance. Does make_paginated_list or make_list work for your case?
There was a problem hiding this comment.
🟡 Changes recommended
Alert references are incorrectly treated as fully populated definitions and retain a mutable discriminator that save() can send, while the channel CRUD test suppresses deletion failures.
2 open issues
What changed in this PR
Adds email alert-channel management to the Monitor SDK, extending existing read support with creation, updates, deletion, and retrieval of associated alerts.
Changes:
- Adds channel creation and paginated alert lookup, preserving each alert’s service context.
- Makes channel labels and details editable and introduces an alert-channel type enum.
- Adds unit and integration coverage, channel fixtures, and
%unit values in database-monitoring fixtures.
| File | Description |
|---|---|
test/unit/objects/monitor_test.py |
Tests channel lifecycle operations and updates the metric-unit assertion. |
test/unit/groups/monitor_api_test.py |
Tests channel operations, associated alerts, and service context across pages. |
test/integration/models/monitor/test_monitor.py |
Adds live channel tests and creates channels for alert-definition tests. |
test/fixtures/monitor_services_dbaas_metric-definitions.json |
Changes the CPU metric unit to %. |
test/fixtures/monitor_services_dbaas_alert-definitions.json |
Updates the alert-list fixture’s CPU unit. |
test/fixtures/monitor_services_dbaas_alert-definitions_12345.json |
Updates the individual alert fixture’s CPU unit. |
test/fixtures/monitor_alert-channels_123.json |
Adds an individual email-channel response fixture. |
test/fixtures/monitor_alert-channels_123_alerts.json |
Adds a paginated channel-alert reference fixture. |
linode_api4/objects/monitor.py |
Adds channel type values and enables label and details updates. |
linode_api4/groups/monitor.py |
Adds channel creation and service-aware associated-alert retrieval. |
Review effort: Balanced
| return super().make_instance( | ||
| id, | ||
| client, | ||
| parent_id=parent_id, | ||
| json=json, | ||
| ) |
| # Clean up: delete the created channel | ||
| try: | ||
| created_channel.delete() | ||
| except Exception as e: | ||
| # Log but don't fail if cleanup fails | ||
| print( | ||
| f"Warning: Failed to delete channel {created_channel.id}: {e}" | ||
| ) |
| class _AlertChannelAlertDefinition(AlertDefinition): | ||
| """Build channel alerts with each response item's service parent.""" | ||
|
|
||
| @classmethod | ||
| def make_instance(cls, id, client, parent_id=None, json=None): | ||
| if parent_id is None and json: | ||
| parent_id = json.get(cls.parent_id_name) | ||
| return super().make_instance( | ||
| id, | ||
| client, | ||
| parent_id=parent_id, | ||
| json=json, | ||
| ) |
There was a problem hiding this comment.
Why do we need a derived class of AlertDefinition rather than putting the method into AlertDefinition directly? Was there any blocker?
| return self.client._get_and_filter( | ||
| _AlertChannelAlertDefinition, | ||
| *filters, | ||
| endpoint=f"/monitor/alert-channels/{channel_id}/alerts", |
There was a problem hiding this comment.
_AlertChannelAlertDefinition is a derived class of AlertDefinition, which doesn't match the schema of the API.


📝 Description
Updating python sdk to include email channel management api
What does this PR do and why is this change necessary?
Adds full SDK support for Creating a new channel (post request) used by tests and examples.
Ensures create channel fields are parsed and exposed as per the latest API response.
This change is necessary because:
The SDK did not have channel management api added.
✔️ How to Test
Clone the repository
Prepare environment (zsh / macOS)
✔️create & activate venv (recommended)
python3 -m venv .venv
source .venv/bin/activate
install deps
python -m pip install --upgrade pip
Install runtime dependencies:
pip3 install requests polling deprecated
Install dev/test extras
pip3 install -e '.[dev,test]'
test deps
pip3 install pytest mock httpretty pytest-rerunfailures
✔️How do I run the relevant unit tests?
cd <PROJECT_DIRECTORY>/linode_api4-python
Unit tests: python -m pytest test/unit -q
Unit test for all monitor: python3 -m pytest test/unit/objects/monitor_test.py -q -s
python3 -m pytest test/unit/groups/monitor_api_test.py -q -s -v
Single unit: python3 -m pytest test/unit/objects/monitor_test.py::MonitorTest -q -s
python3 -m pytest test/unit/groups/monitor_api_test.py::MonitorAlertDefinitionsTest::test_create_channel -q -s -v
What are the steps to reproduce the issue or verify the changes?
End to end integration testing should suffice
✔️How do I run the relevant integration tests?
Integration tests (E2E):
Note:
#if you have PAT token with write access only to Monitor and read for rest of the services for integration
export SKIP_E2E_FIREWALL=1 # optional: skip firewall autouse fixture
export LINODE_TOKEN="YOUR_REAL_TOKEN" # required for integration
export SKIP_E2E_FIREWALL=1 # optional: skip firewall autouse fixture
python3 -m pytest test/integration/models/monitor/test_monitor.py::test_integration_create_get_delete_alert_channel -q -s