Skip to content

adding SDK changes for ACLP APIs #528

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
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open

Conversation

pmajali
Copy link

@pmajali pmajali commented Apr 11, 2025

📝 Description

The PR adds Monitor API for ACLP Product

✔️ How to Test

import os
import logging
from linode_api4 import LinodeClient

logger = logging.getLogger(__name__)

client = LinodeClient(os.environ.get("MY_PERSONAL_ACCESS_TOKEN"))
client.base_url = "https://api.linode.com/v4beta"


print("Listing services supported by ACLP")
services = client.monitor.supported_services()
for service in services:
        print("Label:", service.label)

How do I run the relevant unit/integration tests?

Run unit test as follows
pytest test/unit

Run integration test as follows
make testint TEST_SUITE=monitor

@pmajali pmajali requested a review from a team as a code owner April 11, 2025 06:20
@pmajali pmajali requested review from jriddle-linode and lgarber-akamai and removed request for a team April 11, 2025 06:20
@lgarber-akamai lgarber-akamai added the new-feature for new features in the changelog. label Apr 11, 2025
@yec-akamai
Copy link
Contributor

@pmajali Thank you for starting contributing to python SDK! Do you mind filling the PR description and test steps?

@@ -21,3 +21,4 @@
from .tag import *
from .volume import *
from .vpc import *
from .monitor import *

Check notice

Code scanning / CodeQL

'import *' may pollute namespace Note

Import pollutes the enclosing namespace, as the imported module
linode_api4.groups.monitor
does not define '__all__'.
@@ -21,3 +21,4 @@
from .vpc import *
from .beta import *
from .placement import *
from .monitor import *

Check notice

Code scanning / CodeQL

'import *' may pollute namespace Note

Import pollutes the enclosing namespace, as the imported module
linode_api4.objects.monitor
does not define '__all__'.
Copy link
Author

Choose a reason for hiding this comment

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

updated the group and object to include 'all'

@@ -0,0 +1,122 @@
import json

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'json' is not used.
MetricDefinition,
CreateToken,
)
from linode_api4 import LinodeClient,MySQLDatabase

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'MySQLDatabase' is not used.
CreateToken,
)
from linode_api4 import LinodeClient,MySQLDatabase
import re

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 're' is not used.
)
from linode_api4 import LinodeClient,MySQLDatabase
import re
import time

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'time' is not used.
from test.unit.base import ClientBaseCase
import datetime

from linode_api4.objects import CreateToken

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'CreateToken' is not used.
@yec-akamai yec-akamai self-requested a review April 18, 2025 15:27
Copy link
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.

Can you fix the PR given the suggestion from code scanning?

Comment on lines +42 to +63
def dashboard_by_ID(self, dashboard_id: int, *filters):
"""
Returns a dashboards on your account based on the ID passed.

.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.

API Documentation: https://techdocs.akamai.com/linode-api/reference/get-dashboards-by-id

:param filters: Any number of filters to apply to this query.
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
for more details on filtering.

:returns: A Dashboards.
:rtype: PaginatedList of the Dashboard
"""
result = self.client.get(f"/monitor/dashboards/{dashboard_id}")

if not "id" in result:
raise UnexpectedResponseError(
"Unexpected response when getting Dashboard!", json=result
)
return DashboardsByID(self.client, result["id"], result)
Copy link
Contributor

@yec-akamai yec-akamai Apr 18, 2025

Choose a reason for hiding this comment

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

You don't have to explicitly implement the get by id method in the group. If you read through the Base class for object, you can find each object has inherited some basic functions, i.e. get, set, delete, etc. Can you please update your PR to match the codebase standard?

Copy link
Author

Choose a reason for hiding this comment

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

The functions in the base class can only be used when the API parses ID based on the header called 'X-Filter'. The ACLP APIs are not written in a way to recognise any additional headers like this, hence added a new method for ID

Comment on lines +7 to +39
class Dashboard(Base):
"""
List dashboards: https://techdocs.akamai.com/linode-api/get-dashboards-all
"""

api_endpoint = "/monitor/dashboards/"
properties = {
"id": Property(identifier=True),
"created": Property(is_datetime=True),
"label": Property(),
"service_type": Property(),
"type": Property(),
"widgets": Property(mutable=True),
"updated": Property(is_datetime=True),

}

class DashboardsByID(Base):
"""
Get a dashboard: https://techdocs.akamai.com/linode-api/reference/get-dashboards-by-id
"""


properties = {
"id": Property(identifier=True),
"created": Property(is_datetime=True),
"label": Property(),
"service_type": Property(),
"type": Property(),
"widgets": Property(mutable=True),
"updated": Property(is_datetime=True),

}
Copy link
Contributor

@lgarber-akamai lgarber-akamai Apr 21, 2025

Choose a reason for hiding this comment

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

Could these two be merged using an api_endpoint like /monitor/dashboards/{id}?

Copy link
Author

Choose a reason for hiding this comment

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

The /monitor/dashboards and /monitor/dashboards/{id} are implemented separately in the codebase. It does not expect the 'X-filter' header which I believe is mandatory for grouping it.

Co-authored-by: Lena Garber <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature for new features in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants