Skip to content

Commit 57e31eb

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add Get Tag Cardinalities Endpoint Spec (#737)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent d9e12f1 commit 57e31eb

12 files changed

+791
-2
lines changed

.generated-info

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"spec_repo_commit": "20279f4",
3-
"generated": "2025-07-18 10:27:51.182"
2+
"spec_repo_commit": "dc49df4",
3+
"generated": "2025-07-18 14:02:24.862"
44
}

.generator/schemas/v2/openapi.yaml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23189,6 +23189,61 @@ components:
2318923189
type: string
2319023190
type: array
2319123191
type: object
23192+
MetricTagCardinalitiesData:
23193+
description: A list of tag cardinalities associated with the given metric.
23194+
items:
23195+
$ref: '#/components/schemas/MetricTagCardinality'
23196+
type: array
23197+
MetricTagCardinalitiesMeta:
23198+
description: Response metadata object.
23199+
properties:
23200+
metric_name:
23201+
description: 'The name of metric for which the tag cardinalities are returned.
23202+
23203+
This matches the metric name provided in the request.
23204+
23205+
'
23206+
type: string
23207+
type: object
23208+
MetricTagCardinalitiesResponse:
23209+
description: 'Response object that includes an array of objects representing
23210+
the cardinality details of a metric''s tags.
23211+
23212+
'
23213+
properties:
23214+
data:
23215+
$ref: '#/components/schemas/MetricTagCardinalitiesData'
23216+
meta:
23217+
$ref: '#/components/schemas/MetricTagCardinalitiesMeta'
23218+
readOnly: true
23219+
type: object
23220+
MetricTagCardinality:
23221+
description: Object containing metadata and attributes related to a specific
23222+
tag key associated with the metric.
23223+
example:
23224+
attributes:
23225+
cardinality_delta: 25
23226+
id: http.request.latency
23227+
type: tag_cardinality
23228+
properties:
23229+
attributes:
23230+
$ref: '#/components/schemas/MetricTagCardinalityAttributes'
23231+
id:
23232+
description: The name of the tag key.
23233+
type: string
23234+
type:
23235+
default: tag_cardinality
23236+
description: This describes the endpoint action.
23237+
type: string
23238+
type: object
23239+
MetricTagCardinalityAttributes:
23240+
description: An object containing properties related to the tag key
23241+
properties:
23242+
cardinality_delta:
23243+
description: This describes the recent change in the tag keys cardinality
23244+
format: int64
23245+
type: integer
23246+
type: object
2319223247
MetricTagConfiguration:
2319323248
description: Object for a single metric tag configuration.
2319423249
example:
@@ -53610,6 +53665,50 @@ paths:
5361053665
x-permission:
5361153666
operator: OPEN
5361253667
permissions: []
53668+
/api/v2/metrics/{metric_name}/tag-cardinalities:
53669+
get:
53670+
description: Returns the cardinality details of tags for a specific metric.
53671+
operationId: GetMetricTagCardinalityDetails
53672+
parameters:
53673+
- $ref: '#/components/parameters/MetricName'
53674+
responses:
53675+
'200':
53676+
content:
53677+
application/json:
53678+
schema:
53679+
$ref: '#/components/schemas/MetricTagCardinalitiesResponse'
53680+
description: Success
53681+
'400':
53682+
content:
53683+
application/json:
53684+
schema:
53685+
$ref: '#/components/schemas/APIErrorResponse'
53686+
description: Bad Request
53687+
'403':
53688+
content:
53689+
application/json:
53690+
schema:
53691+
$ref: '#/components/schemas/APIErrorResponse'
53692+
description: Forbidden
53693+
'404':
53694+
content:
53695+
application/json:
53696+
schema:
53697+
$ref: '#/components/schemas/APIErrorResponse'
53698+
description: Not Found
53699+
'429':
53700+
content:
53701+
application/json:
53702+
schema:
53703+
$ref: '#/components/schemas/APIErrorResponse'
53704+
description: Too Many Requests
53705+
summary: Get tag key cardinality details
53706+
tags:
53707+
- Metrics
53708+
x-permission:
53709+
operator: OR
53710+
permissions:
53711+
- metrics_read
5361353712
/api/v2/metrics/{metric_name}/tags:
5361453713
delete:
5361553714
description: 'Deletes a metric''s tag configuration. Can only be used with application
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Get tag key cardinality details returns "Success" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV2::api_metrics::MetricsAPI;
4+
5+
#[tokio::main]
6+
async fn main() {
7+
let configuration = datadog::Configuration::new();
8+
let api = MetricsAPI::with_config(configuration);
9+
let resp = api
10+
.get_metric_tag_cardinality_details("metric_name".to_string())
11+
.await;
12+
if let Ok(value) = resp {
13+
println!("{:#?}", value);
14+
} else {
15+
println!("{:#?}", resp.unwrap_err());
16+
}
17+
}

src/datadogV2/api/api_metrics.rs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ pub enum EstimateMetricsOutputSeriesError {
228228
UnknownValue(serde_json::Value),
229229
}
230230

231+
/// GetMetricTagCardinalityDetailsError is a struct for typed errors of method [`MetricsAPI::get_metric_tag_cardinality_details`]
232+
#[derive(Debug, Clone, Serialize, Deserialize)]
233+
#[serde(untagged)]
234+
pub enum GetMetricTagCardinalityDetailsError {
235+
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
236+
UnknownValue(serde_json::Value),
237+
}
238+
231239
/// ListActiveMetricConfigurationsError is a struct for typed errors of method [`MetricsAPI::list_active_metric_configurations`]
232240
#[derive(Debug, Clone, Serialize, Deserialize)]
233241
#[serde(untagged)]
@@ -1122,6 +1130,118 @@ impl MetricsAPI {
11221130
}
11231131
}
11241132

1133+
/// Returns the cardinality details of tags for a specific metric.
1134+
pub async fn get_metric_tag_cardinality_details(
1135+
&self,
1136+
metric_name: String,
1137+
) -> Result<
1138+
crate::datadogV2::model::MetricTagCardinalitiesResponse,
1139+
datadog::Error<GetMetricTagCardinalityDetailsError>,
1140+
> {
1141+
match self
1142+
.get_metric_tag_cardinality_details_with_http_info(metric_name)
1143+
.await
1144+
{
1145+
Ok(response_content) => {
1146+
if let Some(e) = response_content.entity {
1147+
Ok(e)
1148+
} else {
1149+
Err(datadog::Error::Serde(serde::de::Error::custom(
1150+
"response content was None",
1151+
)))
1152+
}
1153+
}
1154+
Err(err) => Err(err),
1155+
}
1156+
}
1157+
1158+
/// Returns the cardinality details of tags for a specific metric.
1159+
pub async fn get_metric_tag_cardinality_details_with_http_info(
1160+
&self,
1161+
metric_name: String,
1162+
) -> Result<
1163+
datadog::ResponseContent<crate::datadogV2::model::MetricTagCardinalitiesResponse>,
1164+
datadog::Error<GetMetricTagCardinalityDetailsError>,
1165+
> {
1166+
let local_configuration = &self.config;
1167+
let operation_id = "v2.get_metric_tag_cardinality_details";
1168+
1169+
let local_client = &self.client;
1170+
1171+
let local_uri_str = format!(
1172+
"{}/api/v2/metrics/{metric_name}/tag-cardinalities",
1173+
local_configuration.get_operation_host(operation_id),
1174+
metric_name = datadog::urlencode(metric_name)
1175+
);
1176+
let mut local_req_builder =
1177+
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1178+
1179+
// build headers
1180+
let mut headers = HeaderMap::new();
1181+
headers.insert("Accept", HeaderValue::from_static("application/json"));
1182+
1183+
// build user agent
1184+
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1185+
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1186+
Err(e) => {
1187+
log::warn!("Failed to parse user agent header: {e}, falling back to default");
1188+
headers.insert(
1189+
reqwest::header::USER_AGENT,
1190+
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1191+
)
1192+
}
1193+
};
1194+
1195+
// build auth
1196+
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1197+
headers.insert(
1198+
"DD-API-KEY",
1199+
HeaderValue::from_str(local_key.key.as_str())
1200+
.expect("failed to parse DD-API-KEY header"),
1201+
);
1202+
};
1203+
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1204+
headers.insert(
1205+
"DD-APPLICATION-KEY",
1206+
HeaderValue::from_str(local_key.key.as_str())
1207+
.expect("failed to parse DD-APPLICATION-KEY header"),
1208+
);
1209+
};
1210+
1211+
local_req_builder = local_req_builder.headers(headers);
1212+
let local_req = local_req_builder.build()?;
1213+
log::debug!("request content: {:?}", local_req.body());
1214+
let local_resp = local_client.execute(local_req).await?;
1215+
1216+
let local_status = local_resp.status();
1217+
let local_content = local_resp.text().await?;
1218+
log::debug!("response content: {}", local_content);
1219+
1220+
if !local_status.is_client_error() && !local_status.is_server_error() {
1221+
match serde_json::from_str::<crate::datadogV2::model::MetricTagCardinalitiesResponse>(
1222+
&local_content,
1223+
) {
1224+
Ok(e) => {
1225+
return Ok(datadog::ResponseContent {
1226+
status: local_status,
1227+
content: local_content,
1228+
entity: Some(e),
1229+
})
1230+
}
1231+
Err(e) => return Err(datadog::Error::Serde(e)),
1232+
};
1233+
} else {
1234+
let local_entity: Option<GetMetricTagCardinalityDetailsError> =
1235+
serde_json::from_str(&local_content).ok();
1236+
let local_error = datadog::ResponseContent {
1237+
status: local_status,
1238+
content: local_content,
1239+
entity: local_entity,
1240+
};
1241+
Err(datadog::Error::ResponseError(local_error))
1242+
}
1243+
}
1244+
11251245
/// List tags and aggregations that are actively queried on dashboards, notebooks, monitors, the Metrics Explorer, and using the API for a given metric name.
11261246
pub async fn list_active_metric_configurations(
11271247
&self,

src/datadogV2/model/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,6 +2596,14 @@ pub mod model_metric_estimate_type;
25962596
pub use self::model_metric_estimate_type::MetricEstimateType;
25972597
pub mod model_metric_estimate_resource_type;
25982598
pub use self::model_metric_estimate_resource_type::MetricEstimateResourceType;
2599+
pub mod model_metric_tag_cardinalities_response;
2600+
pub use self::model_metric_tag_cardinalities_response::MetricTagCardinalitiesResponse;
2601+
pub mod model_metric_tag_cardinality;
2602+
pub use self::model_metric_tag_cardinality::MetricTagCardinality;
2603+
pub mod model_metric_tag_cardinality_attributes;
2604+
pub use self::model_metric_tag_cardinality_attributes::MetricTagCardinalityAttributes;
2605+
pub mod model_metric_tag_cardinalities_meta;
2606+
pub use self::model_metric_tag_cardinalities_meta::MetricTagCardinalitiesMeta;
25992607
pub mod model_metric_tag_configuration_response;
26002608
pub use self::model_metric_tag_configuration_response::MetricTagConfigurationResponse;
26012609
pub mod model_metric_tag_configuration_update_request;
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
use serde::de::{Error, MapAccess, Visitor};
5+
use serde::{Deserialize, Deserializer, Serialize};
6+
use serde_with::skip_serializing_none;
7+
use std::fmt::{self, Formatter};
8+
9+
/// Response metadata object.
10+
#[non_exhaustive]
11+
#[skip_serializing_none]
12+
#[derive(Clone, Debug, PartialEq, Serialize)]
13+
pub struct MetricTagCardinalitiesMeta {
14+
/// The name of metric for which the tag cardinalities are returned.
15+
/// This matches the metric name provided in the request.
16+
///
17+
#[serde(rename = "metric_name")]
18+
pub metric_name: Option<String>,
19+
#[serde(flatten)]
20+
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
21+
#[serde(skip)]
22+
#[serde(default)]
23+
pub(crate) _unparsed: bool,
24+
}
25+
26+
impl MetricTagCardinalitiesMeta {
27+
pub fn new() -> MetricTagCardinalitiesMeta {
28+
MetricTagCardinalitiesMeta {
29+
metric_name: None,
30+
additional_properties: std::collections::BTreeMap::new(),
31+
_unparsed: false,
32+
}
33+
}
34+
35+
pub fn metric_name(mut self, value: String) -> Self {
36+
self.metric_name = Some(value);
37+
self
38+
}
39+
40+
pub fn additional_properties(
41+
mut self,
42+
value: std::collections::BTreeMap<String, serde_json::Value>,
43+
) -> Self {
44+
self.additional_properties = value;
45+
self
46+
}
47+
}
48+
49+
impl Default for MetricTagCardinalitiesMeta {
50+
fn default() -> Self {
51+
Self::new()
52+
}
53+
}
54+
55+
impl<'de> Deserialize<'de> for MetricTagCardinalitiesMeta {
56+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
57+
where
58+
D: Deserializer<'de>,
59+
{
60+
struct MetricTagCardinalitiesMetaVisitor;
61+
impl<'a> Visitor<'a> for MetricTagCardinalitiesMetaVisitor {
62+
type Value = MetricTagCardinalitiesMeta;
63+
64+
fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
65+
f.write_str("a mapping")
66+
}
67+
68+
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
69+
where
70+
M: MapAccess<'a>,
71+
{
72+
let mut metric_name: Option<String> = None;
73+
let mut additional_properties: std::collections::BTreeMap<
74+
String,
75+
serde_json::Value,
76+
> = std::collections::BTreeMap::new();
77+
let mut _unparsed = false;
78+
79+
while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
80+
match k.as_str() {
81+
"metric_name" => {
82+
if v.is_null() {
83+
continue;
84+
}
85+
metric_name =
86+
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
87+
}
88+
&_ => {
89+
if let Ok(value) = serde_json::from_value(v.clone()) {
90+
additional_properties.insert(k, value);
91+
}
92+
}
93+
}
94+
}
95+
96+
let content = MetricTagCardinalitiesMeta {
97+
metric_name,
98+
additional_properties,
99+
_unparsed,
100+
};
101+
102+
Ok(content)
103+
}
104+
}
105+
106+
deserializer.deserialize_any(MetricTagCardinalitiesMetaVisitor)
107+
}
108+
}

0 commit comments

Comments
 (0)