-
Notifications
You must be signed in to change notification settings - Fork 21
add docs for pagination in /api/v2/metrics endpoint #2021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 2024-12-06T19:12:25.667Z |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Get a list of metrics returns "Success" response with pagination | ||
|
|
||
| require "datadog_api_client" | ||
| api_instance = DatadogAPIClient::V2::MetricsAPI.new | ||
| opts = { | ||
| page_size: 2, | ||
| } | ||
| api_instance.list_tag_configurations_with_pagination(opts) { |item| puts item } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -603,6 +603,9 @@ def list_tag_configurations(opts = {}) | |||||
| # Get a list of metrics. | ||||||
| # | ||||||
| # Returns all metrics that can be configured in the Metrics Summary page or with Metrics without Limits™ (matching additional filters if specified). | ||||||
| # Optionally, paginate by using the `page[cursor]` and/or `page[size]` query parameters. | ||||||
| # 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. | ||||||
| # Once the `meta.pagination.next_cursor` value is null, all pages have been retrieved. | ||||||
| # | ||||||
| # @param opts [Hash] the optional parameters | ||||||
| # @option opts [Boolean] :filter_configured Filter custom metrics that have configured tags. | ||||||
|
|
@@ -612,6 +615,8 @@ def list_tag_configurations(opts = {}) | |||||
| # @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. | ||||||
| # @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. | ||||||
| # @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). | ||||||
| # @option opts [Integer] :page_size Maximum number of results returned. | ||||||
| # @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. | ||||||
| # @return [Array<(MetricsAndMetricTagConfigurationsResponse, Integer, Hash)>] MetricsAndMetricTagConfigurationsResponse data, response status code and response headers | ||||||
| def list_tag_configurations_with_http_info(opts = {}) | ||||||
|
|
||||||
|
|
@@ -622,6 +627,12 @@ def list_tag_configurations_with_http_info(opts = {}) | |||||
| if @api_client.config.client_side_validation && opts[:'filter_metric_type'] && !allowable_values.include?(opts[:'filter_metric_type']) | ||||||
| fail ArgumentError, "invalid value for \"filter_metric_type\", must be one of #{allowable_values}" | ||||||
| end | ||||||
| if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] > 10000 | ||||||
| fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling MetricsAPI.list_tag_configurations, must be smaller than or equal to 10000.' | ||||||
| end | ||||||
| if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] < 1 | ||||||
| fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling MetricsAPI.list_tag_configurations, must be greater than or equal to 1.' | ||||||
| end | ||||||
| # resource path | ||||||
| local_var_path = '/api/v2/metrics' | ||||||
|
|
||||||
|
|
@@ -634,6 +645,8 @@ def list_tag_configurations_with_http_info(opts = {}) | |||||
| query_params[:'filter[queried]'] = opts[:'filter_queried'] if !opts[:'filter_queried'].nil? | ||||||
| query_params[:'filter[tags]'] = opts[:'filter_tags'] if !opts[:'filter_tags'].nil? | ||||||
| query_params[:'window[seconds]'] = opts[:'window_seconds'] if !opts[:'window_seconds'].nil? | ||||||
| query_params[:'page[size]'] = opts[:'page_size'] if !opts[:'page_size'].nil? | ||||||
| query_params[:'page[cursor]'] = opts[:'page_cursor'] if !opts[:'page_cursor'].nil? | ||||||
|
|
||||||
| # header parameters | ||||||
| header_params = opts[:header_params] || {} | ||||||
|
|
@@ -670,6 +683,27 @@ def list_tag_configurations_with_http_info(opts = {}) | |||||
| return data, status_code, headers | ||||||
| end | ||||||
|
|
||||||
| # Get a list of metrics. | ||||||
| # | ||||||
| # Provide a paginated version of {#list_tag_configurations}, returning all items. | ||||||
| # | ||||||
| # To use it you need to use a block: list_tag_configurations_with_pagination { |item| p item } | ||||||
| # | ||||||
| # @yield [MetricsAndMetricTagConfigurations] Paginated items | ||||||
| def list_tag_configurations_with_pagination(opts = {}) | ||||||
| api_version = "V2" | ||||||
| page_size = @api_client.get_attribute_from_path(opts, "page_size", 10000) | ||||||
| @api_client.set_attribute_from_path(api_version, opts, "page_size", Integer, page_size) | ||||||
| while true do | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Code Quality Violation
Suggested change
Don't use the expression `while true` for an infinite loop (...read more)The Ruby static analysis rule "Use Kernel#loop instead of while/until" focuses on promoting the use of The To adhere to this rule, replace any |
||||||
| response = list_tag_configurations(opts) | ||||||
| @api_client.get_attribute_from_path(response, "data").each { |item| yield(item) } | ||||||
| if @api_client.get_attribute_from_path(response, "data").length < page_size | ||||||
| break | ||||||
| end | ||||||
| @api_client.set_attribute_from_path(api_version, opts, "page_cursor", String, @api_client.get_attribute_from_path(response, "meta.pagination.next_cursor")) | ||||||
| end | ||||||
| end | ||||||
|
|
||||||
| # List tags by metric name. | ||||||
| # | ||||||
| # @see #list_tags_by_metric_name_with_http_info | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚪ Code Quality Violation
Avoid using a hash as an optional parameter (...read more)
The rule "Avoid hash optional parameters" is a guideline that encourages developers to explicitly declare parameters instead of using a hash for optional parameters. This is because using a hash for optional parameters can make the code harder to understand and maintain. It can also lead to unexpected behavior if a developer accidentally includes a key in the hash that the method does not expect.
This rule is important because it promotes code readability and maintainability. It also helps prevent potential bugs that may occur due to unexpected keys in the optional hash. By explicitly declaring each parameter, developers can easily see what parameters a method expects, making the code easier to read and understand.
To adhere to this rule, instead of using a hash for optional parameters, explicitly declare each parameter in the method definition. For example, instead of using
options = {}in the method definition, declare each parameter likename, email, age. This way, anyone reading the code can easily understand what parameters the method expects and in what order.