Skip to content

Commit 5d15d77

Browse files
api-clients-generation-pipeline[bot]skarimoci.datadog-api-spec
authored
add docs for pagination in /api/v2/metrics endpoint (#416)
Co-authored-by: Sherzod Karimov <[email protected]> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent bc86586 commit 5d15d77

15 files changed

+878
-6
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.6",
7-
"regenerated": "2024-12-11 20:35:39.203447",
8-
"spec_repo_commit": "7b62d196"
7+
"regenerated": "2024-12-12 13:29:27.994176",
8+
"spec_repo_commit": "f0c3c0f4"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2024-12-11 20:35:39.222879",
13-
"spec_repo_commit": "7b62d196"
12+
"regenerated": "2024-12-12 13:29:28.013354",
13+
"spec_repo_commit": "f0c3c0f4"
1414
}
1515
}
1616
}

.generator/schemas/v2/openapi.yaml

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16012,6 +16012,36 @@ components:
1601216012
- COUNT
1601316013
- RATE
1601416014
- GAUGE
16015+
MetricMetaPage:
16016+
description: Paging attributes. Only present if pagination query parameters
16017+
were provided.
16018+
properties:
16019+
cursor:
16020+
description: The cursor used to get the current results, if any.
16021+
nullable: true
16022+
type: string
16023+
limit:
16024+
description: Number of results returned
16025+
format: int32
16026+
maximum: 20000
16027+
minimum: 0
16028+
type: integer
16029+
next_cursor:
16030+
description: The cursor used to get the next results, if any.
16031+
nullable: true
16032+
type: string
16033+
type:
16034+
$ref: '#/components/schemas/MetricMetaPageType'
16035+
type: object
16036+
MetricMetaPageType:
16037+
default: cursor_limit
16038+
description: Type of metric pagination.
16039+
enum:
16040+
- cursor_limit
16041+
example: cursor_limit
16042+
type: string
16043+
x-enum-varnames:
16044+
- CURSOR_LIMIT
1601516045
MetricMetadata:
1601616046
description: Metadata for the metric.
1601716047
properties:
@@ -16094,6 +16124,12 @@ components:
1609416124
maximum: 1000
1609516125
type: integer
1609616126
type: object
16127+
MetricPaginationMeta:
16128+
description: Response metadata object.
16129+
properties:
16130+
pagination:
16131+
$ref: '#/components/schemas/MetricMetaPage'
16132+
type: object
1609716133
MetricPayload:
1609816134
description: The metrics' payload.
1609916135
properties:
@@ -16570,6 +16606,10 @@ components:
1657016606
items:
1657116607
$ref: '#/components/schemas/MetricsAndMetricTagConfigurations'
1657216608
type: array
16609+
links:
16610+
$ref: '#/components/schemas/MetricsListResponseLinks'
16611+
meta:
16612+
$ref: '#/components/schemas/MetricPaginationMeta'
1657316613
readOnly: true
1657416614
type: object
1657516615
MetricsDataSource:
@@ -16583,6 +16623,29 @@ components:
1658316623
x-enum-varnames:
1658416624
- METRICS
1658516625
- CLOUD_COST
16626+
MetricsListResponseLinks:
16627+
description: Pagination links. Only present if pagination query parameters were
16628+
provided.
16629+
properties:
16630+
first:
16631+
description: Link to the first page.
16632+
type: string
16633+
last:
16634+
description: Link to the last page.
16635+
nullable: true
16636+
type: string
16637+
next:
16638+
description: Link to the next page.
16639+
nullable: true
16640+
type: string
16641+
prev:
16642+
description: Link to previous page.
16643+
nullable: true
16644+
type: string
16645+
self:
16646+
description: Link to current page.
16647+
type: string
16648+
type: object
1658616649
MetricsScalarQuery:
1658716650
description: An individual scalar metrics query.
1658816651
properties:
@@ -35773,7 +35836,12 @@ paths:
3577335836
get:
3577435837
description: "Returns all metrics that can be configured in the Metrics Summary
3577535838
page or with Metrics without Limits\u2122 (matching additional filters if
35776-
specified)."
35839+
specified).\nOptionally, paginate by using the `page[cursor]` and/or `page[size]`
35840+
query parameters.\nTo fetch the first page, pass in a query parameter with
35841+
either a valid `page[size]` or an empty cursor like `page[cursor]=`. To fetch
35842+
the next page, pass in the `next_cursor` value from the response as the new
35843+
`page[cursor]` value.\nOnce the `meta.pagination.next_cursor` value is null,
35844+
all pages have been retrieved."
3577735845
operationId: ListTagConfigurations
3577835846
parameters:
3577935847
- description: Filter custom metrics that have configured tags.
@@ -35838,6 +35906,27 @@ paths:
3583835906
schema:
3583935907
format: int64
3584035908
type: integer
35909+
- description: Maximum number of results returned.
35910+
in: query
35911+
name: page[size]
35912+
required: false
35913+
schema:
35914+
default: 10000
35915+
format: int32
35916+
maximum: 10000
35917+
minimum: 1
35918+
type: integer
35919+
- description: 'String to query the next page of results.
35920+
35921+
This key is provided with each valid response from the API in `meta.pagination.next_cursor`.
35922+
35923+
Once the `meta.pagination.next_cursor` key is null, all pages have been
35924+
retrieved.'
35925+
in: query
35926+
name: page[cursor]
35927+
required: false
35928+
schema:
35929+
type: string
3584135930
responses:
3584235931
'200':
3584335932
content:
@@ -35871,6 +35960,11 @@ paths:
3587135960
summary: Get a list of metrics
3587235961
tags:
3587335962
- Metrics
35963+
x-pagination:
35964+
cursorParam: page[cursor]
35965+
cursorPath: meta.pagination.next_cursor
35966+
limitParam: page[size]
35967+
resultsPath: data
3587435968
x-permission:
3587535969
operator: OR
3587635970
permissions:

.generator/src/generator/templates/api.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,13 @@ impl {{ structName }} {
256256
{%- set cursorPathParts = pagination.cursorPath.split(".") %}
257257
{%- for i in range(cursorPathParts|length) %}
258258
{%- set ns.required = cursorPathParts[i] in ns.parentSchema.get("required", []) %}
259+
{%- set ns.nullable = ns.parentSchema.properties[cursorPathParts[i]].get("nullable", False) %}
259260

260261
{%- if ns.required %}
261262
{%- set ns.cursorGetter = ns.cursorGetter ~ "." ~ cursorPathParts[i] %}
262263
{%- else %}
263264
{%- set attrName = cursorPathParts[i]|variable_name %}
264-
let Some({{ attrName }}) = {{ ns.cursorGetter }}.{{ attrName }} else { break };
265+
let Some({{ attrName }}) = {{ ns.cursorGetter }}.{{ attrName }}{%if ns.nullable %}.unwrap(){% endif %} else { break };
265266
{%- set ns.cursorGetter = attrName %}
266267
{%- endif %}
267268

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Get a list of metrics returns "Success" response with pagination
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV2::api_metrics::ListTagConfigurationsOptionalParams;
4+
use datadog_api_client::datadogV2::api_metrics::MetricsAPI;
5+
use futures_util::pin_mut;
6+
use futures_util::stream::StreamExt;
7+
8+
#[tokio::main]
9+
async fn main() {
10+
let configuration = datadog::Configuration::new();
11+
let api = MetricsAPI::with_config(configuration);
12+
let response = api.list_tag_configurations_with_pagination(
13+
ListTagConfigurationsOptionalParams::default().page_size(2),
14+
);
15+
pin_mut!(response);
16+
while let Some(resp) = response.next().await {
17+
if let Ok(value) = resp {
18+
println!("{:#?}", value);
19+
} else {
20+
println!("{:#?}", resp.unwrap_err());
21+
}
22+
}
23+
}

src/datadogV2/api/api_metrics.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
// This product includes software developed at Datadog (https://www.datadoghq.com/).
33
// Copyright 2019-Present Datadog, Inc.
44
use crate::datadog;
5+
use async_stream::try_stream;
56
use flate2::{
67
write::{GzEncoder, ZlibEncoder},
78
Compression,
89
};
10+
use futures_core::stream::Stream;
911
use reqwest::header::{HeaderMap, HeaderValue};
1012
use serde::{Deserialize, Serialize};
1113
use std::io::Write;
@@ -95,6 +97,12 @@ pub struct ListTagConfigurationsOptionalParams {
9597
/// The number of seconds of look back (from now) to apply to a filter[tag] or filter[queried] query.
9698
/// Default value is 3600 (1 hour), maximum value is 2,592,000 (30 days).
9799
pub window_seconds: Option<i64>,
100+
/// Maximum number of results returned.
101+
pub page_size: Option<i32>,
102+
/// String to query the next page of results.
103+
/// This key is provided with each valid response from the API in `meta.pagination.next_cursor`.
104+
/// Once the `meta.pagination.next_cursor` key is null, all pages have been retrieved.
105+
pub page_cursor: Option<String>,
98106
}
99107

100108
impl ListTagConfigurationsOptionalParams {
@@ -140,6 +148,18 @@ impl ListTagConfigurationsOptionalParams {
140148
self.window_seconds = Some(value);
141149
self
142150
}
151+
/// Maximum number of results returned.
152+
pub fn page_size(mut self, value: i32) -> Self {
153+
self.page_size = Some(value);
154+
self
155+
}
156+
/// String to query the next page of results.
157+
/// This key is provided with each valid response from the API in `meta.pagination.next_cursor`.
158+
/// Once the `meta.pagination.next_cursor` key is null, all pages have been retrieved.
159+
pub fn page_cursor(mut self, value: String) -> Self {
160+
self.page_cursor = Some(value);
161+
self
162+
}
143163
}
144164

145165
/// SubmitMetricsOptionalParams is a struct for passing parameters to the method [`MetricsAPI::submit_metrics`]
@@ -1440,6 +1460,9 @@ impl MetricsAPI {
14401460
}
14411461

14421462
/// Returns all metrics that can be configured in the Metrics Summary page or with Metrics without Limits™ (matching additional filters if specified).
1463+
/// Optionally, paginate by using the `page[cursor]` and/or `page[size]` query parameters.
1464+
/// To fetch the first page, pass in a query parameter with either a valid `page[size]` or an empty cursor like `page[cursor]=`. To fetch the next page, pass in the `next_cursor` value from the response as the new `page[cursor]` value.
1465+
/// Once the `meta.pagination.next_cursor` value is null, all pages have been retrieved.
14431466
pub async fn list_tag_configurations(
14441467
&self,
14451468
params: ListTagConfigurationsOptionalParams,
@@ -1461,7 +1484,48 @@ impl MetricsAPI {
14611484
}
14621485
}
14631486

1487+
pub fn list_tag_configurations_with_pagination(
1488+
&self,
1489+
mut params: ListTagConfigurationsOptionalParams,
1490+
) -> impl Stream<
1491+
Item = Result<
1492+
crate::datadogV2::model::MetricsAndMetricTagConfigurations,
1493+
datadog::Error<ListTagConfigurationsError>,
1494+
>,
1495+
> + '_ {
1496+
try_stream! {
1497+
let mut page_size: i32 = 10000;
1498+
if params.page_size.is_none() {
1499+
params.page_size = Some(page_size);
1500+
} else {
1501+
page_size = params.page_size.unwrap().clone();
1502+
}
1503+
loop {
1504+
let resp = self.list_tag_configurations(params.clone()).await?;
1505+
let Some(data) = resp.data else { break };
1506+
1507+
let r = data;
1508+
let count = r.len();
1509+
for team in r {
1510+
yield team;
1511+
}
1512+
1513+
if count < page_size as usize {
1514+
break;
1515+
}
1516+
let Some(meta) = resp.meta else { break };
1517+
let Some(pagination) = meta.pagination else { break };
1518+
let Some(next_cursor) = pagination.next_cursor.unwrap() else { break };
1519+
1520+
params.page_cursor = Some(next_cursor);
1521+
}
1522+
}
1523+
}
1524+
14641525
/// Returns all metrics that can be configured in the Metrics Summary page or with Metrics without Limits™ (matching additional filters if specified).
1526+
/// Optionally, paginate by using the `page[cursor]` and/or `page[size]` query parameters.
1527+
/// To fetch the first page, pass in a query parameter with either a valid `page[size]` or an empty cursor like `page[cursor]=`. To fetch the next page, pass in the `next_cursor` value from the response as the new `page[cursor]` value.
1528+
/// Once the `meta.pagination.next_cursor` value is null, all pages have been retrieved.
14651529
pub async fn list_tag_configurations_with_http_info(
14661530
&self,
14671531
params: ListTagConfigurationsOptionalParams,
@@ -1482,6 +1546,8 @@ impl MetricsAPI {
14821546
let filter_queried = params.filter_queried;
14831547
let filter_tags = params.filter_tags;
14841548
let window_seconds = params.window_seconds;
1549+
let page_size = params.page_size;
1550+
let page_cursor = params.page_cursor;
14851551

14861552
let local_client = &self.client;
14871553

@@ -1522,6 +1588,14 @@ impl MetricsAPI {
15221588
local_req_builder =
15231589
local_req_builder.query(&[("window[seconds]", &local_query_param.to_string())]);
15241590
};
1591+
if let Some(ref local_query_param) = page_size {
1592+
local_req_builder =
1593+
local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
1594+
};
1595+
if let Some(ref local_query_param) = page_cursor {
1596+
local_req_builder =
1597+
local_req_builder.query(&[("page[cursor]", &local_query_param.to_string())]);
1598+
};
15251599

15261600
// build headers
15271601
let mut headers = HeaderMap::new();

src/datadogV2/model/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,14 @@ pub mod model_metric_tag_configuration_type;
19081908
pub use self::model_metric_tag_configuration_type::MetricTagConfigurationType;
19091909
pub mod model_metrics_and_metric_tag_configurations;
19101910
pub use self::model_metrics_and_metric_tag_configurations::MetricsAndMetricTagConfigurations;
1911+
pub mod model_metrics_list_response_links;
1912+
pub use self::model_metrics_list_response_links::MetricsListResponseLinks;
1913+
pub mod model_metric_pagination_meta;
1914+
pub use self::model_metric_pagination_meta::MetricPaginationMeta;
1915+
pub mod model_metric_meta_page;
1916+
pub use self::model_metric_meta_page::MetricMetaPage;
1917+
pub mod model_metric_meta_page_type;
1918+
pub use self::model_metric_meta_page_type::MetricMetaPageType;
19111919
pub mod model_metric_bulk_tag_config_delete_request;
19121920
pub use self::model_metric_bulk_tag_config_delete_request::MetricBulkTagConfigDeleteRequest;
19131921
pub mod model_metric_bulk_tag_config_delete;

0 commit comments

Comments
 (0)