Skip to content

Commit 3f94d0a

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add metric namespace config filters to V2 GCP API (#979)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 25b414a commit 3f94d0a

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

.generator/schemas/v2/openapi.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20582,9 +20582,20 @@ components:
2058220582
to this GCP metric namespace.
2058320583
example: true
2058420584
type: boolean
20585+
filters:
20586+
description: When enabled, Datadog applies these additional filters to limit
20587+
metric collection. A metric is collected only if it does not match all
20588+
exclusion filters and matches at least one allow filter.
20589+
example:
20590+
- snapshot.*
20591+
- '!*_by_region'
20592+
items:
20593+
description: A metric namespace filter
20594+
type: string
20595+
type: array
2058520596
id:
2058620597
description: The id of the GCP metric namespace.
20587-
example: aiplatform
20598+
example: pubsub
2058820599
type: string
2058920600
type: object
2059020601
GCPMonitoredResourceConfig:
@@ -20746,6 +20757,10 @@ components:
2074620757
example:
2074720758
- disabled: true
2074820759
id: aiplatform
20760+
- filters:
20761+
- snapshot.*
20762+
- '!*_by_region'
20763+
id: pubsub
2074920764
items:
2075020765
$ref: '#/components/schemas/GCPMetricNamespaceConfig'
2075120766
type: array

src/datadogV2/model/model_gcp_metric_namespace_config.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pub struct GCPMetricNamespaceConfig {
1414
/// When disabled, Datadog does not collect metrics that are related to this GCP metric namespace.
1515
#[serde(rename = "disabled")]
1616
pub disabled: Option<bool>,
17+
/// When enabled, Datadog applies these additional filters to limit metric collection. A metric is collected only if it does not match all exclusion filters and matches at least one allow filter.
18+
#[serde(rename = "filters")]
19+
pub filters: Option<Vec<String>>,
1720
/// The id of the GCP metric namespace.
1821
#[serde(rename = "id")]
1922
pub id: Option<String>,
@@ -28,6 +31,7 @@ impl GCPMetricNamespaceConfig {
2831
pub fn new() -> GCPMetricNamespaceConfig {
2932
GCPMetricNamespaceConfig {
3033
disabled: None,
34+
filters: None,
3135
id: None,
3236
additional_properties: std::collections::BTreeMap::new(),
3337
_unparsed: false,
@@ -39,6 +43,11 @@ impl GCPMetricNamespaceConfig {
3943
self
4044
}
4145

46+
pub fn filters(mut self, value: Vec<String>) -> Self {
47+
self.filters = Some(value);
48+
self
49+
}
50+
4251
pub fn id(mut self, value: String) -> Self {
4352
self.id = Some(value);
4453
self
@@ -77,6 +86,7 @@ impl<'de> Deserialize<'de> for GCPMetricNamespaceConfig {
7786
M: MapAccess<'a>,
7887
{
7988
let mut disabled: Option<bool> = None;
89+
let mut filters: Option<Vec<String>> = None;
8090
let mut id: Option<String> = None;
8191
let mut additional_properties: std::collections::BTreeMap<
8292
String,
@@ -92,6 +102,12 @@ impl<'de> Deserialize<'de> for GCPMetricNamespaceConfig {
92102
}
93103
disabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
94104
}
105+
"filters" => {
106+
if v.is_null() {
107+
continue;
108+
}
109+
filters = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
110+
}
95111
"id" => {
96112
if v.is_null() {
97113
continue;
@@ -108,6 +124,7 @@ impl<'de> Deserialize<'de> for GCPMetricNamespaceConfig {
108124

109125
let content = GCPMetricNamespaceConfig {
110126
disabled,
127+
filters,
111128
id,
112129
additional_properties,
113130
_unparsed,

tests/scenarios/features/v2/gcp_integration.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ Feature: GCP Integration
3434
@generated @skip @team:DataDog/gcp-integrations
3535
Scenario: Create a new entry for your service account returns "Bad Request" response
3636
Given new "CreateGCPSTSAccount" request
37-
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "datadog-service-account@test-project.iam.gserviceaccount.com", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": ["$KEY:$VALUE"], "is_per_project_quota_enabled": true, "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true, "metric_namespace_configs": [{"disabled": true, "id": "aiplatform"}], "monitored_resource_configs": [{"filters": ["$KEY:$VALUE"], "type": "gce_instance"}]}, "type": "gcp_service_account"}}
37+
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "datadog-service-account@test-project.iam.gserviceaccount.com", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": ["$KEY:$VALUE"], "is_per_project_quota_enabled": true, "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true, "metric_namespace_configs": [{"disabled": true, "id": "aiplatform"}, {"filters": ["snapshot.*", "!*_by_region"], "id": "pubsub"}], "monitored_resource_configs": [{"filters": ["$KEY:$VALUE"], "type": "gce_instance"}]}, "type": "gcp_service_account"}}
3838
When the request is sent
3939
Then the response status is 400 Bad Request
4040

4141
@generated @skip @team:DataDog/gcp-integrations
4242
Scenario: Create a new entry for your service account returns "Conflict" response
4343
Given new "CreateGCPSTSAccount" request
44-
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "datadog-service-account@test-project.iam.gserviceaccount.com", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": ["$KEY:$VALUE"], "is_per_project_quota_enabled": true, "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true, "metric_namespace_configs": [{"disabled": true, "id": "aiplatform"}], "monitored_resource_configs": [{"filters": ["$KEY:$VALUE"], "type": "gce_instance"}]}, "type": "gcp_service_account"}}
44+
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "datadog-service-account@test-project.iam.gserviceaccount.com", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": ["$KEY:$VALUE"], "is_per_project_quota_enabled": true, "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true, "metric_namespace_configs": [{"disabled": true, "id": "aiplatform"}, {"filters": ["snapshot.*", "!*_by_region"], "id": "pubsub"}], "monitored_resource_configs": [{"filters": ["$KEY:$VALUE"], "type": "gce_instance"}]}, "type": "gcp_service_account"}}
4545
When the request is sent
4646
Then the response status is 409 Conflict
4747

@@ -151,15 +151,15 @@ Feature: GCP Integration
151151
Scenario: Update STS Service Account returns "Bad Request" response
152152
Given new "UpdateGCPSTSAccount" request
153153
And request contains "account_id" parameter from "REPLACE.ME"
154-
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "datadog-service-account@test-project.iam.gserviceaccount.com", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": ["$KEY:$VALUE"], "is_per_project_quota_enabled": true, "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true, "metric_namespace_configs": [{"disabled": true, "id": "aiplatform"}], "monitored_resource_configs": [{"filters": ["$KEY:$VALUE"], "type": "gce_instance"}]}, "id": "d291291f-12c2-22g4-j290-123456678897", "type": "gcp_service_account"}}
154+
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "datadog-service-account@test-project.iam.gserviceaccount.com", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": ["$KEY:$VALUE"], "is_per_project_quota_enabled": true, "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true, "metric_namespace_configs": [{"disabled": true, "id": "aiplatform"}, {"filters": ["snapshot.*", "!*_by_region"], "id": "pubsub"}], "monitored_resource_configs": [{"filters": ["$KEY:$VALUE"], "type": "gce_instance"}]}, "id": "d291291f-12c2-22g4-j290-123456678897", "type": "gcp_service_account"}}
155155
When the request is sent
156156
Then the response status is 400 Bad Request
157157

158158
@generated @skip @team:DataDog/gcp-integrations
159159
Scenario: Update STS Service Account returns "Not Found" response
160160
Given new "UpdateGCPSTSAccount" request
161161
And request contains "account_id" parameter from "REPLACE.ME"
162-
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "datadog-service-account@test-project.iam.gserviceaccount.com", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": ["$KEY:$VALUE"], "is_per_project_quota_enabled": true, "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true, "metric_namespace_configs": [{"disabled": true, "id": "aiplatform"}], "monitored_resource_configs": [{"filters": ["$KEY:$VALUE"], "type": "gce_instance"}]}, "id": "d291291f-12c2-22g4-j290-123456678897", "type": "gcp_service_account"}}
162+
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "datadog-service-account@test-project.iam.gserviceaccount.com", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": ["$KEY:$VALUE"], "is_per_project_quota_enabled": true, "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true, "metric_namespace_configs": [{"disabled": true, "id": "aiplatform"}, {"filters": ["snapshot.*", "!*_by_region"], "id": "pubsub"}], "monitored_resource_configs": [{"filters": ["$KEY:$VALUE"], "type": "gce_instance"}]}, "id": "d291291f-12c2-22g4-j290-123456678897", "type": "gcp_service_account"}}
163163
When the request is sent
164164
Then the response status is 404 Not Found
165165

0 commit comments

Comments
 (0)