Skip to content
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

Add support for metrics metadata syncing #249

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ When running againts multiple destination organizations, a seperate working dire
| logs_pipelines_order | Sync Datadog logs pipelines order. |
| logs_restriction_queries | Sync Datadog logs restriction queries. |
| metric_tag_configurations | Sync Datadog metric tags configurations. |
| metrics_metadata | Sync Datadog metric metadata. |
| monitors | Sync Datadog monitors. |
| notebooks | Sync Datadog notebooks. |
| powerpacks | Sync Datadog powerpacks. |
Expand All @@ -229,9 +230,9 @@ When running againts multiple destination organizations, a seperate working dire
| service_level_objectives | Sync Datadog SLOs. |
| slo_corrections | Sync Datadog SLO corrections. |
| spans_metrics | Sync Datadog spans metrics. |
| synthetics_global_variables | Sync Datadog synthetic global variables. |
| synthetics_private_locations | Sync Datadog synthetic private locations. |
| synthetics_tests | Sync Datadog synthetic tests. |
| synthetics_global_variables | Sync Datadog synthetic global variables. |
| synthetics_private_locations | Sync Datadog synthetic private locations. |
| synthetics_tests | Sync Datadog synthetic tests. |
| teams | Sync Datadog teams (excluding users and permissions). |
| users | Sync Datadog users. |

Expand Down Expand Up @@ -260,6 +261,7 @@ See [Supported resources](#supported-resources) section below for potential reso
| logs_pipelines_order | logs_pipelines |
| logs_restriction_queries | roles |
| metric_tag_configurations | - |
| metrics_metadata | - |
| monitors | roles, service_level_objectives |
| notebooks | - |
| powerpacks | monitors, service_level_objectives |
Expand Down
59 changes: 59 additions & 0 deletions datadog_sync/model/metrics_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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 typing import Optional, List, Dict, Tuple

from datadog_sync.utils.base_resource import BaseResource, ResourceConfig
from datadog_sync.utils.custom_client import CustomClient
from datadog_sync.utils.resource_utils import SkipResource


class MetricsMetadata(BaseResource):
resource_type = "metrics_metadata"
resource_config = ResourceConfig(
base_path="/api/v1/metrics",
excluded_attributes=["integration"],
)
# Additional MetricsMetadata specific attributes
metrics_get_path = "/api/v2/metrics"

async def get_resources(self, client: CustomClient) -> List[Dict]:
params = {
"filter[configured]": "false",
"window[seconds]": 14 * 86400, # 14 days
}
resp = await client.get(self.metrics_get_path, params=params)

return resp["data"]

async def import_resource(self, _id: Optional[str] = None, resource: Optional[Dict] = None) -> Tuple[str, Dict]:
source_client = self.config.source_client
metric_name = _id or resource["id"]

resource = await source_client.get(self.resource_config.base_path + f"/{metric_name}")
if all(value is None for value in resource.values()):
raise SkipResource(metric_name, self.resource_type, "Metric has no metadata.")

return metric_name, 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]:
return await self.update_resource(_id, resource)

async def update_resource(self, _id: str, resource: Dict) -> Tuple[str, Dict]:
destination_client = self.config.destination_client
resp = await destination_client.put(self.resource_config.base_path + f"/{_id}", resource)

return _id, resp

async def delete_resource(self, _id: str) -> None:
pass

def connect_id(self, key: str, r_obj: Dict, resource_to_connect: str) -> Optional[List[str]]:
pass
1 change: 0 additions & 1 deletion datadog_sync/model/powerpacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,3 @@ async def delete_resource(self, _id: str) -> None:

def connect_id(self, key: str, r_obj: Dict, resource_to_connect: str) -> Optional[List[str]]:
return super(Powerpacks, self).connect_id(key, r_obj, resource_to_connect)

1 change: 1 addition & 0 deletions datadog_sync/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from datadog_sync.model.logs_pipelines_order import LogsPipelinesOrder
from datadog_sync.model.logs_restriction_queries import LogsRestrictionQueries
from datadog_sync.model.metric_tag_configurations import MetricTagConfigurations
from datadog_sync.model.metrics_metadata import MetricsMetadata
from datadog_sync.model.monitors import Monitors
from datadog_sync.model.notebooks import Notebooks
from datadog_sync.model.powerpacks import Powerpacks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-05-20T16:03:56.970961-04:00
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-05-20T16:03:56.983697-04:00
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-05-20T16:03:52.778410-04:00
Loading
Loading