Skip to content
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
6 changes: 1 addition & 5 deletions datadog_sync/model/dashboard_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,5 @@ def connect_id(self, key: str, r_obj: Dict, resource_to_connect: str) -> Optiona
async def update_dash_list_items(self, _id: str, dashboards: Dict, dashboard_list: dict):
payload = {"dashboards": dashboards}
destination_client = self.config.destination_client
try:
dashboards = await destination_client.put(self.dash_list_items_path.format(_id), payload)
except CustomClientHTTPError as e:
self.config.logger.error("error updating dashboard list items: %s", e)
return
dashboards = await destination_client.put(self.dash_list_items_path.format(_id), payload)
dashboard_list.update(dashboards)
102 changes: 102 additions & 0 deletions datadog_sync/model/rum_applications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# 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

if TYPE_CHECKING:
from datadog_sync.utils.custom_client import CustomClient


class RUMApplications(BaseResource):
resource_type = "rum_applications"
resource_config = ResourceConfig(
base_path="/api/v2/rum/applications",
excluded_attributes=[
"id",
"attributes.api_key_id",
"attributes.application_id",
"attributes.client_token",
"attributes.created_at",
"attributes.created_by_handle",
"attributes.hash",
"attributes.is_active",
"attributes.ootb_metrics_installed",
"attributes.org_id",
"attributes.updated_at",
"attributes.updated_by_handle",
"attributes.product_scales.product_analytics_retention_scale.last_modified_at",
"attributes.product_scales.product_analytics_retention_scale.state",
"attributes.product_scales.rum_event_processing_scale.last_modified_at",
"attributes.remote_config_id",
"attributes.short_name",
],
)
# Additional RUM Applications specific attributes

async def get_resources(self, client: CustomClient) -> List[Dict]:
resp = await client.get(self.resource_config.base_path)

# the list endpoint doesn't return the whole resource, so pull them individually
resources = []
for partial_resource in resp["data"]:
partial_resource_id = partial_resource["id"]
whole_resource = (await client.get(self.resource_config.base_path + f"/{partial_resource_id}"))["data"]
resources.append(whole_resource)

return resources

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]:
destination_client = self.config.destination_client
resource["type"] = "rum_application_create"
payload = {"data": resource}
post_resp = await destination_client.post(self.resource_config.base_path, payload)
return _id, post_resp["data"]

async def update_resource(self, _id: str, resource: Dict) -> Tuple[str, Dict]:
destination_client = self.config.destination_client
destination_id = self.config.state.destination[self.resource_type][_id]["id"]

# if the resource doesn't exist at the destination then create it
existing_resources = await self.get_resources(destination_client)
existing_resource_ids = [r["id"] for r in existing_resources]
if destination_id not in existing_resource_ids:
self.config.logger.debug(f"{destination_id} not found, creating it")
return await self.create_resource(_id, resource)

# resource exists so we can update it
resource["type"] = "rum_application_update"
resource["id"] = destination_id
payload = {"data": resource}
resp = await destination_client.patch(
self.resource_config.base_path + "/" + destination_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']}"
)

def connect_id(self, key: str, r_obj: Dict, resource_to_connect: str) -> Optional[List[str]]:
pass
6 changes: 6 additions & 0 deletions datadog_sync/model/spans_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class SpansMetrics(BaseResource):
resource_type = "spans_metrics"
resource_config = ResourceConfig(
base_path="/api/v2/apm/config/metrics",
non_nullable_list_vals=[
(
"attributes.group_by",
{"path": "resource_hash", "tag_name": "resource"},
),
],
)
# Additional SpansMetrics specific attributes

Expand Down
3 changes: 3 additions & 0 deletions datadog_sync/model/synthetics_global_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ async def create_resource(self, _id: str, resource: Dict) -> Tuple[str, Dict]:
if "value" not in resource["value"]:
resource["value"]["value"] = "SECRET"

if "is_fido" in resource and resource["is_fido"]:
resource.pop("value")

resp = await destination_client.post(self.resource_config.base_path, resource)

return _id, resp
Expand Down
80 changes: 80 additions & 0 deletions datadog_sync/model/synthetics_mobile_applications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# 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

if TYPE_CHECKING:
from datadog_sync.utils.custom_client import CustomClient


class SyntheticsMobileApplications(BaseResource):
resource_type = "synthetics_mobile_applications"
resource_config = ResourceConfig(
base_path="/api/unstable/synthetics/mobile/applications",
resource_connections={
"synthetics_mobile_applications_versions": ["versions.id"],
},
excluded_attributes=[
"id",
"created_at",
"versions",
],
non_nullable_attr=[
"framework",
],
null_values={
"framework": [""],
},
)
# Additional Synthetics Mobile Applications specific attributes

async def get_resources(self, client: CustomClient) -> List[Dict]:
resp = await client.get(self.resource_config.base_path)
return resp["applications"]

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}")

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]:
destination_client = self.config.destination_client
resource.pop("versions", None)
resp = await destination_client.post(self.resource_config.base_path, resource)
return _id, resp

async def update_resource(self, _id: str, resource: Dict) -> Tuple[str, Dict]:
destination_client = self.config.destination_client
destination_id = self.config.state.destination[self.resource_type][_id]["id"]

# resource exists so we can update it
resource["id"] = destination_id
payload = {"data": resource}
resp = await destination_client.put(
self.resource_config.base_path + "/" + destination_id,
payload,
)
return _id, resp

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']}"
)

def connect_id(self, key: str, r_obj: Dict, resource_to_connect: str) -> Optional[List[str]]:
pass
Loading
Loading