Skip to content

Commit b386c11

Browse files
committed
review updates
1 parent 33e954f commit b386c11

File tree

3 files changed

+55
-30
lines changed

3 files changed

+55
-30
lines changed

linode_api4/groups/monitor_service.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class MonitorGroup(Group):
1212
"""
13-
Encapsulates Monitor-related methods of the :any:`LinodeClient`.
13+
Encapsulates Monitor-related methods of the :any:`LinodeClient`.
1414
1515
This group contains all features beneath the `/monitor` group in the API v4.
1616
"""
@@ -36,12 +36,14 @@ def list_monitor_dashboards(self, *filters) -> list[MonitorDashboard]:
3636

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

39-
def list_dashboards_by_service(self, service_type: str, *filters) -> list[MonitorDashboard]:
39+
def list_dashboards_by_service(
40+
self, service_type: str, *filters
41+
) -> list[MonitorDashboard]:
4042
"""
4143
Returns a list of dashboards for a particular service.
42-
44+
4345
dashboard_by_service = client.monitor_service.list_dashboards_by_service(service_type="dbaas")
44-
46+
4547
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
4648
4749
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-dashboards
@@ -67,7 +69,7 @@ def list_supported_services(self, *filters) -> list[MonitorService]:
6769
Returns a list of services supported by ACLP.
6870
6971
supported_services = client.monitor_service.list_supported_services()
70-
72+
7173
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
7274
7375
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services
@@ -82,22 +84,24 @@ def list_supported_services(self, *filters) -> list[MonitorService]:
8284

8385
return self.client._get_and_filter(MonitorService, *filters)
8486

85-
def list_service_by_type(self, service_type: str, *filters) -> list[MonitorService]:
87+
def list_service_by_type(
88+
self, service_type: str, *filters
89+
) -> list[MonitorService]:
8690
"""
8791
Lists monitor services by a given service_type
8892
8993
service_details = client.monitor_service.list_service_by_type(service_type="dbaas")
90-
94+
9195
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
92-
96+
9397
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services-for-service-type
94-
98+
9599
:param service_type: The service type to get details for.
96100
:type service_type: str
97101
:param filters: Any number of filters to apply to this query.
98102
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
99103
for more details on filtering.
100-
104+
101105
:returns: Lists monitor services by a given service_type
102106
:rtype: PaginatedList of the Services
103107
"""
@@ -107,8 +111,9 @@ def list_service_by_type(self, service_type: str, *filters) -> list[MonitorServi
107111
endpoint=f"/monitor/services/{service_type}",
108112
)
109113

110-
111-
def list_metric_definitions(self, service_type: str, *filters) -> list[MonitorMetricsDefinition]:
114+
def list_metric_definitions(
115+
self, service_type: str, *filters
116+
) -> list[MonitorMetricsDefinition]:
112117
"""
113118
Returns metrics for a specific service type.
114119
@@ -132,15 +137,17 @@ def list_metric_definitions(self, service_type: str, *filters) -> list[MonitorMe
132137
endpoint=f"/monitor/services/{service_type}/metric-definitions",
133138
)
134139

135-
def create_token(self, service_type: str, entity_ids: list) -> MonitorServiceToken:
140+
def create_token(
141+
self, service_type: str, entity_ids: list
142+
) -> MonitorServiceToken:
136143
"""
137144
Returns a JWE Token for a specific service type.
138145
token = client.monitor_service.create_token(service_type="dbaas", entity_ids=[1234])
139146
140147
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
141148
142149
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-get-token
143-
150+
144151
:param service_type: The service type to create token for.
145152
:type service_type: str
146153
:param entity_ids: The list of entity IDs for which the token is valid.
@@ -161,4 +168,3 @@ def create_token(self, service_type: str, entity_ids: list) -> MonitorServiceTok
161168
"Unexpected response when creating token!", json=result
162169
)
163170
return MonitorServiceToken(token=result["token"])
164-

linode_api4/objects/monitor_service.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass, field
2-
from typing import Any, Dict, List, Optional, Union
2+
from typing import List, Optional
33

44
from linode_api4.objects import Base, JSONObject, Property, StrEnum
55

@@ -8,6 +8,7 @@ class AggregateFunction(StrEnum):
88
"""
99
Enum for supported aggregate functions.
1010
"""
11+
1112
min = "min"
1213
max = "max"
1314
avg = "avg"
@@ -17,17 +18,21 @@ class AggregateFunction(StrEnum):
1718
increase = "increase"
1819
last = "last"
1920

21+
2022
class ChartType(StrEnum):
2123
"""
2224
Enum for supported chart types.
2325
"""
26+
2427
line = "line"
2528
area = "area"
2629

30+
2731
class ServiceType(StrEnum):
2832
"""
2933
Enum for supported service types.
3034
"""
35+
3136
dbaas = "dbaas"
3237
linode = "linode"
3338
lke = "lke"
@@ -37,19 +42,23 @@ class ServiceType(StrEnum):
3742
object_storage = "object_storage"
3843
aclb = "aclb"
3944

45+
4046
class MetricType(StrEnum):
4147
"""
4248
Enum for supported metric type
4349
"""
50+
4451
gauge = "gauge"
4552
counter = "counter"
4653
histogram = "histogram"
4754
summary = "summary"
4855

56+
4957
class MetricUnit(StrEnum):
5058
"""
5159
Enum for supported metric units.
5260
"""
61+
5362
COUNT = "count"
5463
PERCENT = "percent"
5564
BYTE = "byte"
@@ -66,18 +75,22 @@ class MetricUnit(StrEnum):
6675
OPS_PER_SECOND = "ops_per_second"
6776
IOPS = "iops"
6877

78+
6979
class DashboardType(StrEnum):
7080
"""
7181
Enum for supported dashboard types.
7282
"""
83+
7384
standard = "standard"
7485
custom = "custom"
7586

87+
7688
@dataclass
7789
class DashboardWidget(JSONObject):
7890
"""
7991
Represents a single widget in the widgets list.
8092
"""
93+
8194
metric: str = ""
8295
unit: MetricUnit = ""
8396
label: str = ""
@@ -86,21 +99,24 @@ class DashboardWidget(JSONObject):
8699
chart_type: ChartType = ""
87100
y_label: str = ""
88101
aggregate_function: AggregateFunction = ""
89-
102+
103+
90104
@dataclass
91105
class Dimension(JSONObject):
92106
"""
93107
Represents a single dimension in the dimensions list.
94108
"""
109+
95110
dimension_label: Optional[str] = None
96111
label: Optional[str] = None
97112
values: Optional[List[str]] = None
98-
113+
114+
99115
@dataclass
100116
class MonitorMetricsDefinition(JSONObject):
101117
"""
102118
Represents a single metric definition in the metrics definition list.
103-
119+
104120
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-information
105121
"""
106122

@@ -111,8 +127,10 @@ class MonitorMetricsDefinition(JSONObject):
111127
scrape_interval: int = 0
112128
is_alertable: bool = False
113129
dimensions: Optional[List[Dimension]] = None
114-
available_aggregate_functions: List[AggregateFunction] = field(default_factory=list)
115-
130+
available_aggregate_functions: List[AggregateFunction] = field(
131+
default_factory=list
132+
)
133+
116134

117135
class MonitorDashboard(Base):
118136
"""
@@ -132,11 +150,12 @@ class MonitorDashboard(Base):
132150
"updated": Property(is_datetime=True),
133151
}
134152

153+
135154
class MonitorService(Base):
136155
"""
137156
Represents a single service type.
138157
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services
139-
158+
140159
"""
141160

142161
api_endpoint = "/monitor/services/{service_type}"
@@ -146,7 +165,8 @@ class MonitorService(Base):
146165
"label": Property(),
147166
}
148167

149-
@dataclass
168+
169+
@dataclass
150170
class MonitorServiceToken(JSONObject):
151171
"""
152172
A token for the requested service_type.
@@ -155,6 +175,3 @@ class MonitorServiceToken(JSONObject):
155175
"""
156176

157177
token: str = ""
158-
159-
160-

test/unit/objects/monitor_service_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,17 @@ def test_get_all_dashboards(self):
8787
self.assertEqual(dashboards[0].widgets[0].y_label, "cpu_usage")
8888

8989
def test_specific_service_details(self):
90-
data = self.client.monitor_service.list_service_by_type(service_type="dbaas")
90+
data = self.client.monitor_service.list_service_by_type(
91+
service_type="dbaas"
92+
)
9193
self.assertEqual(data[0].label, "Databases")
9294
self.assertEqual(data[0].service_type, "dbaas")
9395

9496
def test_metric_definitions(self):
9597

96-
metrics = self.client.monitor_service.list_metric_definitions(service_type="dbaas")
98+
metrics = self.client.monitor_service.list_metric_definitions(
99+
service_type="dbaas"
100+
)
97101
self.assertEqual(
98102
metrics[0].available_aggregate_functions,
99103
["max", "avg", "min", "sum"],
@@ -117,5 +121,3 @@ def test_create_token(self):
117121
service_type="dbaas", entity_ids=[189690, 188020]
118122
)
119123
self.assertEqual(m.return_dct["token"], "abcdefhjigkfghh")
120-
121-

0 commit comments

Comments
 (0)