diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index b2b327ba4fab..63e869ff6c8e 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -22607,6 +22607,61 @@ components: type: string type: array type: object + MetricTagCardinalitiesData: + description: A list of tag cardinalities associated with the given metric. + items: + $ref: '#/components/schemas/MetricTagCardinality' + type: array + MetricTagCardinalitiesMeta: + description: Response metadata object. + properties: + metric_name: + description: 'The name of metric for which the tag cardinalities are returned. + + This matches the metric name provided in the request. + + ' + type: string + type: object + MetricTagCardinalitiesResponse: + description: 'Response object that includes an array of objects representing + the cardinality details of a metric''s tags. + + ' + properties: + data: + $ref: '#/components/schemas/MetricTagCardinalitiesData' + meta: + $ref: '#/components/schemas/MetricTagCardinalitiesMeta' + readOnly: true + type: object + MetricTagCardinality: + description: Object containing metadata and attributes related to a specific + tag key associated with the metric. + example: + attributes: + cardinality_delta: 25 + id: http.request.latency + type: get-tag-cardinalities + properties: + attributes: + $ref: '#/components/schemas/MetricTagCardinalityAttributes' + id: + description: The name of the tag key. + type: string + type: + default: get-tag-cardinalities + description: This describes the endpoint action. + type: string + type: object + MetricTagCardinalityAttributes: + description: An object containing properties related to the tag key + properties: + cardinality_delta: + description: This describes the recent change in the tag keys cardinality + format: int64 + type: integer + type: object MetricTagConfiguration: description: Object for a single metric tag configuration. example: @@ -53500,6 +53555,53 @@ paths: permissions: [] x-undo: type: safe + /api/v2/metrics/{metric_name}/tag-cardinalities: + get: + description: Returns the cardinality details of tags for a specific metric. + operationId: GetTagKeyCardinalityDetails + parameters: + - $ref: '#/components/parameters/MetricName' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/MetricTagCardinalitiesResponse' + description: Success + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Forbidden + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Not Found + '429': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Too Many Requests + summary: Get tag key cardinality details + tags: + - Metrics + x-menu-order: 13 + x-permission: + operator: OR + permissions: + - metrics_read + x-undo: + type: safe /api/v2/metrics/{metric_name}/tags: delete: description: 'Deletes a metric''s tag configuration. Can only be used with application diff --git a/features/v2/metrics.feature b/features/v2/metrics.feature index e412ab01368d..01666c53b9b1 100644 --- a/features/v2/metrics.feature +++ b/features/v2/metrics.feature @@ -152,6 +152,30 @@ Feature: Metrics Then the response status is 200 Success And the response "data[0].type" is equal to "manage_tags" + @generated @skip @team:DataDog/metrics-experience + Scenario: Get tag key cardinality details returns "Bad Request" response + Given a valid "appKeyAuth" key in the system + And new "GetTagKeyCardinalityDetails" request + And request contains "metric_name" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/metrics-experience + Scenario: Get tag key cardinality details returns "Not Found" response + Given a valid "appKeyAuth" key in the system + And new "GetTagKeyCardinalityDetails" request + And request contains "metric_name" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/metrics-experience + Scenario: Get tag key cardinality details returns "Success" response + Given a valid "appKeyAuth" key in the system + And new "GetTagKeyCardinalityDetails" request + And request contains "metric_name" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 Success + @generated @skip @team:DataDog/metrics-experience Scenario: List active tags and aggregations returns "Bad Request" response Given a valid "appKeyAuth" key in the system diff --git a/features/v2/undo.json b/features/v2/undo.json index 3cc857a7365b..0c2a47f6596d 100644 --- a/features/v2/undo.json +++ b/features/v2/undo.json @@ -1773,6 +1773,12 @@ "type": "safe" } }, + "GetTagKeyCardinalityDetails": { + "tag": "Metrics", + "undo": { + "type": "safe" + } + }, "DeleteTagConfiguration": { "tag": "Metrics", "undo": { diff --git a/private/bdd_runner/src/support/scenarios_model_mapping.ts b/private/bdd_runner/src/support/scenarios_model_mapping.ts index 9ae9f4d7d3e1..79f2104c9ed1 100644 --- a/private/bdd_runner/src/support/scenarios_model_mapping.ts +++ b/private/bdd_runner/src/support/scenarios_model_mapping.ts @@ -5698,6 +5698,13 @@ export const ScenariosModelMappings: { [key: string]: OperationMapping } = { }, operationResponseType: "MetricEstimateResponse", }, + "MetricsApi.V2.GetTagKeyCardinalityDetails": { + metricName: { + type: "string", + format: "", + }, + operationResponseType: "MetricTagCardinalitiesResponse", + }, "MetricsApi.V2.ListTagConfigurationByName": { metricName: { type: "string", diff --git a/services/metrics/src/v2/MetricsApi.ts b/services/metrics/src/v2/MetricsApi.ts index bd9dda390566..cede0e5377bc 100644 --- a/services/metrics/src/v2/MetricsApi.ts +++ b/services/metrics/src/v2/MetricsApi.ts @@ -35,6 +35,7 @@ import { MetricPayload } from "./models/MetricPayload"; import { MetricsAndMetricTagConfigurations } from "./models/MetricsAndMetricTagConfigurations"; import { MetricsAndMetricTagConfigurationsResponse } from "./models/MetricsAndMetricTagConfigurationsResponse"; import { MetricSuggestedTagsAndAggregationsResponse } from "./models/MetricSuggestedTagsAndAggregationsResponse"; +import { MetricTagCardinalitiesResponse } from "./models/MetricTagCardinalitiesResponse"; import { MetricTagConfigurationCreateRequest } from "./models/MetricTagConfigurationCreateRequest"; import { MetricTagConfigurationMetricTypeCategory } from "./models/MetricTagConfigurationMetricTypeCategory"; import { MetricTagConfigurationResponse } from "./models/MetricTagConfigurationResponse"; @@ -344,6 +345,51 @@ export class MetricsApiRequestFactory extends BaseAPIRequestFactory { return requestContext; } + public async getTagKeyCardinalityDetails( + metricName: string, + _options?: Configuration, + ): Promise { + const _config = _options || this.configuration; + + // verify required parameter 'metricName' is not null or undefined + if (metricName === null || metricName === undefined) { + throw new RequiredError("metricName", "getTagKeyCardinalityDetails"); + } + + // Path Params + const localVarPath = + "/api/v2/metrics/{metric_name}/tag-cardinalities".replace( + "{metric_name}", + encodeURIComponent(String(metricName)), + ); + + // Make Request Context + const { server, overrides } = _config.getServerAndOverrides( + "MetricsApi.v2.getTagKeyCardinalityDetails", + MetricsApi.operationServers, + ); + const requestContext = server.makeRequestContext( + localVarPath, + HttpMethod.GET, + overrides, + ); + requestContext.setHeaderParam("Accept", "application/json"); + requestContext.setHttpConfig(_config.httpConfig); + + // Set User-Agent + if (this.userAgent) { + requestContext.setHeaderParam("User-Agent", this.userAgent); + } + + // Apply auth methods + applySecurityAuthentication(_config, requestContext, [ + "apiKeyAuth", + "appKeyAuth", + ]); + + return requestContext; + } + public async listActiveMetricConfigurations( metricName: string, windowSeconds?: number, @@ -1213,6 +1259,67 @@ export class MetricsApiResponseProcessor { ); } + /** + * Unwraps the actual response sent by the server from the response context and deserializes the response content + * to the expected objects + * + * @params response Response returned by the server for a request to getTagKeyCardinalityDetails + * @throws ApiException if the response code was not in [200, 299] + */ + public async getTagKeyCardinalityDetails( + response: ResponseContext, + ): Promise { + const contentType = normalizeMediaType(response.headers["content-type"]); + if (response.httpStatusCode === 200) { + const body: MetricTagCardinalitiesResponse = deserialize( + parse(await response.body.text(), contentType), + TypingInfo, + "MetricTagCardinalitiesResponse", + ) as MetricTagCardinalitiesResponse; + return body; + } + if ( + response.httpStatusCode === 400 || + response.httpStatusCode === 403 || + response.httpStatusCode === 404 || + response.httpStatusCode === 429 + ) { + const bodyText = parse(await response.body.text(), contentType); + let body: APIErrorResponse; + try { + body = deserialize( + bodyText, + TypingInfo, + "APIErrorResponse", + ) as APIErrorResponse; + } catch (error) { + logger.debug(`Got error deserializing error: ${error}`); + throw new ApiException( + response.httpStatusCode, + bodyText, + ); + } + throw new ApiException(response.httpStatusCode, body); + } + + // Work around for missing responses in specification, e.g. for petstore.yaml + if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { + const body: MetricTagCardinalitiesResponse = deserialize( + parse(await response.body.text(), contentType), + TypingInfo, + "MetricTagCardinalitiesResponse", + "", + ) as MetricTagCardinalitiesResponse; + return body; + } + + const body = (await response.body.text()) || ""; + throw new ApiException( + response.httpStatusCode, + 'Unknown API Status Code!\nBody: "' + body + '"', + ); + } + /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects @@ -1890,6 +1997,14 @@ export interface MetricsApiEstimateMetricsOutputSeriesRequest { filterTimespanH?: number; } +export interface MetricsApiGetTagKeyCardinalityDetailsRequest { + /** + * The name of the metric. + * @type string + */ + metricName: string; +} + export interface MetricsApiListActiveMetricConfigurationsRequest { /** * The name of the metric. @@ -2186,6 +2301,30 @@ export class MetricsApi { }); } + /** + * Returns the cardinality details of tags for a specific metric. + * @param param The request object + */ + public getTagKeyCardinalityDetails( + param: MetricsApiGetTagKeyCardinalityDetailsRequest, + options?: Configuration, + ): Promise { + const requestContextPromise = + this.requestFactory.getTagKeyCardinalityDetails( + param.metricName, + options, + ); + return requestContextPromise.then((requestContext) => { + return this.configuration.httpApi + .send(requestContext) + .then((responseContext) => { + return this.responseProcessor.getTagKeyCardinalityDetails( + responseContext, + ); + }); + }); + } + /** * List tags and aggregations that are actively queried on dashboards, notebooks, monitors, the Metrics Explorer, and using the API for a given metric name. * @param param The request object diff --git a/services/metrics/src/v2/index.ts b/services/metrics/src/v2/index.ts index dff244ee9fee..5b87a14d2448 100644 --- a/services/metrics/src/v2/index.ts +++ b/services/metrics/src/v2/index.ts @@ -4,6 +4,7 @@ export { MetricsApiDeleteBulkTagsMetricsConfigurationRequest, MetricsApiDeleteTagConfigurationRequest, MetricsApiEstimateMetricsOutputSeriesRequest, + MetricsApiGetTagKeyCardinalityDetailsRequest, MetricsApiListActiveMetricConfigurationsRequest, MetricsApiListMetricAssetsRequest, MetricsApiListTagConfigurationByNameRequest, @@ -103,6 +104,10 @@ export { MetricsTimeseriesQuery } from "./models/MetricsTimeseriesQuery"; export { MetricSuggestedTagsAndAggregations } from "./models/MetricSuggestedTagsAndAggregations"; export { MetricSuggestedTagsAndAggregationsResponse } from "./models/MetricSuggestedTagsAndAggregationsResponse"; export { MetricSuggestedTagsAttributes } from "./models/MetricSuggestedTagsAttributes"; +export { MetricTagCardinalitiesMeta } from "./models/MetricTagCardinalitiesMeta"; +export { MetricTagCardinalitiesResponse } from "./models/MetricTagCardinalitiesResponse"; +export { MetricTagCardinality } from "./models/MetricTagCardinality"; +export { MetricTagCardinalityAttributes } from "./models/MetricTagCardinalityAttributes"; export { MetricTagConfiguration } from "./models/MetricTagConfiguration"; export { MetricTagConfigurationAttributes } from "./models/MetricTagConfigurationAttributes"; export { MetricTagConfigurationCreateAttributes } from "./models/MetricTagConfigurationCreateAttributes"; diff --git a/services/metrics/src/v2/models/MetricTagCardinalitiesMeta.ts b/services/metrics/src/v2/models/MetricTagCardinalitiesMeta.ts new file mode 100644 index 000000000000..727d7a046509 --- /dev/null +++ b/services/metrics/src/v2/models/MetricTagCardinalitiesMeta.ts @@ -0,0 +1,45 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +/** + * Response metadata object. + */ +export class MetricTagCardinalitiesMeta { + /** + * The name of metric for which the tag cardinalities are returned. + * This matches the metric name provided in the request. + */ + "metricName"?: string; + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + "additionalProperties"?: { [key: string]: any }; + /** + * @ignore + */ + "_unparsed"?: boolean; + + /** + * @ignore + */ + static readonly attributeTypeMap: AttributeTypeMap = { + metricName: { + baseName: "metric_name", + type: "string", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return MetricTagCardinalitiesMeta.attributeTypeMap; + } + + public constructor() {} +} diff --git a/services/metrics/src/v2/models/MetricTagCardinalitiesResponse.ts b/services/metrics/src/v2/models/MetricTagCardinalitiesResponse.ts new file mode 100644 index 000000000000..c4a6fdf590a8 --- /dev/null +++ b/services/metrics/src/v2/models/MetricTagCardinalitiesResponse.ts @@ -0,0 +1,55 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +import { MetricTagCardinalitiesMeta } from "./MetricTagCardinalitiesMeta"; +import { MetricTagCardinality } from "./MetricTagCardinality"; + +/** + * Response object that includes an array of objects representing the cardinality details of a metric's tags. + */ +export class MetricTagCardinalitiesResponse { + /** + * A list of tag cardinalities associated with the given metric. + */ + "data"?: Array; + /** + * Response metadata object. + */ + "meta"?: MetricTagCardinalitiesMeta; + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + "additionalProperties"?: { [key: string]: any }; + /** + * @ignore + */ + "_unparsed"?: boolean; + + /** + * @ignore + */ + static readonly attributeTypeMap: AttributeTypeMap = { + data: { + baseName: "data", + type: "Array", + }, + meta: { + baseName: "meta", + type: "MetricTagCardinalitiesMeta", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return MetricTagCardinalitiesResponse.attributeTypeMap; + } + + public constructor() {} +} diff --git a/services/metrics/src/v2/models/MetricTagCardinality.ts b/services/metrics/src/v2/models/MetricTagCardinality.ts new file mode 100644 index 000000000000..a629f6bf87e8 --- /dev/null +++ b/services/metrics/src/v2/models/MetricTagCardinality.ts @@ -0,0 +1,62 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +import { MetricTagCardinalityAttributes } from "./MetricTagCardinalityAttributes"; + +/** + * Object containing metadata and attributes related to a specific tag key associated with the metric. + */ +export class MetricTagCardinality { + /** + * An object containing properties related to the tag key + */ + "attributes"?: MetricTagCardinalityAttributes; + /** + * The name of the tag key. + */ + "id"?: string; + /** + * This describes the endpoint action. + */ + "type"?: string; + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + "additionalProperties"?: { [key: string]: any }; + /** + * @ignore + */ + "_unparsed"?: boolean; + + /** + * @ignore + */ + static readonly attributeTypeMap: AttributeTypeMap = { + attributes: { + baseName: "attributes", + type: "MetricTagCardinalityAttributes", + }, + id: { + baseName: "id", + type: "string", + }, + type: { + baseName: "type", + type: "string", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return MetricTagCardinality.attributeTypeMap; + } + + public constructor() {} +} diff --git a/services/metrics/src/v2/models/MetricTagCardinalityAttributes.ts b/services/metrics/src/v2/models/MetricTagCardinalityAttributes.ts new file mode 100644 index 000000000000..f209bd084177 --- /dev/null +++ b/services/metrics/src/v2/models/MetricTagCardinalityAttributes.ts @@ -0,0 +1,45 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +/** + * An object containing properties related to the tag key + */ +export class MetricTagCardinalityAttributes { + /** + * This describes the recent change in the tag keys cardinality + */ + "cardinalityDelta"?: number; + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + "additionalProperties"?: { [key: string]: any }; + /** + * @ignore + */ + "_unparsed"?: boolean; + + /** + * @ignore + */ + static readonly attributeTypeMap: AttributeTypeMap = { + cardinalityDelta: { + baseName: "cardinality_delta", + type: "number", + format: "int64", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return MetricTagCardinalityAttributes.attributeTypeMap; + } + + public constructor() {} +} diff --git a/services/metrics/src/v2/models/TypingInfo.ts b/services/metrics/src/v2/models/TypingInfo.ts index 3533db478246..238eb5f446d0 100644 --- a/services/metrics/src/v2/models/TypingInfo.ts +++ b/services/metrics/src/v2/models/TypingInfo.ts @@ -60,6 +60,10 @@ import { MetricSeries } from "./MetricSeries"; import { MetricSuggestedTagsAndAggregations } from "./MetricSuggestedTagsAndAggregations"; import { MetricSuggestedTagsAndAggregationsResponse } from "./MetricSuggestedTagsAndAggregationsResponse"; import { MetricSuggestedTagsAttributes } from "./MetricSuggestedTagsAttributes"; +import { MetricTagCardinalitiesMeta } from "./MetricTagCardinalitiesMeta"; +import { MetricTagCardinalitiesResponse } from "./MetricTagCardinalitiesResponse"; +import { MetricTagCardinality } from "./MetricTagCardinality"; +import { MetricTagCardinalityAttributes } from "./MetricTagCardinalityAttributes"; import { MetricTagConfiguration } from "./MetricTagConfiguration"; import { MetricTagConfigurationAttributes } from "./MetricTagConfigurationAttributes"; import { MetricTagConfigurationCreateAttributes } from "./MetricTagConfigurationCreateAttributes"; @@ -231,6 +235,10 @@ export const TypingInfo: ModelTypingInfo = { MetricSuggestedTagsAndAggregationsResponse: MetricSuggestedTagsAndAggregationsResponse, MetricSuggestedTagsAttributes: MetricSuggestedTagsAttributes, + MetricTagCardinalitiesMeta: MetricTagCardinalitiesMeta, + MetricTagCardinalitiesResponse: MetricTagCardinalitiesResponse, + MetricTagCardinality: MetricTagCardinality, + MetricTagCardinalityAttributes: MetricTagCardinalityAttributes, MetricTagConfiguration: MetricTagConfiguration, MetricTagConfigurationAttributes: MetricTagConfigurationAttributes, MetricTagConfigurationCreateAttributes: