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 17 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?

@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?

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.

You'll have to sign all of you commits (make sure each commit has the green Verified tag) before merging this PR. To save troubles in the end, I'd suggest to do it sooner than later. You can look for github official docs to add signatures to all your commits

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.

Thanks for addressing the comments! A few things to note:

Comment on lines 18 to 65
def list_monitor_dashboards(self, *filters) -> list[MonitorDashboard]:
"""
Returns a list of dashboards.

dashboards = client.monitor_service.list_monitor_dashboards()
dashboard = client.load(MonitorDashboard, 1)

.. 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-all

: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 list of Dashboards.
:rtype: PaginatedList of Dashboard
"""

return self.client._get_and_filter(MonitorDashboard, *filters)

def list_dashboards_by_service(
self, service_type: str, *filters
) -> list[MonitorDashboard]:
"""
Returns a list of dashboards for a particular service.

dashboard_by_service = client.monitor_service.list_dashboards_by_service(service_type="dbaas")

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

:param service_type: The service type to get dashboards for.
:type service_type: str
: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: Dashboards filtered by Service Type.
:rtype: PaginatedList of the Dashboards
"""

return self.client._get_and_filter(
MonitorDashboard,
*filters,
endpoint=f"/monitor/services/{service_type}/dashboards",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it makes more sense to combine these two functions, since they're serving the same purpose to list dashboards and returning the same type.

How about we just having one function dashboards(...), and take an optional parameter service_type? In this case if service_type is provided by user, we will call the listing dashboards by service_type endpoint; if not, we will can the basic listing endpoint. The function header should looks like:

 def dashborads(
        self, service_type: Optional[str], *filters
    ) -> PaginatedList:
      # implement the two endpoints

Copy link
Author

Choose a reason for hiding this comment

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

We could have one function but both the endpoints have different implementation and fall under different api_endpoint group, so it could be misleading.
for dashboards we have - /monitor/dashboards/{id}
for service dashboard - /monitor/services/{service_type}/dashboards

return self.client._get_and_filter(
MonitorService,
*filters,
endpoint=f"/monitor/services/{service_type}",
Copy link
Contributor

Choose a reason for hiding this comment

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

I checked the api doc, and it looks GET /monitor/services/{service_type} is not a listing endpoint

Copy link
Author

Choose a reason for hiding this comment

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

This endpoint should ideally return the details about a service. But the return type is a list.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh interesting, do you mean that even GET /monitor/services/{service_type} supposed to get a single service, but the response is a list, right?

Comment on lines 154 to 166
class MonitorService(Base):
"""
Represents a single service type.
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services

"""

api_endpoint = "/monitor/services/{service_type}"
id_attribute = "service_type"
properties = {
"service_type": Property(ServiceType, identifier=True),
"label": Property(),
}
Copy link
Contributor

@yec-akamai yec-akamai May 16, 2025

Choose a reason for hiding this comment

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

Since GET /monitor/services/{service_type} returns a list, it can't be populated by the default _api_get() in Base. I think you can build MonitorService into a JSONObject as well, so user won't accidentally try to get this object from default approach

Copy link
Author

Choose a reason for hiding this comment

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

updated to JSONObject

:param service_type: The service type to create token for.
:type service_type: str
:param entity_ids: The list of entity IDs for which the token is valid.
:type entity_ids: list of int
Copy link
Contributor

@yec-akamai yec-akamai May 20, 2025

Choose a reason for hiding this comment

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

It seems entity_ids is not necessary a list of int and could be any id types based on the linodego change: linode/linodego#746 Can you make the change and test it correspondingly as well?

Copy link
Author

Choose a reason for hiding this comment

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

updated type to Any

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.

Nice work, tests passed locally! Just change the entity_ids type then should be good to go

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