-
Notifications
You must be signed in to change notification settings - Fork 26
feat: add observability_pipelines resource type #725
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
michael-richey
wants to merge
10
commits into
main
Choose a base branch
from
michael.richey/add-observability-pipelines
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
05b9617
feat: add observability_pipelines resource type
michael-richey 0f77d7e
docs: add observability_pipelines to README and integration test stub
michael-richey 171dc9c
fix: use custom PaginationConfig for OP meta.totalCount response shape
michael-richey 81ca09f
fix: add observability_pipelines to _ID_FILE_STATE_LOAD_SUPPORTED_TYPES
michael-richey 82339d9
chore: retrigger CI (ubuntu-latest runner stuck)
michael-richey 218333b
chore: retrigger CI (test jobs stuck on runner)
michael-richey 2d44c96
chore: retrigger CI (integration test suite timed out)
michael-richey b2a8717
chore: retrigger integration tests (queue cleared)
michael-richey 90a3c83
Merge remote-tracking branch 'origin/main' into michael.richey/add-ob…
michael-richey d5e6cf1
chore: retrigger integration tests (previous run was cancelled)
michael-richey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # Unless explicitly stated otherwise all files in this repository are licensed | ||
| # under the 3-clause BSD style license (see LICENSE). | ||
| # This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| # Copyright 2019 Datadog, Inc. | ||
|
|
||
| from __future__ import annotations | ||
| from typing import TYPE_CHECKING, Optional, List, Dict, Tuple, cast | ||
|
|
||
| from datadog_sync.utils.base_resource import BaseResource, ResourceConfig | ||
| from datadog_sync.utils.custom_client import PaginationConfig | ||
|
|
||
| if TYPE_CHECKING: | ||
| from datadog_sync.utils.custom_client import CustomClient | ||
|
|
||
|
|
||
| def _op_remaining_func(idx, resp, page_size, page_number): | ||
| """remaining_func for the OP list response. | ||
|
|
||
| The OP API returns total count as ``meta.totalCount`` (camelCase), not the | ||
| default ``meta.page.total_count`` used by most other v2 endpoints. If ``meta`` | ||
| or ``totalCount`` is absent, return a negative value so pagination stops | ||
| after the current page (the ``resp_len < page_size`` break in | ||
| ``paginated_request`` already handles the last-page case). | ||
| """ | ||
| meta = resp.get("meta") or {} | ||
| total = meta.get("totalCount", 0) | ||
| return total - page_size * (page_number + 1) | ||
|
|
||
|
|
||
| class ObservabilityPipelines(BaseResource): | ||
| resource_type = "observability_pipelines" | ||
| resource_config = ResourceConfig( | ||
| base_path="/api/v2/obs-pipelines/pipelines", | ||
| excluded_attributes=["id"], | ||
| resource_mapping_key="id", | ||
| ) | ||
| # The OP list endpoint paginates with page[size]/page[number] (matching the | ||
| # default param names) but returns total count as meta.totalCount, not the | ||
| # default meta.page.total_count. Use a custom remaining_func so multi-page | ||
| # responses don't raise KeyError on the missing meta.page key. | ||
| pagination_config = PaginationConfig( | ||
| page_size=100, | ||
| page_size_param="page[size]", | ||
| page_number_param="page[number]", | ||
| remaining_func=_op_remaining_func, | ||
| ) | ||
|
|
||
| async def get_resources(self, client: CustomClient) -> List[Dict]: | ||
| resp = await client.paginated_request(client.get)( | ||
| self.resource_config.base_path, pagination_config=self.pagination_config | ||
| ) | ||
|
|
||
| return resp | ||
|
|
||
| async def import_resource(self, _id: Optional[str] = None, resource: Optional[Dict] = None) -> Tuple[str, Dict]: | ||
| if _id: | ||
| source_client = self.config.source_client | ||
| resource = (await source_client.get(self.resource_config.base_path + f"/{_id}"))["data"] | ||
| resource = cast(dict, resource) | ||
|
|
||
| return resource["id"], resource | ||
|
|
||
| async def pre_resource_action_hook(self, _id, resource: Dict) -> None: | ||
| pass | ||
|
|
||
| async def pre_apply_hook(self) -> None: | ||
| pass | ||
|
|
||
| async def create_resource(self, _id: str, resource: Dict) -> Tuple[str, Dict]: | ||
| if _id in self._existing_resources_map: | ||
| self.config.state.destination[self.resource_type][_id] = self._existing_resources_map[_id] | ||
| return await self.update_resource(_id, resource) | ||
|
|
||
| destination_client = self.config.destination_client | ||
| payload = {"data": resource} | ||
| resp = await destination_client.post(self.resource_config.base_path, payload) | ||
|
|
||
| return _id, resp["data"] | ||
|
|
||
| async def update_resource(self, _id: str, resource: Dict) -> Tuple[str, Dict]: | ||
| destination_client = self.config.destination_client | ||
| resource["id"] = self.config.state.destination[self.resource_type][_id]["id"] | ||
| payload = {"data": resource} | ||
| resp = await destination_client.put( | ||
| self.resource_config.base_path + f"/{self.config.state.destination[self.resource_type][_id]['id']}", | ||
| payload, | ||
| ) | ||
|
|
||
| return _id, resp["data"] | ||
|
|
||
| async def delete_resource(self, _id: str) -> None: | ||
| destination_client = self.config.destination_client | ||
| await destination_client.delete( | ||
| self.resource_config.base_path + f"/{self.config.state.destination[self.resource_type][_id]['id']}" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/integration/resources/test_observability_pipelines.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Unless explicitly stated otherwise all files in this repository are licensed | ||
| # under the 3-clause BSD style license (see LICENSE). | ||
| # This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
|
|
||
| from datadog_sync.models import ObservabilityPipelines | ||
| from tests.integration.helpers import BaseResourcesTestClass | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Cannot delete these from destination easily") | ||
| class TestObservabilityPipelines(BaseResourcesTestClass): | ||
|
michael-richey marked this conversation as resolved.
|
||
| resource_type = ObservabilityPipelines.resource_type | ||
| field_to_update = "attributes.name" | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.