diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 661976d24e3e..d4dfe8ead6bc 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -18645,6 +18645,376 @@ components: - ATTACK_PATH - IDENTITY_RISK - API_SECURITY + FlakyTest: + description: A flaky test object. + properties: + attributes: + $ref: '#/components/schemas/FlakyTestAttributes' + id: + description: Test's ID. This ID is the hash of the test's Fully Qualified + Name and Git repository ID. On the Test Runs UI it is the same as the + `test_fingerprint_fqn` tag. + type: string + type: + $ref: '#/components/schemas/FlakyTestType' + type: object + FlakyTestAttributes: + description: Attributes of a flaky test. + properties: + attempt_to_fix_id: + description: 'Unique identifier for the attempt to fix this flaky test. + Use this ID in the Git commit message in order to trigger the attempt + to fix workflow. + + + When the workflow is triggered the test is automatically retried by the + tracer a certain number of configurable times. When all retries pass, + the test is automatically marked as fixed in Flaky Test Management. + + Test runs are tagged with @test.test_management.attempt_to_fix_passed + and @test.test_management.is_attempt_to_fix when the attempt to fix workflow + is triggered.' + example: I42TEO + type: string + codeowners: + description: The name of the test's code owners as inferred from the repository + configuration. + example: + - '@foo' + - '@bar' + items: + type: string + type: array + envs: + description: List of environments where this test has been flaky. + example: prod + items: + type: string + type: array + first_flaked_branch: + description: The branch name where the test exhibited flakiness for the + first time. + example: main + type: string + first_flaked_sha: + description: The commit SHA where the test exhibited flakiness for the first + time. + example: 0c6be03165b7f7ffe96e076ffb29afb2825616c3 + type: string + first_flaked_ts: + description: Unix timestamp when the test exhibited flakiness for the first + time. + example: 1757688149 + format: int64 + type: integer + flaky_category: + description: The category of a flaky test. + example: Timeout + nullable: true + type: string + flaky_state: + $ref: '#/components/schemas/FlakyTestAttributesFlakyState' + last_flaked_branch: + description: The branch name where the test exhibited flakiness for the + last time. + example: main + type: string + last_flaked_sha: + description: The commit SHA where the test exhibited flakiness for the last + time. + example: 0c6be03165b7f7ffe96e076ffb29afb2825616c3 + type: string + last_flaked_ts: + description: Unix timestamp when the test exhibited flakiness for the last + time. + example: 1757688149 + format: int64 + type: integer + module: + description: 'The name of the test module. The definition of module changes + slightly per language: + + - In .NET, a test module groups every test that is run under the same + unit test project. + + - In Swift, a test module groups every test that is run for a given bundle. + + - In JavaScript, the test modules map one-to-one to test sessions. + + - In Java, a test module groups every test that is run by the same Maven + Surefire/Failsafe or Gradle Test task execution. + + - In Python, a test module groups every test that is run under the same + `.py` file as part of a test suite, which is typically managed by a framework + like `unittest` or `pytest`. + + - In Ruby, a test module groups every test that is run within the same + test file, which is typically managed by a framework like `RSpec` or `Minitest`.' + example: TestModule + nullable: true + type: string + name: + description: The test name. A concise name for a test case. Defined in the + test itself. + example: TestName + type: string + pipeline_stats: + $ref: '#/components/schemas/FlakyTestPipelineStats' + nullable: true + services: + description: 'List of test service names where this test has been flaky. + + + A test service is a group of tests associated with a project or repository. + It contains all the individual tests for your code, optionally organized + into test suites, which are like folders for your tests.' + example: + - foo + - bar + items: + type: string + type: array + suite: + description: The name of the test suite. A group of tests exercising the + same unit of code depending on your language and testing framework. + example: TestSuite + type: string + test_run_metadata: + $ref: '#/components/schemas/FlakyTestRunMetadata' + test_stats: + $ref: '#/components/schemas/FlakyTestStats' + type: object + FlakyTestAttributesFlakyState: + description: The current state of the flaky test. + enum: + - active + - fixed + - quarantined + - disabled + example: active + type: string + x-enum-varnames: + - ACTIVE + - FIXED + - QUARANTINED + - DISABLED + FlakyTestPipelineStats: + description: CI pipeline related statistics for the flaky test. This information + is only available if test runs are associated with CI pipeline events from + CI Visibility. + properties: + failed_pipelines: + description: The number of pipelines that failed due to this test for the + past 7 days. This is computed as the sum of failed CI pipeline events + associated with test runs where the flaky test failed. + example: 319 + format: int64 + nullable: true + type: integer + total_lost_time_ms: + description: The total time lost by CI pipelines due to this flaky test + in milliseconds. This is computed as the sum of the duration of failed + CI pipeline events associated with test runs where the flaky test failed. + example: 1527550000 + format: int64 + nullable: true + type: integer + type: object + FlakyTestRunMetadata: + description: Metadata about the latest failed test run of the flaky test. + properties: + duration_ms: + description: The duration of the test run in milliseconds. + example: 27398 + format: int64 + nullable: true + type: integer + error_message: + description: The error message from the test failure. + example: Expecting actual not to be empty + nullable: true + type: string + error_stack: + description: The stack trace from the test failure. + example: "Traceback (most recent call last):\n File \"test_foo.py\", line + 10, in test_foo\n assert actual == expected\nAssertionError: Expecting + actual not to be empty" + nullable: true + type: string + source_end: + description: The line number where the test ends in the source file. + example: 20 + format: int64 + nullable: true + type: integer + source_file: + description: The source file where the test is defined. + example: test_foo.py + nullable: true + type: string + source_start: + description: The line number where the test starts in the source file. + example: 10 + format: int64 + nullable: true + type: integer + type: object + FlakyTestStats: + description: Test statistics for the flaky test. + properties: + failure_rate_pct: + description: The failure rate percentage of the test for the past 7 days. + This is the number of failed test runs divided by the total number of + test runs (excluding skipped test runs). + example: 0.1 + format: double + nullable: true + type: number + type: object + FlakyTestType: + description: The type of the flaky test from Flaky Test Management. + enum: + - flaky_test + type: string + x-enum-varnames: + - FLAKY_TEST + FlakyTestsPagination: + description: Pagination metadata for flaky tests. + properties: + next_page: + description: Cursor for the next page of results. + nullable: true + type: string + type: object + FlakyTestsSearchFilter: + description: Search filter settings. + properties: + query: + default: '*' + description: 'Search query following log syntax used to filter flaky tests, + same as on Flaky Tests Management UI. The supported search keys are: + + - `flaky_test_state` + + - `flaky_test_category` + + - `@test.name` + + - `@test.suite` + + - `@test.module` + + - `@test.service` + + - `@git.repository.id_v2` + + - `@git.branch` + + - `@test.codeowners` + + - `env` + + ' + example: flaky_test_state:active @git.repository.id_v2:"github.com/datadog/shopist" + type: string + type: object + FlakyTestsSearchPageOptions: + description: Pagination attributes for listing flaky tests. + properties: + cursor: + description: List following results with a cursor provided in the previous + request. + example: eyJzdGFydEF0IjoiQVFBQUFYS2tMS3pPbm40NGV3QUFBQUJCV0V0clRFdDZVbG8zY3pCRmNsbHJiVmxDWlEifQ== + type: string + limit: + default: 10 + description: Maximum number of flaky tests in the response. + example: 25 + format: int64 + maximum: 1000 + minimum: 1 + type: integer + type: object + FlakyTestsSearchRequest: + description: The request for a flaky tests search. + properties: + data: + $ref: '#/components/schemas/FlakyTestsSearchRequestData' + type: object + FlakyTestsSearchRequestAttributes: + description: Attributes for the flaky tests search request. + properties: + filter: + $ref: '#/components/schemas/FlakyTestsSearchFilter' + page: + $ref: '#/components/schemas/FlakyTestsSearchPageOptions' + sort: + $ref: '#/components/schemas/FlakyTestsSearchSort' + type: object + FlakyTestsSearchRequestData: + description: The JSON:API data for flaky tests search request. + properties: + attributes: + $ref: '#/components/schemas/FlakyTestsSearchRequestAttributes' + type: + $ref: '#/components/schemas/FlakyTestsSearchRequestDataType' + type: object + FlakyTestsSearchRequestDataType: + description: The definition of `FlakyTestsSearchRequestDataType` object. + enum: + - search_flaky_tests_request + type: string + x-enum-varnames: + - SEARCH_FLAKY_TESTS_REQUEST + FlakyTestsSearchResponse: + description: Response object with flaky tests matching the search request. + properties: + data: + description: Array of flaky tests matching the request. + items: + $ref: '#/components/schemas/FlakyTest' + type: array + meta: + $ref: '#/components/schemas/FlakyTestsSearchResponseMeta' + type: object + FlakyTestsSearchResponseMeta: + description: Metadata for the flaky tests search response. + properties: + pagination: + $ref: '#/components/schemas/FlakyTestsPagination' + type: object + FlakyTestsSearchSort: + description: Parameter for sorting flaky test results. The default sort is by + ascending Fully Qualified Name (FQN). The FQN is the concatenation of the + test module, suite, and name. + enum: + - fqn + - -fqn + - first_flaked + - -first_flaked + - last_flaked + - -last_flaked + - failure_rate + - -failure_rate + - pipelines_failed + - -pipelines_failed + - pipelines_duration_lost + - -pipelines_duration_lost + example: failure_rate + type: string + x-enum-varnames: + - FQN_ASCENDING + - FQN_DESCENDING + - FIRST_FLAKED_ASCENDING + - FIRST_FLAKED_DESCENDING + - LAST_FLAKED_ASCENDING + - LAST_FLAKED_DESCENDING + - FAILURE_RATE_ASCENDING + - FAILURE_RATE_DESCENDING + - PIPELINES_FAILED_ASCENDING + - PIPELINES_FAILED_DESCENDING + - PIPELINES_DURATION_LOST_ASCENDING + - PIPELINES_DURATION_LOST_DESCENDING FormulaLimit: description: 'Message for specifying limits to the number of values returned by a query. @@ -74196,6 +74566,52 @@ paths: permissions: - incident_settings_write x-unstable: '**Note**: This endpoint is deprecated. See the [Teams API endpoints](https://docs.datadoghq.com/api/latest/teams/).' + /api/v2/test/flaky-test-management/tests: + post: + description: List endpoint returning flaky tests from Flaky Test Management. + Results are paginated. + operationId: SearchFlakyTests + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/FlakyTestsSearchRequest' + required: false + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/FlakyTestsSearchResponse' + description: OK + '400': + $ref: '#/components/responses/BadRequestResponse' + '403': + $ref: '#/components/responses/NotAuthorizedResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - test_optimization_read + summary: Search flaky tests + tags: + - Test Optimization + x-codegen-request-body-name: body + x-pagination: + cursorParam: body.data.attributes.page.cursor + cursorPath: meta.pagination.next_page + limitParam: body.data.attributes.page.limit + resultsPath: data + x-permission: + operator: OR + permissions: + - test_optimization_read + x-unstable: '**Note**: This endpoint is in public beta and may be subject to + change. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' /api/v2/usage/application_security: get: deprecated: true @@ -76239,6 +76655,9 @@ tags: - description: View and manage teams within Datadog. See the [Teams page](https://docs.datadoghq.com/account_management/teams/) for more information. name: Teams +- description: Search and manage flaky tests through Test Optimization. See the [Test + Optimization page](https://docs.datadoghq.com/tests/) for more information. + name: Test Optimization - description: 'The usage metering API allows you to get hourly, daily, and monthly usage across multiple facets of Datadog. diff --git a/examples/v2/test-optimization/SearchFlakyTests.ts b/examples/v2/test-optimization/SearchFlakyTests.ts new file mode 100644 index 000000000000..2aabaaedd18f --- /dev/null +++ b/examples/v2/test-optimization/SearchFlakyTests.ts @@ -0,0 +1,37 @@ +/** + * Search flaky tests returns "OK" response + */ + +import { client, v2 } from "@datadog/datadog-api-client"; + +const configuration = client.createConfiguration(); +configuration.unstableOperations["v2.searchFlakyTests"] = true; +const apiInstance = new v2.TestOptimizationApi(configuration); + +const params: v2.TestOptimizationApiSearchFlakyTestsRequest = { + body: { + data: { + attributes: { + filter: { + query: `flaky_test_state:active @git.repository.id_v2:"github.com/datadog/shopist"`, + }, + page: { + cursor: + "eyJzdGFydEF0IjoiQVFBQUFYS2tMS3pPbm40NGV3QUFBQUJCV0V0clRFdDZVbG8zY3pCRmNsbHJiVmxDWlEifQ==", + limit: 25, + }, + sort: "failure_rate", + }, + type: "search_flaky_tests_request", + }, + }, +}; + +apiInstance + .searchFlakyTests(params) + .then((data: v2.FlakyTestsSearchResponse) => { + console.log( + "API called successfully. Returned data: " + JSON.stringify(data) + ); + }) + .catch((error: any) => console.error(error)); diff --git a/examples/v2/test-optimization/SearchFlakyTests_1224086727.ts b/examples/v2/test-optimization/SearchFlakyTests_1224086727.ts new file mode 100644 index 000000000000..7d8131fbfdc0 --- /dev/null +++ b/examples/v2/test-optimization/SearchFlakyTests_1224086727.ts @@ -0,0 +1,40 @@ +/** + * Search flaky tests returns "OK" response with pagination + */ + +import { client, v2 } from "@datadog/datadog-api-client"; + +const configuration = client.createConfiguration(); +configuration.unstableOperations["v2.searchFlakyTests"] = true; +const apiInstance = new v2.TestOptimizationApi(configuration); + +const params: v2.TestOptimizationApiSearchFlakyTestsRequest = { + body: { + data: { + attributes: { + filter: { + query: `flaky_test_state:active @git.repository.id_v2:"github.com/datadog/shopist"`, + }, + page: { + cursor: + "eyJzdGFydEF0IjoiQVFBQUFYS2tMS3pPbm40NGV3QUFBQUJCV0V0clRFdDZVbG8zY3pCRmNsbHJiVmxDWlEifQ==", + limit: 25, + }, + sort: "failure_rate", + }, + type: "search_flaky_tests_request", + }, + }, +}; + +(async () => { + try { + for await (const item of apiInstance.searchFlakyTestsWithPagination( + params + )) { + console.log(item); + } + } catch (error) { + console.error(error); + } +})(); diff --git a/examples/v2/test-optimization/SearchFlakyTests_2665223746.ts b/examples/v2/test-optimization/SearchFlakyTests_2665223746.ts new file mode 100644 index 000000000000..c24b146e95d6 --- /dev/null +++ b/examples/v2/test-optimization/SearchFlakyTests_2665223746.ts @@ -0,0 +1,38 @@ +/** + * Search flaky tests returns "OK" response with filtered query + */ + +import { client, v2 } from "@datadog/datadog-api-client"; + +const configuration = client.createConfiguration(); +configuration.unstableOperations["v2.searchFlakyTests"] = true; +const apiInstance = new v2.TestOptimizationApi(configuration); + +const params: v2.TestOptimizationApiSearchFlakyTestsRequest = { + body: { + data: { + attributes: { + filter: { + query: `flaky_test_state:active @git.repository.id_v2:"github.com/datadog/cart-tracking"`, + }, + page: { + limit: 10, + }, + sort: "-last_flaked", + }, + type: "search_flaky_tests_request", + }, + }, +}; + +(async () => { + try { + for await (const item of apiInstance.searchFlakyTestsWithPagination( + params + )) { + console.log(item); + } + } catch (error) { + console.error(error); + } +})(); diff --git a/features/support/scenarios_model_mapping.ts b/features/support/scenarios_model_mapping.ts index f6a2a5d9fc53..923349010113 100644 --- a/features/support/scenarios_model_mapping.ts +++ b/features/support/scenarios_model_mapping.ts @@ -8419,6 +8419,13 @@ export const ScenariosModelMappings: {[key: string]: {[key: string]: any}} = { }, "operationResponseType": "IncidentTeamResponse", }, + "v2.SearchFlakyTests": { + "body": { + "type": "FlakyTestsSearchRequest", + "format": "", + }, + "operationResponseType": "FlakyTestsSearchResponse", + }, "v2.SendInvitations": { "body": { "type": "UserInvitationsRequest", diff --git a/features/v2/test_optimization.feature b/features/v2/test_optimization.feature new file mode 100644 index 000000000000..18af1e9cad90 --- /dev/null +++ b/features/v2/test_optimization.feature @@ -0,0 +1,42 @@ +@endpoint(test-optimization) @endpoint(test-optimization-v2) +Feature: Test Optimization + Search and manage flaky tests through Test Optimization. See the [Test + Optimization page](https://docs.datadoghq.com/tests/) for more + information. + + Background: + Given a valid "apiKeyAuth" key in the system + And a valid "appKeyAuth" key in the system + And an instance of "TestOptimization" API + And operation "SearchFlakyTests" enabled + And new "SearchFlakyTests" request + + @generated @skip @team:DataDog/ci-app-backend + Scenario: Search flaky tests returns "Bad Request" response + Given body with value {"data": {"attributes": {"filter": {"query": "flaky_test_state:active @git.repository.id_v2:\"github.com/datadog/shopist\""}, "page": {"cursor": "eyJzdGFydEF0IjoiQVFBQUFYS2tMS3pPbm40NGV3QUFBQUJCV0V0clRFdDZVbG8zY3pCRmNsbHJiVmxDWlEifQ==", "limit": 25}, "sort": "failure_rate"}, "type": "search_flaky_tests_request"}} + When the request is sent + Then the response status is 400 Bad Request + + @skip @team:DataDog/ci-app-backend + Scenario: Search flaky tests returns "Bad Request" response with invalid limit + Given body with value {"data": {"attributes": {"filter": {"query": "*"}, "page": {"limit": 2000}, "sort": "fqn"}, "type": "search_flaky_tests_request"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/ci-app-backend + Scenario: Search flaky tests returns "OK" response + Given body with value {"data": {"attributes": {"filter": {"query": "flaky_test_state:active @git.repository.id_v2:\"github.com/datadog/shopist\""}, "page": {"cursor": "eyJzdGFydEF0IjoiQVFBQUFYS2tMS3pPbm40NGV3QUFBQUJCV0V0clRFdDZVbG8zY3pCRmNsbHJiVmxDWlEifQ==", "limit": 25}, "sort": "failure_rate"}, "type": "search_flaky_tests_request"}} + When the request is sent + Then the response status is 200 OK + + @replay-only @skip @skip-validation @team:DataDog/ci-app-backend @with-pagination + Scenario: Search flaky tests returns "OK" response with filtered query + Given body with value {"data": {"attributes": {"filter": {"query": "flaky_test_state:active @git.repository.id_v2:\"github.com/datadog/cart-tracking\""}, "page": {"limit": 10}, "sort": "-last_flaked"}, "type": "search_flaky_tests_request"}} + When the request with pagination is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/ci-app-backend @with-pagination + Scenario: Search flaky tests returns "OK" response with pagination + Given body with value {"data": {"attributes": {"filter": {"query": "flaky_test_state:active @git.repository.id_v2:\"github.com/datadog/shopist\""}, "page": {"cursor": "eyJzdGFydEF0IjoiQVFBQUFYS2tMS3pPbm40NGV3QUFBQUJCV0V0clRFdDZVbG8zY3pCRmNsbHJiVmxDWlEifQ==", "limit": 25}, "sort": "failure_rate"}, "type": "search_flaky_tests_request"}} + When the request with pagination is sent + Then the response status is 200 OK diff --git a/features/v2/undo.json b/features/v2/undo.json index 85202abf3460..92c07fe002e0 100644 --- a/features/v2/undo.json +++ b/features/v2/undo.json @@ -3978,6 +3978,12 @@ "type": "idempotent" } }, + "SearchFlakyTests": { + "tag": "Test Optimization", + "undo": { + "type": "safe" + } + }, "GetUsageApplicationSecurityMonitoring": { "tag": "Usage Metering", "undo": { diff --git a/packages/datadog-api-client-common/configuration.ts b/packages/datadog-api-client-common/configuration.ts index 6e7c9c22dc51..a5f3561eca57 100644 --- a/packages/datadog-api-client-common/configuration.ts +++ b/packages/datadog-api-client-common/configuration.ts @@ -327,6 +327,7 @@ export function createConfiguration( "v2.getIncidentTeam": false, "v2.listIncidentTeams": false, "v2.updateIncidentTeam": false, + "v2.searchFlakyTests": false, } ); configuration.httpApi.zstdCompressorCallback = conf.zstdCompressorCallback; diff --git a/packages/datadog-api-client-v2/apis/TestOptimizationApi.ts b/packages/datadog-api-client-v2/apis/TestOptimizationApi.ts new file mode 100644 index 000000000000..4122d9837556 --- /dev/null +++ b/packages/datadog-api-client-v2/apis/TestOptimizationApi.ts @@ -0,0 +1,240 @@ +import { BaseAPIRequestFactory } from "../../datadog-api-client-common/baseapi"; +import { + Configuration, + applySecurityAuthentication, +} from "../../datadog-api-client-common/configuration"; +import { + RequestContext, + HttpMethod, + ResponseContext, +} from "../../datadog-api-client-common/http/http"; + +import { logger } from "../../../logger"; +import { ObjectSerializer } from "../models/ObjectSerializer"; +import { ApiException } from "../../datadog-api-client-common/exception"; + +import { APIErrorResponse } from "../models/APIErrorResponse"; +import { FlakyTest } from "../models/FlakyTest"; +import { FlakyTestsSearchPageOptions } from "../models/FlakyTestsSearchPageOptions"; +import { FlakyTestsSearchRequest } from "../models/FlakyTestsSearchRequest"; +import { FlakyTestsSearchRequestAttributes } from "../models/FlakyTestsSearchRequestAttributes"; +import { FlakyTestsSearchRequestData } from "../models/FlakyTestsSearchRequestData"; +import { FlakyTestsSearchResponse } from "../models/FlakyTestsSearchResponse"; + +export class TestOptimizationApiRequestFactory extends BaseAPIRequestFactory { + public async searchFlakyTests( + body?: FlakyTestsSearchRequest, + _options?: Configuration + ): Promise { + const _config = _options || this.configuration; + + logger.warn("Using unstable operation 'searchFlakyTests'"); + if (!_config.unstableOperations["v2.searchFlakyTests"]) { + throw new Error("Unstable operation 'searchFlakyTests' is disabled"); + } + + // Path Params + const localVarPath = "/api/v2/test/flaky-test-management/tests"; + + // Make Request Context + const requestContext = _config + .getServer("v2.TestOptimizationApi.searchFlakyTests") + .makeRequestContext(localVarPath, HttpMethod.POST); + requestContext.setHeaderParam("Accept", "application/json"); + requestContext.setHttpConfig(_config.httpConfig); + + // Body Params + const contentType = ObjectSerializer.getPreferredMediaType([ + "application/json", + ]); + requestContext.setHeaderParam("Content-Type", contentType); + const serializedBody = ObjectSerializer.stringify( + ObjectSerializer.serialize(body, "FlakyTestsSearchRequest", ""), + contentType + ); + requestContext.setBody(serializedBody); + + // Apply auth methods + applySecurityAuthentication(_config, requestContext, [ + "apiKeyAuth", + "appKeyAuth", + "AuthZ", + ]); + + return requestContext; + } +} + +export class TestOptimizationApiResponseProcessor { + /** + * 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 searchFlakyTests + * @throws ApiException if the response code was not in [200, 299] + */ + public async searchFlakyTests( + response: ResponseContext + ): Promise { + const contentType = ObjectSerializer.normalizeMediaType( + response.headers["content-type"] + ); + if (response.httpStatusCode === 200) { + const body: FlakyTestsSearchResponse = ObjectSerializer.deserialize( + ObjectSerializer.parse(await response.body.text(), contentType), + "FlakyTestsSearchResponse" + ) as FlakyTestsSearchResponse; + return body; + } + if ( + response.httpStatusCode === 400 || + response.httpStatusCode === 403 || + response.httpStatusCode === 429 + ) { + const bodyText = ObjectSerializer.parse( + await response.body.text(), + contentType + ); + let body: APIErrorResponse; + try { + body = ObjectSerializer.deserialize( + bodyText, + "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: FlakyTestsSearchResponse = ObjectSerializer.deserialize( + ObjectSerializer.parse(await response.body.text(), contentType), + "FlakyTestsSearchResponse", + "" + ) as FlakyTestsSearchResponse; + return body; + } + + const body = (await response.body.text()) || ""; + throw new ApiException( + response.httpStatusCode, + 'Unknown API Status Code!\nBody: "' + body + '"' + ); + } +} + +export interface TestOptimizationApiSearchFlakyTestsRequest { + /** + * @type FlakyTestsSearchRequest + */ + body?: FlakyTestsSearchRequest; +} + +export class TestOptimizationApi { + private requestFactory: TestOptimizationApiRequestFactory; + private responseProcessor: TestOptimizationApiResponseProcessor; + private configuration: Configuration; + + public constructor( + configuration: Configuration, + requestFactory?: TestOptimizationApiRequestFactory, + responseProcessor?: TestOptimizationApiResponseProcessor + ) { + this.configuration = configuration; + this.requestFactory = + requestFactory || new TestOptimizationApiRequestFactory(configuration); + this.responseProcessor = + responseProcessor || new TestOptimizationApiResponseProcessor(); + } + + /** + * List endpoint returning flaky tests from Flaky Test Management. Results are paginated. + * @param param The request object + */ + public searchFlakyTests( + param: TestOptimizationApiSearchFlakyTestsRequest = {}, + options?: Configuration + ): Promise { + const requestContextPromise = this.requestFactory.searchFlakyTests( + param.body, + options + ); + return requestContextPromise.then((requestContext) => { + return this.configuration.httpApi + .send(requestContext) + .then((responseContext) => { + return this.responseProcessor.searchFlakyTests(responseContext); + }); + }); + } + + /** + * Provide a paginated version of searchFlakyTests returning a generator with all the items. + */ + public async *searchFlakyTestsWithPagination( + param: TestOptimizationApiSearchFlakyTestsRequest = {}, + options?: Configuration + ): AsyncGenerator { + let pageSize = 10; + if (param.body === undefined) { + param.body = new FlakyTestsSearchRequest(); + } + if (param.body.data === undefined) { + param.body.data = new FlakyTestsSearchRequestData(); + } + if (param.body.data.attributes === undefined) { + param.body.data.attributes = new FlakyTestsSearchRequestAttributes(); + } + if (param.body.data.attributes.page === undefined) { + param.body.data.attributes.page = new FlakyTestsSearchPageOptions(); + } + if (param.body.data.attributes.page.limit !== undefined) { + pageSize = param.body.data.attributes.page.limit; + } + param.body.data.attributes.page.limit = pageSize; + while (true) { + const requestContext = await this.requestFactory.searchFlakyTests( + param.body, + options + ); + const responseContext = await this.configuration.httpApi.send( + requestContext + ); + + const response = await this.responseProcessor.searchFlakyTests( + responseContext + ); + const responseData = response.data; + if (responseData === undefined) { + break; + } + const results = responseData; + for (const item of results) { + yield item; + } + if (results.length < pageSize) { + break; + } + const cursorMeta = response.meta; + if (cursorMeta === undefined) { + break; + } + const cursorMetaPagination = cursorMeta.pagination; + if (cursorMetaPagination === undefined) { + break; + } + const cursorMetaPaginationNextPage = cursorMetaPagination.nextPage; + if (cursorMetaPaginationNextPage === undefined) { + break; + } + + param.body.data.attributes.page.cursor = cursorMetaPaginationNextPage; + } + } +} diff --git a/packages/datadog-api-client-v2/index.ts b/packages/datadog-api-client-v2/index.ts index 00ff611c5045..c068002129fa 100644 --- a/packages/datadog-api-client-v2/index.ts +++ b/packages/datadog-api-client-v2/index.ts @@ -796,6 +796,11 @@ export { TeamsApi, } from "./apis/TeamsApi"; +export { + TestOptimizationApiSearchFlakyTestsRequest, + TestOptimizationApi, +} from "./apis/TestOptimizationApi"; + export { UsageMeteringApiGetBillingDimensionMappingRequest, UsageMeteringApiGetCostByOrgRequest, @@ -1927,6 +1932,23 @@ export { FindingRule } from "./models/FindingRule"; export { FindingStatus } from "./models/FindingStatus"; export { FindingType } from "./models/FindingType"; export { FindingVulnerabilityType } from "./models/FindingVulnerabilityType"; +export { FlakyTest } from "./models/FlakyTest"; +export { FlakyTestAttributes } from "./models/FlakyTestAttributes"; +export { FlakyTestAttributesFlakyState } from "./models/FlakyTestAttributesFlakyState"; +export { FlakyTestPipelineStats } from "./models/FlakyTestPipelineStats"; +export { FlakyTestRunMetadata } from "./models/FlakyTestRunMetadata"; +export { FlakyTestsPagination } from "./models/FlakyTestsPagination"; +export { FlakyTestsSearchFilter } from "./models/FlakyTestsSearchFilter"; +export { FlakyTestsSearchPageOptions } from "./models/FlakyTestsSearchPageOptions"; +export { FlakyTestsSearchRequest } from "./models/FlakyTestsSearchRequest"; +export { FlakyTestsSearchRequestAttributes } from "./models/FlakyTestsSearchRequestAttributes"; +export { FlakyTestsSearchRequestData } from "./models/FlakyTestsSearchRequestData"; +export { FlakyTestsSearchRequestDataType } from "./models/FlakyTestsSearchRequestDataType"; +export { FlakyTestsSearchResponse } from "./models/FlakyTestsSearchResponse"; +export { FlakyTestsSearchResponseMeta } from "./models/FlakyTestsSearchResponseMeta"; +export { FlakyTestsSearchSort } from "./models/FlakyTestsSearchSort"; +export { FlakyTestStats } from "./models/FlakyTestStats"; +export { FlakyTestType } from "./models/FlakyTestType"; export { FormulaLimit } from "./models/FormulaLimit"; export { FrameworkHandleAndVersionResponseData } from "./models/FrameworkHandleAndVersionResponseData"; export { FreshserviceAPIKey } from "./models/FreshserviceAPIKey"; diff --git a/packages/datadog-api-client-v2/models/FlakyTest.ts b/packages/datadog-api-client-v2/models/FlakyTest.ts new file mode 100644 index 000000000000..82981784ee82 --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTest.ts @@ -0,0 +1,70 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ +import { FlakyTestAttributes } from "./FlakyTestAttributes"; +import { FlakyTestType } from "./FlakyTestType"; + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * A flaky test object. + */ +export class FlakyTest { + /** + * Attributes of a flaky test. + */ + "attributes"?: FlakyTestAttributes; + /** + * Test's ID. This ID is the hash of the test's Fully Qualified Name and Git repository ID. On the Test Runs UI it is the same as the `test_fingerprint_fqn` tag. + */ + "id"?: string; + /** + * The type of the flaky test from Flaky Test Management. + */ + "type"?: FlakyTestType; + + /** + * 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: "FlakyTestAttributes", + }, + id: { + baseName: "id", + type: "string", + }, + type: { + baseName: "type", + type: "FlakyTestType", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return FlakyTest.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/FlakyTestAttributes.ts b/packages/datadog-api-client-v2/models/FlakyTestAttributes.ts new file mode 100644 index 000000000000..2f7ee1de87e7 --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestAttributes.ts @@ -0,0 +1,205 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ +import { FlakyTestAttributesFlakyState } from "./FlakyTestAttributesFlakyState"; +import { FlakyTestPipelineStats } from "./FlakyTestPipelineStats"; +import { FlakyTestRunMetadata } from "./FlakyTestRunMetadata"; +import { FlakyTestStats } from "./FlakyTestStats"; + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * Attributes of a flaky test. + */ +export class FlakyTestAttributes { + /** + * Unique identifier for the attempt to fix this flaky test. Use this ID in the Git commit message in order to trigger the attempt to fix workflow. + * + * When the workflow is triggered the test is automatically retried by the tracer a certain number of configurable times. When all retries pass, the test is automatically marked as fixed in Flaky Test Management. + * Test runs are tagged with @test.test_management.attempt_to_fix_passed and @test.test_management.is_attempt_to_fix when the attempt to fix workflow is triggered. + */ + "attemptToFixId"?: string; + /** + * The name of the test's code owners as inferred from the repository configuration. + */ + "codeowners"?: Array; + /** + * List of environments where this test has been flaky. + */ + "envs"?: Array; + /** + * The branch name where the test exhibited flakiness for the first time. + */ + "firstFlakedBranch"?: string; + /** + * The commit SHA where the test exhibited flakiness for the first time. + */ + "firstFlakedSha"?: string; + /** + * Unix timestamp when the test exhibited flakiness for the first time. + */ + "firstFlakedTs"?: number; + /** + * The category of a flaky test. + */ + "flakyCategory"?: string; + /** + * The current state of the flaky test. + */ + "flakyState"?: FlakyTestAttributesFlakyState; + /** + * The branch name where the test exhibited flakiness for the last time. + */ + "lastFlakedBranch"?: string; + /** + * The commit SHA where the test exhibited flakiness for the last time. + */ + "lastFlakedSha"?: string; + /** + * Unix timestamp when the test exhibited flakiness for the last time. + */ + "lastFlakedTs"?: number; + /** + * The name of the test module. The definition of module changes slightly per language: + * - In .NET, a test module groups every test that is run under the same unit test project. + * - In Swift, a test module groups every test that is run for a given bundle. + * - In JavaScript, the test modules map one-to-one to test sessions. + * - In Java, a test module groups every test that is run by the same Maven Surefire/Failsafe or Gradle Test task execution. + * - In Python, a test module groups every test that is run under the same `.py` file as part of a test suite, which is typically managed by a framework like `unittest` or `pytest`. + * - In Ruby, a test module groups every test that is run within the same test file, which is typically managed by a framework like `RSpec` or `Minitest`. + */ + "module"?: string; + /** + * The test name. A concise name for a test case. Defined in the test itself. + */ + "name"?: string; + /** + * CI pipeline related statistics for the flaky test. This information is only available if test runs are associated with CI pipeline events from CI Visibility. + */ + "pipelineStats"?: FlakyTestPipelineStats; + /** + * List of test service names where this test has been flaky. + * + * A test service is a group of tests associated with a project or repository. It contains all the individual tests for your code, optionally organized into test suites, which are like folders for your tests. + */ + "services"?: Array; + /** + * The name of the test suite. A group of tests exercising the same unit of code depending on your language and testing framework. + */ + "suite"?: string; + /** + * Metadata about the latest failed test run of the flaky test. + */ + "testRunMetadata"?: FlakyTestRunMetadata; + /** + * Test statistics for the flaky test. + */ + "testStats"?: FlakyTestStats; + + /** + * 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 = { + attemptToFixId: { + baseName: "attempt_to_fix_id", + type: "string", + }, + codeowners: { + baseName: "codeowners", + type: "Array", + }, + envs: { + baseName: "envs", + type: "Array", + }, + firstFlakedBranch: { + baseName: "first_flaked_branch", + type: "string", + }, + firstFlakedSha: { + baseName: "first_flaked_sha", + type: "string", + }, + firstFlakedTs: { + baseName: "first_flaked_ts", + type: "number", + format: "int64", + }, + flakyCategory: { + baseName: "flaky_category", + type: "string", + }, + flakyState: { + baseName: "flaky_state", + type: "FlakyTestAttributesFlakyState", + }, + lastFlakedBranch: { + baseName: "last_flaked_branch", + type: "string", + }, + lastFlakedSha: { + baseName: "last_flaked_sha", + type: "string", + }, + lastFlakedTs: { + baseName: "last_flaked_ts", + type: "number", + format: "int64", + }, + module: { + baseName: "module", + type: "string", + }, + name: { + baseName: "name", + type: "string", + }, + pipelineStats: { + baseName: "pipeline_stats", + type: "FlakyTestPipelineStats", + }, + services: { + baseName: "services", + type: "Array", + }, + suite: { + baseName: "suite", + type: "string", + }, + testRunMetadata: { + baseName: "test_run_metadata", + type: "FlakyTestRunMetadata", + }, + testStats: { + baseName: "test_stats", + type: "FlakyTestStats", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return FlakyTestAttributes.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/FlakyTestAttributesFlakyState.ts b/packages/datadog-api-client-v2/models/FlakyTestAttributesFlakyState.ts new file mode 100644 index 000000000000..76f8ce17cc39 --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestAttributesFlakyState.ts @@ -0,0 +1,22 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ + +import { UnparsedObject } from "../../datadog-api-client-common/util"; + +/** + * The current state of the flaky test. + */ + +export type FlakyTestAttributesFlakyState = + | typeof ACTIVE + | typeof FIXED + | typeof QUARANTINED + | typeof DISABLED + | UnparsedObject; +export const ACTIVE = "active"; +export const FIXED = "fixed"; +export const QUARANTINED = "quarantined"; +export const DISABLED = "disabled"; diff --git a/packages/datadog-api-client-v2/models/FlakyTestPipelineStats.ts b/packages/datadog-api-client-v2/models/FlakyTestPipelineStats.ts new file mode 100644 index 000000000000..e56a637f45fe --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestPipelineStats.ts @@ -0,0 +1,62 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * CI pipeline related statistics for the flaky test. This information is only available if test runs are associated with CI pipeline events from CI Visibility. + */ +export class FlakyTestPipelineStats { + /** + * The number of pipelines that failed due to this test for the past 7 days. This is computed as the sum of failed CI pipeline events associated with test runs where the flaky test failed. + */ + "failedPipelines"?: number; + /** + * The total time lost by CI pipelines due to this flaky test in milliseconds. This is computed as the sum of the duration of failed CI pipeline events associated with test runs where the flaky test failed. + */ + "totalLostTimeMs"?: 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 = { + failedPipelines: { + baseName: "failed_pipelines", + type: "number", + format: "int64", + }, + totalLostTimeMs: { + baseName: "total_lost_time_ms", + type: "number", + format: "int64", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return FlakyTestPipelineStats.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/FlakyTestRunMetadata.ts b/packages/datadog-api-client-v2/models/FlakyTestRunMetadata.ts new file mode 100644 index 000000000000..070cf560242a --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestRunMetadata.ts @@ -0,0 +1,95 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * Metadata about the latest failed test run of the flaky test. + */ +export class FlakyTestRunMetadata { + /** + * The duration of the test run in milliseconds. + */ + "durationMs"?: number; + /** + * The error message from the test failure. + */ + "errorMessage"?: string; + /** + * The stack trace from the test failure. + */ + "errorStack"?: string; + /** + * The line number where the test ends in the source file. + */ + "sourceEnd"?: number; + /** + * The source file where the test is defined. + */ + "sourceFile"?: string; + /** + * The line number where the test starts in the source file. + */ + "sourceStart"?: 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 = { + durationMs: { + baseName: "duration_ms", + type: "number", + format: "int64", + }, + errorMessage: { + baseName: "error_message", + type: "string", + }, + errorStack: { + baseName: "error_stack", + type: "string", + }, + sourceEnd: { + baseName: "source_end", + type: "number", + format: "int64", + }, + sourceFile: { + baseName: "source_file", + type: "string", + }, + sourceStart: { + baseName: "source_start", + type: "number", + format: "int64", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return FlakyTestRunMetadata.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/FlakyTestStats.ts b/packages/datadog-api-client-v2/models/FlakyTestStats.ts new file mode 100644 index 000000000000..ac34d43a7211 --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestStats.ts @@ -0,0 +1,53 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * Test statistics for the flaky test. + */ +export class FlakyTestStats { + /** + * The failure rate percentage of the test for the past 7 days. This is the number of failed test runs divided by the total number of test runs (excluding skipped test runs). + */ + "failureRatePct"?: 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 = { + failureRatePct: { + baseName: "failure_rate_pct", + type: "number", + format: "double", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return FlakyTestStats.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/FlakyTestType.ts b/packages/datadog-api-client-v2/models/FlakyTestType.ts new file mode 100644 index 000000000000..b99d1ae2061b --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestType.ts @@ -0,0 +1,14 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ + +import { UnparsedObject } from "../../datadog-api-client-common/util"; + +/** + * The type of the flaky test from Flaky Test Management. + */ + +export type FlakyTestType = typeof FLAKY_TEST | UnparsedObject; +export const FLAKY_TEST = "flaky_test"; diff --git a/packages/datadog-api-client-v2/models/FlakyTestsPagination.ts b/packages/datadog-api-client-v2/models/FlakyTestsPagination.ts new file mode 100644 index 000000000000..87a1f3cd6999 --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestsPagination.ts @@ -0,0 +1,52 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * Pagination metadata for flaky tests. + */ +export class FlakyTestsPagination { + /** + * Cursor for the next page of results. + */ + "nextPage"?: 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 = { + nextPage: { + baseName: "next_page", + type: "string", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return FlakyTestsPagination.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/FlakyTestsSearchFilter.ts b/packages/datadog-api-client-v2/models/FlakyTestsSearchFilter.ts new file mode 100644 index 000000000000..361fddd6e38c --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestsSearchFilter.ts @@ -0,0 +1,62 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * Search filter settings. + */ +export class FlakyTestsSearchFilter { + /** + * Search query following log syntax used to filter flaky tests, same as on Flaky Tests Management UI. The supported search keys are: + * - `flaky_test_state` + * - `flaky_test_category` + * - `@test.name` + * - `@test.suite` + * - `@test.module` + * - `@test.service` + * - `@git.repository.id_v2` + * - `@git.branch` + * - `@test.codeowners` + * - `env` + */ + "query"?: 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 = { + query: { + baseName: "query", + type: "string", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return FlakyTestsSearchFilter.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/FlakyTestsSearchPageOptions.ts b/packages/datadog-api-client-v2/models/FlakyTestsSearchPageOptions.ts new file mode 100644 index 000000000000..22888709e3c9 --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestsSearchPageOptions.ts @@ -0,0 +1,61 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * Pagination attributes for listing flaky tests. + */ +export class FlakyTestsSearchPageOptions { + /** + * List following results with a cursor provided in the previous request. + */ + "cursor"?: string; + /** + * Maximum number of flaky tests in the response. + */ + "limit"?: 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 = { + cursor: { + baseName: "cursor", + type: "string", + }, + limit: { + baseName: "limit", + type: "number", + format: "int64", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return FlakyTestsSearchPageOptions.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/FlakyTestsSearchRequest.ts b/packages/datadog-api-client-v2/models/FlakyTestsSearchRequest.ts new file mode 100644 index 000000000000..5573afaebb12 --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestsSearchRequest.ts @@ -0,0 +1,53 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ +import { FlakyTestsSearchRequestData } from "./FlakyTestsSearchRequestData"; + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * The request for a flaky tests search. + */ +export class FlakyTestsSearchRequest { + /** + * The JSON:API data for flaky tests search request. + */ + "data"?: FlakyTestsSearchRequestData; + + /** + * 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: "FlakyTestsSearchRequestData", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return FlakyTestsSearchRequest.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/FlakyTestsSearchRequestAttributes.ts b/packages/datadog-api-client-v2/models/FlakyTestsSearchRequestAttributes.ts new file mode 100644 index 000000000000..c84f6b7c952a --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestsSearchRequestAttributes.ts @@ -0,0 +1,71 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ +import { FlakyTestsSearchFilter } from "./FlakyTestsSearchFilter"; +import { FlakyTestsSearchPageOptions } from "./FlakyTestsSearchPageOptions"; +import { FlakyTestsSearchSort } from "./FlakyTestsSearchSort"; + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * Attributes for the flaky tests search request. + */ +export class FlakyTestsSearchRequestAttributes { + /** + * Search filter settings. + */ + "filter"?: FlakyTestsSearchFilter; + /** + * Pagination attributes for listing flaky tests. + */ + "page"?: FlakyTestsSearchPageOptions; + /** + * Parameter for sorting flaky test results. The default sort is by ascending Fully Qualified Name (FQN). The FQN is the concatenation of the test module, suite, and name. + */ + "sort"?: FlakyTestsSearchSort; + + /** + * 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 = { + filter: { + baseName: "filter", + type: "FlakyTestsSearchFilter", + }, + page: { + baseName: "page", + type: "FlakyTestsSearchPageOptions", + }, + sort: { + baseName: "sort", + type: "FlakyTestsSearchSort", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return FlakyTestsSearchRequestAttributes.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/FlakyTestsSearchRequestData.ts b/packages/datadog-api-client-v2/models/FlakyTestsSearchRequestData.ts new file mode 100644 index 000000000000..398a21240da6 --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestsSearchRequestData.ts @@ -0,0 +1,62 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ +import { FlakyTestsSearchRequestAttributes } from "./FlakyTestsSearchRequestAttributes"; +import { FlakyTestsSearchRequestDataType } from "./FlakyTestsSearchRequestDataType"; + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * The JSON:API data for flaky tests search request. + */ +export class FlakyTestsSearchRequestData { + /** + * Attributes for the flaky tests search request. + */ + "attributes"?: FlakyTestsSearchRequestAttributes; + /** + * The definition of `FlakyTestsSearchRequestDataType` object. + */ + "type"?: FlakyTestsSearchRequestDataType; + + /** + * 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: "FlakyTestsSearchRequestAttributes", + }, + type: { + baseName: "type", + type: "FlakyTestsSearchRequestDataType", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return FlakyTestsSearchRequestData.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/FlakyTestsSearchRequestDataType.ts b/packages/datadog-api-client-v2/models/FlakyTestsSearchRequestDataType.ts new file mode 100644 index 000000000000..5a26be9b9d61 --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestsSearchRequestDataType.ts @@ -0,0 +1,16 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ + +import { UnparsedObject } from "../../datadog-api-client-common/util"; + +/** + * The definition of `FlakyTestsSearchRequestDataType` object. + */ + +export type FlakyTestsSearchRequestDataType = + | typeof SEARCH_FLAKY_TESTS_REQUEST + | UnparsedObject; +export const SEARCH_FLAKY_TESTS_REQUEST = "search_flaky_tests_request"; diff --git a/packages/datadog-api-client-v2/models/FlakyTestsSearchResponse.ts b/packages/datadog-api-client-v2/models/FlakyTestsSearchResponse.ts new file mode 100644 index 000000000000..b96d242d674a --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestsSearchResponse.ts @@ -0,0 +1,62 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ +import { FlakyTest } from "./FlakyTest"; +import { FlakyTestsSearchResponseMeta } from "./FlakyTestsSearchResponseMeta"; + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * Response object with flaky tests matching the search request. + */ +export class FlakyTestsSearchResponse { + /** + * Array of flaky tests matching the request. + */ + "data"?: Array; + /** + * Metadata for the flaky tests search response. + */ + "meta"?: FlakyTestsSearchResponseMeta; + + /** + * 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: "FlakyTestsSearchResponseMeta", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return FlakyTestsSearchResponse.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/FlakyTestsSearchResponseMeta.ts b/packages/datadog-api-client-v2/models/FlakyTestsSearchResponseMeta.ts new file mode 100644 index 000000000000..6beaa44c6835 --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestsSearchResponseMeta.ts @@ -0,0 +1,53 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ +import { FlakyTestsPagination } from "./FlakyTestsPagination"; + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * Metadata for the flaky tests search response. + */ +export class FlakyTestsSearchResponseMeta { + /** + * Pagination metadata for flaky tests. + */ + "pagination"?: FlakyTestsPagination; + + /** + * 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 = { + pagination: { + baseName: "pagination", + type: "FlakyTestsPagination", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return FlakyTestsSearchResponseMeta.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/FlakyTestsSearchSort.ts b/packages/datadog-api-client-v2/models/FlakyTestsSearchSort.ts new file mode 100644 index 000000000000..abf4b0eae6db --- /dev/null +++ b/packages/datadog-api-client-v2/models/FlakyTestsSearchSort.ts @@ -0,0 +1,38 @@ +/** + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2020-Present Datadog, Inc. + */ + +import { UnparsedObject } from "../../datadog-api-client-common/util"; + +/** + * Parameter for sorting flaky test results. The default sort is by ascending Fully Qualified Name (FQN). The FQN is the concatenation of the test module, suite, and name. + */ + +export type FlakyTestsSearchSort = + | typeof FQN_ASCENDING + | typeof FQN_DESCENDING + | typeof FIRST_FLAKED_ASCENDING + | typeof FIRST_FLAKED_DESCENDING + | typeof LAST_FLAKED_ASCENDING + | typeof LAST_FLAKED_DESCENDING + | typeof FAILURE_RATE_ASCENDING + | typeof FAILURE_RATE_DESCENDING + | typeof PIPELINES_FAILED_ASCENDING + | typeof PIPELINES_FAILED_DESCENDING + | typeof PIPELINES_DURATION_LOST_ASCENDING + | typeof PIPELINES_DURATION_LOST_DESCENDING + | UnparsedObject; +export const FQN_ASCENDING = "fqn"; +export const FQN_DESCENDING = "-fqn"; +export const FIRST_FLAKED_ASCENDING = "first_flaked"; +export const FIRST_FLAKED_DESCENDING = "-first_flaked"; +export const LAST_FLAKED_ASCENDING = "last_flaked"; +export const LAST_FLAKED_DESCENDING = "-last_flaked"; +export const FAILURE_RATE_ASCENDING = "failure_rate"; +export const FAILURE_RATE_DESCENDING = "-failure_rate"; +export const PIPELINES_FAILED_ASCENDING = "pipelines_failed"; +export const PIPELINES_FAILED_DESCENDING = "-pipelines_failed"; +export const PIPELINES_DURATION_LOST_ASCENDING = "pipelines_duration_lost"; +export const PIPELINES_DURATION_LOST_DESCENDING = "-pipelines_duration_lost"; diff --git a/packages/datadog-api-client-v2/models/ObjectSerializer.ts b/packages/datadog-api-client-v2/models/ObjectSerializer.ts index e6a204c0643c..1ae4682f71a3 100644 --- a/packages/datadog-api-client-v2/models/ObjectSerializer.ts +++ b/packages/datadog-api-client-v2/models/ObjectSerializer.ts @@ -816,6 +816,19 @@ import { Finding } from "./Finding"; import { FindingAttributes } from "./FindingAttributes"; import { FindingMute } from "./FindingMute"; import { FindingRule } from "./FindingRule"; +import { FlakyTest } from "./FlakyTest"; +import { FlakyTestAttributes } from "./FlakyTestAttributes"; +import { FlakyTestPipelineStats } from "./FlakyTestPipelineStats"; +import { FlakyTestRunMetadata } from "./FlakyTestRunMetadata"; +import { FlakyTestStats } from "./FlakyTestStats"; +import { FlakyTestsPagination } from "./FlakyTestsPagination"; +import { FlakyTestsSearchFilter } from "./FlakyTestsSearchFilter"; +import { FlakyTestsSearchPageOptions } from "./FlakyTestsSearchPageOptions"; +import { FlakyTestsSearchRequest } from "./FlakyTestsSearchRequest"; +import { FlakyTestsSearchRequestAttributes } from "./FlakyTestsSearchRequestAttributes"; +import { FlakyTestsSearchRequestData } from "./FlakyTestsSearchRequestData"; +import { FlakyTestsSearchResponse } from "./FlakyTestsSearchResponse"; +import { FlakyTestsSearchResponseMeta } from "./FlakyTestsSearchResponseMeta"; import { FormulaLimit } from "./FormulaLimit"; import { FrameworkHandleAndVersionResponseData } from "./FrameworkHandleAndVersionResponseData"; import { FreshserviceAPIKey } from "./FreshserviceAPIKey"; @@ -2819,6 +2832,23 @@ const enumsMap: { [key: string]: any[] } = { "identity_risk", "api_security", ], + FlakyTestAttributesFlakyState: ["active", "fixed", "quarantined", "disabled"], + FlakyTestType: ["flaky_test"], + FlakyTestsSearchRequestDataType: ["search_flaky_tests_request"], + FlakyTestsSearchSort: [ + "fqn", + "-fqn", + "first_flaked", + "-first_flaked", + "last_flaked", + "-last_flaked", + "failure_rate", + "-failure_rate", + "pipelines_failed", + "-pipelines_failed", + "pipelines_duration_lost", + "-pipelines_duration_lost", + ], FreshserviceAPIKeyType: ["FreshserviceAPIKey"], FreshserviceIntegrationType: ["Freshservice"], GCPIntegrationType: ["GCP"], @@ -4832,6 +4862,19 @@ const typeMap: { [index: string]: any } = { FindingAttributes: FindingAttributes, FindingMute: FindingMute, FindingRule: FindingRule, + FlakyTest: FlakyTest, + FlakyTestAttributes: FlakyTestAttributes, + FlakyTestPipelineStats: FlakyTestPipelineStats, + FlakyTestRunMetadata: FlakyTestRunMetadata, + FlakyTestStats: FlakyTestStats, + FlakyTestsPagination: FlakyTestsPagination, + FlakyTestsSearchFilter: FlakyTestsSearchFilter, + FlakyTestsSearchPageOptions: FlakyTestsSearchPageOptions, + FlakyTestsSearchRequest: FlakyTestsSearchRequest, + FlakyTestsSearchRequestAttributes: FlakyTestsSearchRequestAttributes, + FlakyTestsSearchRequestData: FlakyTestsSearchRequestData, + FlakyTestsSearchResponse: FlakyTestsSearchResponse, + FlakyTestsSearchResponseMeta: FlakyTestsSearchResponseMeta, FormulaLimit: FormulaLimit, FrameworkHandleAndVersionResponseData: FrameworkHandleAndVersionResponseData, FreshserviceAPIKey: FreshserviceAPIKey,