Skip to content

Commit 50626e7

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
add docs for pagination in /api/v2/metrics endpoint (#2021)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent e4c4f36 commit 50626e7

14 files changed

+674
-8
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:37.297873",
8-
"spec_repo_commit": "7b62d196"
7+
"regenerated": "2024-12-12 13:29:22.131222",
8+
"spec_repo_commit": "f0c3c0f4"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2024-12-11 20:35:37.316642",
13-
"spec_repo_commit": "7b62d196"
12+
"regenerated": "2024-12-12 13:29:22.150037",
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:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2024-12-06T19:12:25.667Z

cassettes/features/v2/metrics/Get-a-list-of-metrics-returns-Success-response-with-pagination.yml

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Get a list of metrics returns "Success" response with pagination
2+
3+
require "datadog_api_client"
4+
api_instance = DatadogAPIClient::V2::MetricsAPI.new
5+
opts = {
6+
page_size: 2,
7+
}
8+
api_instance.list_tag_configurations_with_pagination(opts) { |item| puts item }

features/scenarios_model_mapping.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,8 @@
15821582
"filter_queried" => "Boolean",
15831583
"filter_tags" => "String",
15841584
"window_seconds" => "Integer",
1585+
"page_size" => "Integer",
1586+
"page_cursor" => "String",
15851587
},
15861588
"v2.DeleteBulkTagsMetricsConfiguration" => {
15871589
"body" => "MetricBulkTagConfigDeleteRequest",

features/v2/metrics.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ Feature: Metrics
125125
When the request is sent
126126
Then the response status is 200 Success
127127

128+
@replay-only @skip-validation @team:DataDog/metrics-experience @with-pagination
129+
Scenario: Get a list of metrics returns "Success" response with pagination
130+
Given a valid "appKeyAuth" key in the system
131+
And new "ListTagConfigurations" request
132+
And request contains "page[size]" parameter with value 2
133+
When the request with pagination is sent
134+
Then the response status is 200 Success
135+
And the response has 3 items
136+
128137
@team:DataDog/metrics-experience
129138
Scenario: Get a list of metrics with a tag filter returns "Success" response
130139
Given a valid "appKeyAuth" key in the system

lib/datadog_api_client/inflector.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,11 +1868,14 @@ def overrides
18681868
"v2.metric_ingested_indexed_volume_type" => "MetricIngestedIndexedVolumeType",
18691869
"v2.metric_intake_type" => "MetricIntakeType",
18701870
"v2.metric_metadata" => "MetricMetadata",
1871+
"v2.metric_meta_page" => "MetricMetaPage",
1872+
"v2.metric_meta_page_type" => "MetricMetaPageType",
18711873
"v2.metric_monitor_asset" => "MetricMonitorAsset",
18721874
"v2.metric_monitor_type" => "MetricMonitorType",
18731875
"v2.metric_notebook_asset" => "MetricNotebookAsset",
18741876
"v2.metric_notebook_type" => "MetricNotebookType",
18751877
"v2.metric_origin" => "MetricOrigin",
1878+
"v2.metric_pagination_meta" => "MetricPaginationMeta",
18761879
"v2.metric_payload" => "MetricPayload",
18771880
"v2.metric_point" => "MetricPoint",
18781881
"v2.metric_resource" => "MetricResource",
@@ -1881,6 +1884,7 @@ def overrides
18811884
"v2.metrics_and_metric_tag_configurations_response" => "MetricsAndMetricTagConfigurationsResponse",
18821885
"v2.metrics_data_source" => "MetricsDataSource",
18831886
"v2.metric_series" => "MetricSeries",
1887+
"v2.metrics_list_response_links" => "MetricsListResponseLinks",
18841888
"v2.metric_slo_asset" => "MetricSLOAsset",
18851889
"v2.metric_slo_type" => "MetricSLOType",
18861890
"v2.metrics_scalar_query" => "MetricsScalarQuery",

lib/datadog_api_client/v2/api/metrics_api.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,9 @@ def list_tag_configurations(opts = {})
603603
# Get a list of metrics.
604604
#
605605
# Returns all metrics that can be configured in the Metrics Summary page or with Metrics without Limits™ (matching additional filters if specified).
606+
# Optionally, paginate by using the `page[cursor]` and/or `page[size]` query parameters.
607+
# 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.
608+
# Once the `meta.pagination.next_cursor` value is null, all pages have been retrieved.
606609
#
607610
# @param opts [Hash] the optional parameters
608611
# @option opts [Boolean] :filter_configured Filter custom metrics that have configured tags.
@@ -612,6 +615,8 @@ def list_tag_configurations(opts = {})
612615
# @option opts [Boolean] :filter_queried (Beta) Filter custom metrics that have or have not been queried in the specified window[seconds]. If no window is provided or the window is less than 2 hours, a default of 2 hours will be applied.
613616
# @option opts [String] :filter_tags Filter metrics that have been submitted with the given tags. Supports boolean and wildcard expressions. Can only be combined with the filter[queried] filter.
614617
# @option opts [Integer] :window_seconds The number of seconds of look back (from now) to apply to a filter[tag] or filter[queried] query. Default value is 3600 (1 hour), maximum value is 2,592,000 (30 days).
618+
# @option opts [Integer] :page_size Maximum number of results returned.
619+
# @option opts [String] :page_cursor String to query the next page of results. This key is provided with each valid response from the API in `meta.pagination.next_cursor`. Once the `meta.pagination.next_cursor` key is null, all pages have been retrieved.
615620
# @return [Array<(MetricsAndMetricTagConfigurationsResponse, Integer, Hash)>] MetricsAndMetricTagConfigurationsResponse data, response status code and response headers
616621
def list_tag_configurations_with_http_info(opts = {})
617622

@@ -622,6 +627,12 @@ def list_tag_configurations_with_http_info(opts = {})
622627
if @api_client.config.client_side_validation && opts[:'filter_metric_type'] && !allowable_values.include?(opts[:'filter_metric_type'])
623628
fail ArgumentError, "invalid value for \"filter_metric_type\", must be one of #{allowable_values}"
624629
end
630+
if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] > 10000
631+
fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling MetricsAPI.list_tag_configurations, must be smaller than or equal to 10000.'
632+
end
633+
if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] < 1
634+
fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling MetricsAPI.list_tag_configurations, must be greater than or equal to 1.'
635+
end
625636
# resource path
626637
local_var_path = '/api/v2/metrics'
627638

@@ -634,6 +645,8 @@ def list_tag_configurations_with_http_info(opts = {})
634645
query_params[:'filter[queried]'] = opts[:'filter_queried'] if !opts[:'filter_queried'].nil?
635646
query_params[:'filter[tags]'] = opts[:'filter_tags'] if !opts[:'filter_tags'].nil?
636647
query_params[:'window[seconds]'] = opts[:'window_seconds'] if !opts[:'window_seconds'].nil?
648+
query_params[:'page[size]'] = opts[:'page_size'] if !opts[:'page_size'].nil?
649+
query_params[:'page[cursor]'] = opts[:'page_cursor'] if !opts[:'page_cursor'].nil?
637650

638651
# header parameters
639652
header_params = opts[:header_params] || {}
@@ -670,6 +683,27 @@ def list_tag_configurations_with_http_info(opts = {})
670683
return data, status_code, headers
671684
end
672685

686+
# Get a list of metrics.
687+
#
688+
# Provide a paginated version of {#list_tag_configurations}, returning all items.
689+
#
690+
# To use it you need to use a block: list_tag_configurations_with_pagination { |item| p item }
691+
#
692+
# @yield [MetricsAndMetricTagConfigurations] Paginated items
693+
def list_tag_configurations_with_pagination(opts = {})
694+
api_version = "V2"
695+
page_size = @api_client.get_attribute_from_path(opts, "page_size", 10000)
696+
@api_client.set_attribute_from_path(api_version, opts, "page_size", Integer, page_size)
697+
while true do
698+
response = list_tag_configurations(opts)
699+
@api_client.get_attribute_from_path(response, "data").each { |item| yield(item) }
700+
if @api_client.get_attribute_from_path(response, "data").length < page_size
701+
break
702+
end
703+
@api_client.set_attribute_from_path(api_version, opts, "page_cursor", String, @api_client.get_attribute_from_path(response, "meta.pagination.next_cursor"))
704+
end
705+
end
706+
673707
# List tags by metric name.
674708
#
675709
# @see #list_tags_by_metric_name_with_http_info

0 commit comments

Comments
 (0)