Skip to content

Commit df35f8c

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add apm_metrics query support to dashboard OpenAPI spec (#1370)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 8db05dc commit df35f8c

11 files changed

Lines changed: 801 additions & 0 deletions

.generator/schemas/v1/openapi.yaml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,123 @@ components:
27092709
- service
27102710
- name
27112711
type: object
2712+
FormulaAndFunctionApmMetricStatName:
2713+
description: APM metric stat name.
2714+
enum:
2715+
- errors
2716+
- error_rate
2717+
- errors_per_second
2718+
- latency_avg
2719+
- latency_max
2720+
- latency_p50
2721+
- latency_p75
2722+
- latency_p90
2723+
- latency_p95
2724+
- latency_p99
2725+
- latency_p999
2726+
- latency_distribution
2727+
- hits
2728+
- hits_per_second
2729+
- total_time
2730+
- apdex
2731+
example: "hits"
2732+
type: string
2733+
x-enum-varnames:
2734+
- ERRORS
2735+
- ERROR_RATE
2736+
- ERRORS_PER_SECOND
2737+
- LATENCY_AVG
2738+
- LATENCY_MAX
2739+
- LATENCY_P50
2740+
- LATENCY_P75
2741+
- LATENCY_P90
2742+
- LATENCY_P95
2743+
- LATENCY_P99
2744+
- LATENCY_P999
2745+
- LATENCY_DISTRIBUTION
2746+
- HITS
2747+
- HITS_PER_SECOND
2748+
- TOTAL_TIME
2749+
- APDEX
2750+
FormulaAndFunctionApmMetricsDataSource:
2751+
description: Data source for APM metrics queries.
2752+
enum:
2753+
- apm_metrics
2754+
example: apm_metrics
2755+
type: string
2756+
x-enum-varnames:
2757+
- APM_METRICS
2758+
FormulaAndFunctionApmMetricsQueryDefinition:
2759+
description: A formula and functions APM metrics query.
2760+
properties:
2761+
data_source:
2762+
$ref: "#/components/schemas/FormulaAndFunctionApmMetricsDataSource"
2763+
group_by:
2764+
description: Optional fields to group the query results by.
2765+
items:
2766+
description: A field to group results by.
2767+
example: "resource_name"
2768+
type: string
2769+
type: array
2770+
name:
2771+
description: Name of this query to use in formulas.
2772+
example: "query_errors"
2773+
type: string
2774+
operation_mode:
2775+
description: Optional operation mode to aggregate across operation names.
2776+
example: "primary"
2777+
type: string
2778+
operation_name:
2779+
description: Name of operation on service. If not provided, the primary operation name is used.
2780+
example: "web.request"
2781+
type: string
2782+
peer_tags:
2783+
description: Tags to query for a specific downstream entity (peer.service, peer.db_instance, peer.s3, peer.s3.bucket, etc.).
2784+
items:
2785+
example: "peer.service:my-service"
2786+
type: string
2787+
type: array
2788+
query_filter:
2789+
description: Additional filters for the query using metrics query syntax (e.g., env, primary_tag).
2790+
example: "env:prod"
2791+
type: string
2792+
resource_hash:
2793+
description: The hash of a specific resource to filter by.
2794+
example: "abc123"
2795+
type: string
2796+
resource_name:
2797+
description: The full name of a specific resource to filter by.
2798+
example: "GET /api/v1/users"
2799+
type: string
2800+
service:
2801+
description: APM service name.
2802+
example: "web-store"
2803+
type: string
2804+
span_kind:
2805+
$ref: "#/components/schemas/FormulaAndFunctionApmMetricsSpanKind"
2806+
stat:
2807+
$ref: "#/components/schemas/FormulaAndFunctionApmMetricStatName"
2808+
required:
2809+
- data_source
2810+
- name
2811+
- stat
2812+
type: object
2813+
FormulaAndFunctionApmMetricsSpanKind:
2814+
description: Describes the relationship between the span, its parents, and its children in a trace.
2815+
enum:
2816+
- consumer
2817+
- server
2818+
- client
2819+
- producer
2820+
- internal
2821+
example: "server"
2822+
type: string
2823+
x-enum-varnames:
2824+
- CONSUMER
2825+
- SERVER
2826+
- CLIENT
2827+
- PRODUCER
2828+
- INTERNAL
27122829
FormulaAndFunctionApmResourceStatName:
27132830
description: APM resource stat name.
27142831
enum:
@@ -3138,6 +3255,7 @@ components:
31383255
- $ref: "#/components/schemas/FormulaAndFunctionProcessQueryDefinition"
31393256
- $ref: "#/components/schemas/FormulaAndFunctionApmDependencyStatsQueryDefinition"
31403257
- $ref: "#/components/schemas/FormulaAndFunctionApmResourceStatsQueryDefinition"
3258+
- $ref: "#/components/schemas/FormulaAndFunctionApmMetricsQueryDefinition"
31413259
- $ref: "#/components/schemas/FormulaAndFunctionSLOQueryDefinition"
31423260
- $ref: "#/components/schemas/FormulaAndFunctionCloudCostQueryDefinition"
31433261
FormulaAndFunctionResponseFormat:
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Create a new dashboard with apm metrics widget
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV1::api_dashboards::DashboardsAPI;
4+
use datadog_api_client::datadogV1::model::Dashboard;
5+
use datadog_api_client::datadogV1::model::DashboardLayoutType;
6+
use datadog_api_client::datadogV1::model::FormulaAndFunctionApmMetricStatName;
7+
use datadog_api_client::datadogV1::model::FormulaAndFunctionApmMetricsDataSource;
8+
use datadog_api_client::datadogV1::model::FormulaAndFunctionApmMetricsQueryDefinition;
9+
use datadog_api_client::datadogV1::model::FormulaAndFunctionQueryDefinition;
10+
use datadog_api_client::datadogV1::model::FormulaAndFunctionResponseFormat;
11+
use datadog_api_client::datadogV1::model::TableWidgetDefinition;
12+
use datadog_api_client::datadogV1::model::TableWidgetDefinitionType;
13+
use datadog_api_client::datadogV1::model::TableWidgetRequest;
14+
use datadog_api_client::datadogV1::model::Widget;
15+
use datadog_api_client::datadogV1::model::WidgetDefinition;
16+
use datadog_api_client::datadogV1::model::WidgetLayout;
17+
use datadog_api_client::datadogV1::model::WidgetTextAlign;
18+
19+
#[tokio::main]
20+
async fn main() {
21+
let body =
22+
Dashboard::new(
23+
DashboardLayoutType::ORDERED,
24+
"Example-Dashboard".to_string(),
25+
vec![
26+
Widget::new(
27+
WidgetDefinition::TableWidgetDefinition(
28+
Box::new(
29+
TableWidgetDefinition::new(
30+
vec![
31+
TableWidgetRequest::new()
32+
.queries(
33+
vec![
34+
FormulaAndFunctionQueryDefinition
35+
::FormulaAndFunctionApmMetricsQueryDefinition(
36+
Box::new(
37+
FormulaAndFunctionApmMetricsQueryDefinition::new(
38+
FormulaAndFunctionApmMetricsDataSource::APM_METRICS,
39+
"query1".to_string(),
40+
FormulaAndFunctionApmMetricStatName::HITS,
41+
)
42+
.group_by(vec!["resource_name".to_string()])
43+
.query_filter("env:prod".to_string())
44+
.service("web-store".to_string()),
45+
),
46+
)
47+
],
48+
)
49+
.response_format(FormulaAndFunctionResponseFormat::SCALAR)
50+
],
51+
TableWidgetDefinitionType::QUERY_TABLE,
52+
)
53+
.title("".to_string())
54+
.title_align(WidgetTextAlign::LEFT)
55+
.title_size("16".to_string()),
56+
),
57+
),
58+
).layout(WidgetLayout::new(4, 4, 0, 0))
59+
],
60+
);
61+
let configuration = datadog::Configuration::new();
62+
let api = DashboardsAPI::with_config(configuration);
63+
let resp = api.create_dashboard(body).await;
64+
if let Ok(value) = resp {
65+
println!("{:#?}", value);
66+
} else {
67+
println!("{:#?}", resp.unwrap_err());
68+
}
69+
}

src/datadogV1/model/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ pub mod model_formula_and_function_apm_resource_stats_data_source;
226226
pub use self::model_formula_and_function_apm_resource_stats_data_source::FormulaAndFunctionApmResourceStatsDataSource;
227227
pub mod model_formula_and_function_apm_resource_stat_name;
228228
pub use self::model_formula_and_function_apm_resource_stat_name::FormulaAndFunctionApmResourceStatName;
229+
pub mod model_formula_and_function_apm_metrics_query_definition;
230+
pub use self::model_formula_and_function_apm_metrics_query_definition::FormulaAndFunctionApmMetricsQueryDefinition;
231+
pub mod model_formula_and_function_apm_metrics_data_source;
232+
pub use self::model_formula_and_function_apm_metrics_data_source::FormulaAndFunctionApmMetricsDataSource;
233+
pub mod model_formula_and_function_apm_metrics_span_kind;
234+
pub use self::model_formula_and_function_apm_metrics_span_kind::FormulaAndFunctionApmMetricsSpanKind;
235+
pub mod model_formula_and_function_apm_metric_stat_name;
236+
pub use self::model_formula_and_function_apm_metric_stat_name::FormulaAndFunctionApmMetricStatName;
229237
pub mod model_formula_and_function_slo_query_definition;
230238
pub use self::model_formula_and_function_slo_query_definition::FormulaAndFunctionSLOQueryDefinition;
231239
pub mod model_formula_and_function_slo_data_source;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
5+
use serde::{Deserialize, Deserializer, Serialize, Serializer};
6+
7+
#[non_exhaustive]
8+
#[derive(Clone, Debug, Eq, PartialEq)]
9+
pub enum FormulaAndFunctionApmMetricStatName {
10+
ERRORS,
11+
ERROR_RATE,
12+
ERRORS_PER_SECOND,
13+
LATENCY_AVG,
14+
LATENCY_MAX,
15+
LATENCY_P50,
16+
LATENCY_P75,
17+
LATENCY_P90,
18+
LATENCY_P95,
19+
LATENCY_P99,
20+
LATENCY_P999,
21+
LATENCY_DISTRIBUTION,
22+
HITS,
23+
HITS_PER_SECOND,
24+
TOTAL_TIME,
25+
APDEX,
26+
UnparsedObject(crate::datadog::UnparsedObject),
27+
}
28+
29+
impl ToString for FormulaAndFunctionApmMetricStatName {
30+
fn to_string(&self) -> String {
31+
match self {
32+
Self::ERRORS => String::from("errors"),
33+
Self::ERROR_RATE => String::from("error_rate"),
34+
Self::ERRORS_PER_SECOND => String::from("errors_per_second"),
35+
Self::LATENCY_AVG => String::from("latency_avg"),
36+
Self::LATENCY_MAX => String::from("latency_max"),
37+
Self::LATENCY_P50 => String::from("latency_p50"),
38+
Self::LATENCY_P75 => String::from("latency_p75"),
39+
Self::LATENCY_P90 => String::from("latency_p90"),
40+
Self::LATENCY_P95 => String::from("latency_p95"),
41+
Self::LATENCY_P99 => String::from("latency_p99"),
42+
Self::LATENCY_P999 => String::from("latency_p999"),
43+
Self::LATENCY_DISTRIBUTION => String::from("latency_distribution"),
44+
Self::HITS => String::from("hits"),
45+
Self::HITS_PER_SECOND => String::from("hits_per_second"),
46+
Self::TOTAL_TIME => String::from("total_time"),
47+
Self::APDEX => String::from("apdex"),
48+
Self::UnparsedObject(v) => v.value.to_string(),
49+
}
50+
}
51+
}
52+
53+
impl Serialize for FormulaAndFunctionApmMetricStatName {
54+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
55+
where
56+
S: Serializer,
57+
{
58+
match self {
59+
Self::UnparsedObject(v) => v.serialize(serializer),
60+
_ => serializer.serialize_str(self.to_string().as_str()),
61+
}
62+
}
63+
}
64+
65+
impl<'de> Deserialize<'de> for FormulaAndFunctionApmMetricStatName {
66+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
67+
where
68+
D: Deserializer<'de>,
69+
{
70+
let s: String = String::deserialize(deserializer)?;
71+
Ok(match s.as_str() {
72+
"errors" => Self::ERRORS,
73+
"error_rate" => Self::ERROR_RATE,
74+
"errors_per_second" => Self::ERRORS_PER_SECOND,
75+
"latency_avg" => Self::LATENCY_AVG,
76+
"latency_max" => Self::LATENCY_MAX,
77+
"latency_p50" => Self::LATENCY_P50,
78+
"latency_p75" => Self::LATENCY_P75,
79+
"latency_p90" => Self::LATENCY_P90,
80+
"latency_p95" => Self::LATENCY_P95,
81+
"latency_p99" => Self::LATENCY_P99,
82+
"latency_p999" => Self::LATENCY_P999,
83+
"latency_distribution" => Self::LATENCY_DISTRIBUTION,
84+
"hits" => Self::HITS,
85+
"hits_per_second" => Self::HITS_PER_SECOND,
86+
"total_time" => Self::TOTAL_TIME,
87+
"apdex" => Self::APDEX,
88+
_ => Self::UnparsedObject(crate::datadog::UnparsedObject {
89+
value: serde_json::Value::String(s.into()),
90+
}),
91+
})
92+
}
93+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
5+
use serde::{Deserialize, Deserializer, Serialize, Serializer};
6+
7+
#[non_exhaustive]
8+
#[derive(Clone, Debug, Eq, PartialEq)]
9+
pub enum FormulaAndFunctionApmMetricsDataSource {
10+
APM_METRICS,
11+
UnparsedObject(crate::datadog::UnparsedObject),
12+
}
13+
14+
impl ToString for FormulaAndFunctionApmMetricsDataSource {
15+
fn to_string(&self) -> String {
16+
match self {
17+
Self::APM_METRICS => String::from("apm_metrics"),
18+
Self::UnparsedObject(v) => v.value.to_string(),
19+
}
20+
}
21+
}
22+
23+
impl Serialize for FormulaAndFunctionApmMetricsDataSource {
24+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
25+
where
26+
S: Serializer,
27+
{
28+
match self {
29+
Self::UnparsedObject(v) => v.serialize(serializer),
30+
_ => serializer.serialize_str(self.to_string().as_str()),
31+
}
32+
}
33+
}
34+
35+
impl<'de> Deserialize<'de> for FormulaAndFunctionApmMetricsDataSource {
36+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
37+
where
38+
D: Deserializer<'de>,
39+
{
40+
let s: String = String::deserialize(deserializer)?;
41+
Ok(match s.as_str() {
42+
"apm_metrics" => Self::APM_METRICS,
43+
_ => Self::UnparsedObject(crate::datadog::UnparsedObject {
44+
value: serde_json::Value::String(s.into()),
45+
}),
46+
})
47+
}
48+
}

0 commit comments

Comments
 (0)