Skip to content

Commit 6169571

Browse files
authored
Merge branch 'dev' into chore/update-docstring
2 parents cd4aecc + 5e120f6 commit 6169571

13 files changed

Lines changed: 1945 additions & 4 deletions

.github/workflows/e2e-test-pr.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ on:
22
pull_request:
33
workflow_dispatch:
44
inputs:
5+
run_aclp_logs_stream_tests:
6+
description: 'Set this parameter to "true" to run ACLP logs stream related test cases'
7+
required: false
8+
default: 'false'
9+
type: choice
10+
options:
11+
- 'true'
12+
- 'false'
513
run_db_fork_tests:
614
description: 'Set this parameter to "true" to run fork database related test cases'
715
required: false
@@ -104,7 +112,7 @@ jobs:
104112
run: |
105113
timestamp=$(date +'%Y%m%d%H%M')
106114
report_filename="${timestamp}_sdk_test_report.xml"
107-
make test-int RUN_DB_FORK_TESTS=${{ github.event.inputs.run_db_fork_tests }} RUN_DB_TESTS=${{ github.event.inputs.run_db_tests }} TEST_ARGS="--junitxml=${report_filename}" TEST_SUITE="${{ github.event.inputs.test_suite }}"
115+
make test-int RUN_DB_FORK_TESTS=${{ github.event.inputs.run_db_fork_tests }} RUN_DB_TESTS=${{ github.event.inputs.run_db_tests }} RUN_ACLP_LOGS_STREAM_TESTS=${{ github.event.inputs.run_aclp_logs_stream_tests }} TEST_ARGS="--junitxml=${report_filename}" TEST_SUITE="${{ github.event.inputs.test_suite }}"
108116
env:
109117
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}
110118

.github/workflows/e2e-test.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ name: Integration Tests
33
on:
44
workflow_dispatch:
55
inputs:
6+
run_aclp_logs_stream_tests:
7+
description: 'Set this parameter to "true" to run ACLP logs stream related test cases'
8+
required: false
9+
default: 'false'
10+
type: choice
11+
options:
12+
- 'true'
13+
- 'false'
614
run_db_fork_tests:
715
description: 'Set this parameter to "true" to run fork database related test cases'
816
required: false
@@ -99,7 +107,7 @@ jobs:
99107
run: |
100108
timestamp=$(date +'%Y%m%d%H%M')
101109
report_filename="${timestamp}_sdk_test_report.xml"
102-
make test-int RUN_DB_FORK_TESTS=${{ github.event.inputs.run_db_fork_tests }} RUN_DB_TESTS=${{ github.event.inputs.run_db_tests }} TEST_SUITE="${{ github.event.inputs.test_suite }}" TEST_ARGS="--junitxml=${report_filename}"
110+
make test-int RUN_DB_FORK_TESTS=${{ github.event.inputs.run_db_fork_tests }} RUN_DB_TESTS=${{ github.event.inputs.run_db_tests }} RUN_ACLP_LOGS_STREAM_TESTS=${{ github.event.inputs.run_aclp_logs_stream_tests }} TEST_SUITE="${{ github.event.inputs.test_suite }}" TEST_ARGS="--junitxml=${report_filename}"
103111
env:
104112
LINODE_TOKEN: ${{ env.LINODE_TOKEN }}
105113

linode_api4/groups/monitor.py

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@
88
AlertDefinition,
99
AlertDefinitionEntity,
1010
AlertScope,
11+
LogsDestination,
12+
LogsDestinationType,
13+
LogsStream,
14+
LogsStreamStatus,
15+
LogsStreamType,
1116
MonitorDashboard,
1217
MonitorMetricsDefinition,
1318
MonitorService,
1419
MonitorServiceToken,
1520
)
21+
from linode_api4.objects.monitor import (
22+
AkamaiObjectStorageLogsDestinationDetails,
23+
CustomHTTPSLogsDestinationDetails,
24+
LogsStreamDetails,
25+
)
1626

1727
__all__ = [
1828
"MonitorGroup",
@@ -318,3 +328,206 @@ def alert_definition_entities(
318328
*filters,
319329
endpoint=endpoint,
320330
)
331+
332+
def destinations(self, *filters) -> PaginatedList:
333+
"""
334+
List available logs destinations.
335+
336+
Returns a paginated collection of :class:`LogsDestination` objects which
337+
describe logs destinations. By default, this method returns all available
338+
destinations; you can supply optional filter expressions to restrict
339+
the results, for example::
340+
341+
# Get destinations created by username and with id 111
342+
destinations = client.monitor.destinations(LogsDestination.created_by == "username",
343+
LogsDestination.id == 111)
344+
345+
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-destinations
346+
347+
:param filters: Any number of filters to apply to this query.
348+
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
349+
for more details on filtering.
350+
351+
:returns: A list of :class:`LogsDestination` objects matching the query.
352+
:rtype: PaginatedList of LogsDestination
353+
"""
354+
355+
return self.client._get_and_filter(LogsDestination, *filters)
356+
357+
def destination_create(
358+
self,
359+
label: str,
360+
type: Union[LogsDestinationType, str],
361+
details: Union[
362+
AkamaiObjectStorageLogsDestinationDetails,
363+
CustomHTTPSLogsDestinationDetails,
364+
],
365+
) -> LogsDestination:
366+
"""
367+
Creates a new :any:`LogsDestination` for logs on this account.
368+
369+
For an ``akamai_object_storage`` destination::
370+
371+
client = LinodeClient(TOKEN)
372+
373+
new_destination = client.monitor.destination_create(
374+
label="OBJ_logs_destination",
375+
type="akamai_object_storage",
376+
details=AkamaiObjectStorageLogsDestinationDetails(
377+
access_key_id="1ABCD23EFG4HIJKLMNO5",
378+
access_key_secret="1aB2CD3e4fgHi5JK6lmnop7qR8STU9VxYzabcdefHh",
379+
bucket_name="primary-bucket",
380+
host="primary-bucket-1.us-east-12.linodeobjects.com",
381+
path="audit-logs",
382+
)
383+
)
384+
385+
For a ``custom_https`` destination::
386+
387+
new_destination = client.monitor.destination_create(
388+
label="custom_logs_destination",
389+
type="custom_https",
390+
details=CustomHTTPSLogsDestinationDetails(
391+
endpoint_url="https://my-site.com/log-storage/basicAuth",
392+
authentication=DestinationAuthentication(
393+
type="basic",
394+
details=BasicAuthenticationDetails(
395+
basic_authentication_user="user",
396+
basic_authentication_password="pass",
397+
),
398+
),
399+
data_compression="gzip",
400+
content_type="application/json",
401+
)
402+
)
403+
404+
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-destination
405+
406+
:param label: The name for this logs destination.
407+
:type label: str
408+
:param type: The type of destination — ``akamai_object_storage`` or ``custom_https``.
409+
:type type: str or LogsDestinationType
410+
:param details: A typed details object matching the destination type.
411+
Use :class:`AkamaiObjectStorageLogsDestinationDetails` for
412+
``akamai_object_storage`` or :class:`CustomHTTPSLogsDestinationDetails`
413+
for ``custom_https``.
414+
:type details: AkamaiObjectStorageLogsDestinationDetails or CustomHTTPSLogsDestinationDetails
415+
416+
:returns: The newly created logs destination.
417+
:rtype: LogsDestination
418+
"""
419+
420+
params = {
421+
"label": label,
422+
"type": type,
423+
"details": details.dict,
424+
}
425+
426+
result = self.client.post("/monitor/streams/destinations", data=params)
427+
428+
if "id" not in result:
429+
raise UnexpectedResponseError(
430+
"Unexpected response when creating destination!",
431+
json=result,
432+
)
433+
434+
return LogsDestination(self.client, result["id"], result)
435+
436+
def streams(self, *filters) -> PaginatedList:
437+
"""
438+
List available logs streams.
439+
440+
Returns a paginated collection of :class:`LogsStream` objects which
441+
describe logs streams. By default, this method returns all available
442+
streams; you can supply optional filter expressions to restrict
443+
the results, for example::
444+
445+
# Get all streams with status ``provisioning``
446+
provisioning_streams = client.monitor.streams(LogsStream.status == "provisioning")
447+
448+
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-streams
449+
450+
:param filters: Any number of filters to apply to this query.
451+
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
452+
for more details on filtering.
453+
:returns: A list of :class:`LogsStream` objects matching the query.
454+
:rtype: PaginatedList of LogsStream
455+
"""
456+
457+
return self.client._get_and_filter(LogsStream, *filters)
458+
459+
def stream_create(
460+
self,
461+
destinations: list[int],
462+
label: str,
463+
type: Union[LogsStreamType, str],
464+
status: Optional[Union[LogsStreamStatus, str]] = None,
465+
details: Optional[LogsStreamDetails] = None,
466+
) -> LogsStream:
467+
"""
468+
Creates a new :any:`LogsStream` for logs on this account. For example::
469+
470+
client = LinodeClient(TOKEN)
471+
472+
# audit_logs stream (no details required)
473+
new_stream = client.monitor.stream_create(
474+
destinations=[1234],
475+
label="Linode_services",
476+
status="active",
477+
type="audit_logs"
478+
)
479+
480+
# lke_audit_logs stream with specific clusters
481+
lke_stream = client.monitor.stream_create(
482+
destinations=[1234],
483+
label="LKE_audit_stream",
484+
type="lke_audit_logs",
485+
details=LogsStreamDetails(
486+
cluster_ids=[1111, 2222],
487+
is_auto_add_all_clusters_enabled=False,
488+
)
489+
)
490+
491+
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-stream
492+
493+
:param destinations: The unique identifier for the sync point that will receive logs data.
494+
Run the List destinations operation and store the id values for each applicable destination.
495+
At the moment only single destination is supported.
496+
:type destinations: list[int]
497+
:param label: The name of the stream. This is used for display purposes in Akamai Cloud Manager.
498+
:type label: str
499+
:param type: The type of stream — ``audit_logs`` for Linode control plane logs,
500+
or ``lke_audit_logs`` for LKE enterprise cluster audit logs.
501+
:type type: str or LogsStreamType
502+
:param status: (Optional) The availability status of the stream. Possible values are: ``active``, ``inactive``.
503+
Defaults to ``active``.
504+
:type status: str
505+
:param details: (Optional) Additional stream details. Only applicable for
506+
``lke_audit_logs`` streams. Omit for ``audit_logs`` streams.
507+
:type details: LogsStreamDetails
508+
509+
:returns: The newly created logs stream.
510+
:rtype: LogsStream
511+
"""
512+
513+
params = {
514+
"label": label,
515+
"type": type,
516+
"destinations": destinations,
517+
}
518+
519+
if status is not None:
520+
params["status"] = status
521+
522+
if details is not None:
523+
params["details"] = details.dict
524+
525+
result = self.client.post("/monitor/streams", data=params)
526+
527+
if "id" not in result:
528+
raise UnexpectedResponseError(
529+
"Unexpected response when creating logs stream!",
530+
json=result,
531+
)
532+
533+
return LogsStream(self.client, result["id"], result)

0 commit comments

Comments
 (0)