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/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/README.md b/packages/datadog-api-client/README.md index 50e135144d54..151dc7767b8d 100644 --- a/packages/datadog-api-client/README.md +++ b/packages/datadog-api-client/README.md @@ -432,6 +432,7 @@ apiInstance | Synthetics | @datadog/datadog-api-client-synthetics | [README.md](../../services/synthetics/README.md) | | Tags | @datadog/datadog-api-client-tags | [README.md](../../services/tags/README.md) | | Teams | @datadog/datadog-api-client-teams | [README.md](../../services/teams/README.md) | +| Test Optimization | @datadog/datadog-api-client-test-optimization | [README.md](../../services/test-optimization/README.md) | | Usage Metering | @datadog/datadog-api-client-usage-metering | [README.md](../../services/usage-metering/README.md) | | Users | @datadog/datadog-api-client-users | [README.md](../../services/users/README.md) | | Webhooks Integration | @datadog/datadog-api-client-webhooks-integration | [README.md](../../services/webhooks-integration/README.md) | diff --git a/private/bdd_runner/src/support/scenarios_model_mapping.ts b/private/bdd_runner/src/support/scenarios_model_mapping.ts index 8c5e8bbb8595..6438d3aae191 100644 --- a/private/bdd_runner/src/support/scenarios_model_mapping.ts +++ b/private/bdd_runner/src/support/scenarios_model_mapping.ts @@ -8429,6 +8429,13 @@ export const ScenariosModelMappings: { [key: string]: OperationMapping } = { }, operationResponseType: "IncidentTeamResponse", }, + "TestOptimizationApi.V2.SearchFlakyTests": { + body: { + type: "FlakyTestsSearchRequest", + format: "", + }, + operationResponseType: "FlakyTestsSearchResponse", + }, "UsersApi.V2.SendInvitations": { body: { type: "UserInvitationsRequest", diff --git a/services/test_optimization/.yarnrc.yml b/services/test_optimization/.yarnrc.yml new file mode 100644 index 000000000000..3186f3f0795a --- /dev/null +++ b/services/test_optimization/.yarnrc.yml @@ -0,0 +1 @@ +nodeLinker: node-modules diff --git a/services/test_optimization/README.md b/services/test_optimization/README.md new file mode 100644 index 000000000000..8b5dd4ae6122 --- /dev/null +++ b/services/test_optimization/README.md @@ -0,0 +1,44 @@ +# @datadog/datadog-api-client-test-optimization + +## Description + +Search and manage flaky tests through Test Optimization. See the [Test Optimization page](https://docs.datadoghq.com/tests/) for more information. + +## Navigation + +- [Installation](#installation) +- [Getting Started](#getting-started) + +## Installation + +```sh +# NPM +npm install @datadog/datadog-api-client-test-optimization +# Yarn +yarn add @datadog/datadog-api-client-test-optimization +``` + +## Getting Started +```ts +import { createConfiguration } from "@datadog/datadog-api-client"; +import { TestOptimizationApiV2 } from "@datadog/datadog-api-client-test-optimization"; +import { v2 } from "@datadog/datadog-api-client-test-optimization"; + +const configuration = createConfiguration(); +// Enable unstable operations +const configurationOpts = { + unstableOperations: { + "TestOptimizationApi.v2.searchFlakyTests": true + } +} + +const configuration = createConfiguration(configurationOpts); +const apiInstance = new TestOptimizationApiV2(configuration); +const params = {/* parameters */}; + +apiInstance.searchFlakyTests(params).then((data) => { + console.log("API called successfully. Returned data: " + JSON.stringify(data)); +}).catch((error) => { + console.error("Error calling API: " + error); +}); +``` \ No newline at end of file diff --git a/services/test_optimization/package.json b/services/test_optimization/package.json new file mode 100644 index 000000000000..d89a084e96e2 --- /dev/null +++ b/services/test_optimization/package.json @@ -0,0 +1,43 @@ +{ + "name": "@datadog/datadog-api-client-test-optimization", + "description": "", + "author": "", + "keywords": [ + "api", + "fetch", + "typescript" + ], + "license": "Apache-2.0", + "licenses": [ + { + "type": "Apache-2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0" + } + ], + "repository": { + "type": "git", + "url": "https://github.com/DataDog/datadog-api-client-typescript.git", + "directory": "services/test-optimization" + }, + "files": [ + "dist/**/*" + ], + "main": "./dist/index.js", + "typings": "./dist/index.d.ts", + "scripts": { + "prepack": "yarn workspace @datadog/datadog-api-client build && yarn build", + "build": "yarn generate-version-files && tsc", + "generate-version-files": "node -p \"'export const version = ' + JSON.stringify(require('./package.json').version)\" > src/version.ts" + }, + "dependencies": { + "@datadog/datadog-api-client": "^2.0.0-beta.0" + }, + "devDependencies": { + "typescript": "5.8.3" + }, + "engines": { + "node": ">=18.0.0" + }, + "version": "0.0.1", + "packageManager": "yarn@4.9.1" +} diff --git a/services/test_optimization/src/index.ts b/services/test_optimization/src/index.ts new file mode 100644 index 000000000000..c45dd8b862c1 --- /dev/null +++ b/services/test_optimization/src/index.ts @@ -0,0 +1,3 @@ +export * as v2 from "./v2"; + +export { TestOptimizationApi as TestOptimizationApiV2 } from "./v2/TestOptimizationApi"; diff --git a/services/test_optimization/src/v2/TestOptimizationApi.ts b/services/test_optimization/src/v2/TestOptimizationApi.ts new file mode 100644 index 000000000000..2d2ca28187ee --- /dev/null +++ b/services/test_optimization/src/v2/TestOptimizationApi.ts @@ -0,0 +1,269 @@ +import { + ApiException, + BaseAPIRequestFactory, + BaseServerConfiguration, + buildUserAgent, + Configuration, + createConfiguration, + deserialize, + getPreferredMediaType, + HttpMethod, + isBrowser, + logger, + normalizeMediaType, + parse, + RequiredError, + RequestContext, + ResponseContext, + serialize, + ServerConfiguration, + stringify, + applySecurityAuthentication, +} from "@datadog/datadog-api-client"; + +import { TypingInfo } from "./models/TypingInfo"; +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"; +import { version } from "../version"; + +export class TestOptimizationApiRequestFactory extends BaseAPIRequestFactory { + public userAgent: string | undefined; + + public constructor(configuration: Configuration) { + super(configuration); + if (!isBrowser) { + this.userAgent = buildUserAgent("test-optimization", version); + } + } + public async searchFlakyTests( + body?: FlakyTestsSearchRequest, + _options?: Configuration, + ): Promise { + const _config = _options || this.configuration; + + if ( + !_config.unstableOperations["TestOptimizationApi.v2.searchFlakyTests"] + ) { + throw new Error( + "Unstable operation 'searchFlakyTests' is disabled. Enable it by setting `configuration.unstableOperations['TestOptimizationApi.v2.searchFlakyTests'] = true`", + ); + } + + // Path Params + const localVarPath = "/api/v2/test/flaky-test-management/tests"; + + // Make Request Context + const { server, overrides } = _config.getServerAndOverrides( + "TestOptimizationApi.v2.searchFlakyTests", + TestOptimizationApi.operationServers, + ); + const requestContext = server.makeRequestContext( + localVarPath, + HttpMethod.POST, + overrides, + ); + requestContext.setHeaderParam("Accept", "application/json"); + requestContext.setHttpConfig(_config.httpConfig); + + // Set User-Agent + if (this.userAgent) { + requestContext.setHeaderParam("User-Agent", this.userAgent); + } + + // Body Params + const contentType = getPreferredMediaType(["application/json"]); + requestContext.setHeaderParam("Content-Type", contentType); + const serializedBody = stringify( + serialize(body, TypingInfo, "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 = normalizeMediaType(response.headers["content-type"]); + if (response.httpStatusCode === 200) { + const body: FlakyTestsSearchResponse = deserialize( + parse(await response.body.text(), contentType), + TypingInfo, + "FlakyTestsSearchResponse", + ) as FlakyTestsSearchResponse; + return body; + } + if ( + response.httpStatusCode === 400 || + response.httpStatusCode === 403 || + 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: FlakyTestsSearchResponse = deserialize( + parse(await response.body.text(), contentType), + TypingInfo, + "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; + + static operationServers: { [key: string]: BaseServerConfiguration[] } = {}; + + public constructor( + configuration?: Configuration, + requestFactory?: TestOptimizationApiRequestFactory, + responseProcessor?: TestOptimizationApiResponseProcessor, + ) { + this.configuration = configuration || createConfiguration(); + this.requestFactory = + requestFactory || + new TestOptimizationApiRequestFactory(this.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/services/test_optimization/src/v2/index.ts b/services/test_optimization/src/v2/index.ts new file mode 100644 index 000000000000..6da8fc9070a0 --- /dev/null +++ b/services/test_optimization/src/v2/index.ts @@ -0,0 +1,23 @@ +export { + TestOptimizationApiSearchFlakyTestsRequest, + TestOptimizationApi, +} from "./TestOptimizationApi"; + +export { APIErrorResponse } from "./models/APIErrorResponse"; +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"; diff --git a/services/test_optimization/src/v2/models/APIErrorResponse.ts b/services/test_optimization/src/v2/models/APIErrorResponse.ts new file mode 100644 index 000000000000..58d6c35b80f0 --- /dev/null +++ b/services/test_optimization/src/v2/models/APIErrorResponse.ts @@ -0,0 +1,45 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +/** + * API error response. + */ +export class APIErrorResponse { + /** + * A list of errors. + */ + "errors": Array; + /** + * 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 = { + errors: { + baseName: "errors", + type: "Array", + required: true, + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return APIErrorResponse.attributeTypeMap; + } + + public constructor() {} +} diff --git a/services/test_optimization/src/v2/models/FlakyTest.ts b/services/test_optimization/src/v2/models/FlakyTest.ts new file mode 100644 index 000000000000..1369870fd45a --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTest.ts @@ -0,0 +1,63 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +import { FlakyTestAttributes } from "./FlakyTestAttributes"; +import { FlakyTestType } from "./FlakyTestType"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestAttributes.ts b/services/test_optimization/src/v2/models/FlakyTestAttributes.ts new file mode 100644 index 000000000000..8e9c72f166e7 --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestAttributes.ts @@ -0,0 +1,198 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +import { FlakyTestAttributesFlakyState } from "./FlakyTestAttributesFlakyState"; +import { FlakyTestPipelineStats } from "./FlakyTestPipelineStats"; +import { FlakyTestRunMetadata } from "./FlakyTestRunMetadata"; +import { FlakyTestStats } from "./FlakyTestStats"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestAttributesFlakyState.ts b/services/test_optimization/src/v2/models/FlakyTestAttributesFlakyState.ts new file mode 100644 index 000000000000..5e1547491512 --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestAttributesFlakyState.ts @@ -0,0 +1,15 @@ +import { UnparsedObject } from "@datadog/datadog-api-client"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestPipelineStats.ts b/services/test_optimization/src/v2/models/FlakyTestPipelineStats.ts new file mode 100644 index 000000000000..cb02d9a2e766 --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestPipelineStats.ts @@ -0,0 +1,54 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestRunMetadata.ts b/services/test_optimization/src/v2/models/FlakyTestRunMetadata.ts new file mode 100644 index 000000000000..34dbb57e24cb --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestRunMetadata.ts @@ -0,0 +1,87 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestStats.ts b/services/test_optimization/src/v2/models/FlakyTestStats.ts new file mode 100644 index 000000000000..5b320ba65fe3 --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestStats.ts @@ -0,0 +1,45 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestType.ts b/services/test_optimization/src/v2/models/FlakyTestType.ts new file mode 100644 index 000000000000..4efa581abc70 --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestType.ts @@ -0,0 +1,7 @@ +import { UnparsedObject } from "@datadog/datadog-api-client"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestsPagination.ts b/services/test_optimization/src/v2/models/FlakyTestsPagination.ts new file mode 100644 index 000000000000..9d2351a5a935 --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestsPagination.ts @@ -0,0 +1,44 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestsSearchFilter.ts b/services/test_optimization/src/v2/models/FlakyTestsSearchFilter.ts new file mode 100644 index 000000000000..88fdfff9875a --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestsSearchFilter.ts @@ -0,0 +1,54 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestsSearchPageOptions.ts b/services/test_optimization/src/v2/models/FlakyTestsSearchPageOptions.ts new file mode 100644 index 000000000000..67417b8bbec2 --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestsSearchPageOptions.ts @@ -0,0 +1,53 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestsSearchRequest.ts b/services/test_optimization/src/v2/models/FlakyTestsSearchRequest.ts new file mode 100644 index 000000000000..40dcc9d6bfce --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestsSearchRequest.ts @@ -0,0 +1,46 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +import { FlakyTestsSearchRequestData } from "./FlakyTestsSearchRequestData"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestsSearchRequestAttributes.ts b/services/test_optimization/src/v2/models/FlakyTestsSearchRequestAttributes.ts new file mode 100644 index 000000000000..17628301679b --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestsSearchRequestAttributes.ts @@ -0,0 +1,64 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +import { FlakyTestsSearchFilter } from "./FlakyTestsSearchFilter"; +import { FlakyTestsSearchPageOptions } from "./FlakyTestsSearchPageOptions"; +import { FlakyTestsSearchSort } from "./FlakyTestsSearchSort"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestsSearchRequestData.ts b/services/test_optimization/src/v2/models/FlakyTestsSearchRequestData.ts new file mode 100644 index 000000000000..3824bd1b9ce2 --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestsSearchRequestData.ts @@ -0,0 +1,55 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +import { FlakyTestsSearchRequestAttributes } from "./FlakyTestsSearchRequestAttributes"; +import { FlakyTestsSearchRequestDataType } from "./FlakyTestsSearchRequestDataType"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestsSearchRequestDataType.ts b/services/test_optimization/src/v2/models/FlakyTestsSearchRequestDataType.ts new file mode 100644 index 000000000000..2c0e32ea1ddd --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestsSearchRequestDataType.ts @@ -0,0 +1,9 @@ +import { UnparsedObject } from "@datadog/datadog-api-client"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestsSearchResponse.ts b/services/test_optimization/src/v2/models/FlakyTestsSearchResponse.ts new file mode 100644 index 000000000000..475036869881 --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestsSearchResponse.ts @@ -0,0 +1,55 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +import { FlakyTest } from "./FlakyTest"; +import { FlakyTestsSearchResponseMeta } from "./FlakyTestsSearchResponseMeta"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestsSearchResponseMeta.ts b/services/test_optimization/src/v2/models/FlakyTestsSearchResponseMeta.ts new file mode 100644 index 000000000000..1f0028e9f341 --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestsSearchResponseMeta.ts @@ -0,0 +1,46 @@ +import { AttributeTypeMap } from "@datadog/datadog-api-client"; + +import { FlakyTestsPagination } from "./FlakyTestsPagination"; + +/** + * 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/services/test_optimization/src/v2/models/FlakyTestsSearchSort.ts b/services/test_optimization/src/v2/models/FlakyTestsSearchSort.ts new file mode 100644 index 000000000000..3cd5afc5bf18 --- /dev/null +++ b/services/test_optimization/src/v2/models/FlakyTestsSearchSort.ts @@ -0,0 +1,31 @@ +import { UnparsedObject } from "@datadog/datadog-api-client"; + +/** + * 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/services/test_optimization/src/v2/models/TypingInfo.ts b/services/test_optimization/src/v2/models/TypingInfo.ts new file mode 100644 index 000000000000..5391a02d69e7 --- /dev/null +++ b/services/test_optimization/src/v2/models/TypingInfo.ts @@ -0,0 +1,60 @@ +import { ModelTypingInfo } from "@datadog/datadog-api-client"; + +import { APIErrorResponse } from "./APIErrorResponse"; +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"; + +export const TypingInfo: ModelTypingInfo = { + enumsMap: { + 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", + ], + }, + oneOfMap: {}, + typeMap: { + APIErrorResponse: APIErrorResponse, + 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, + }, +}; diff --git a/services/test_optimization/tsconfig.json b/services/test_optimization/tsconfig.json new file mode 100644 index 000000000000..d6c32bfb893c --- /dev/null +++ b/services/test_optimization/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "strict": true, + /* Basic Options */ + "target": "es6", + "module": "commonjs", + "moduleResolution": "node", + "declaration": true, + + "esModuleInterop": true, + "resolveJsonModule": true, + + "noImplicitAny": true, + "noImplicitThis": true, + + /* Additional Checks */ + "noUnusedLocals": false /* Report errors on unused locals. */, // TODO: reenable (unused imports!) + "noUnusedParameters": false /* Report errors on unused parameters. */, // TODO: set to true again + "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, + "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, + + "sourceMap": true, + "outDir": "./dist", + "lib": ["es6", "es7"] + }, + "exclude": ["dist", "node_modules", "tests"], + "include": ["src"] +} diff --git a/yarn.lock b/yarn.lock index 23ec86828961..bf2531de6d98 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1027,6 +1027,15 @@ __metadata: languageName: unknown linkType: soft +"@datadog/datadog-api-client-test-optimization@workspace:services/test_optimization": + version: 0.0.0-use.local + resolution: "@datadog/datadog-api-client-test-optimization@workspace:services/test_optimization" + dependencies: + "@datadog/datadog-api-client": "npm:^2.0.0-beta.0" + typescript: "npm:5.8.3" + languageName: unknown + linkType: soft + "@datadog/datadog-api-client-usage-metering@workspace:services/usage_metering": version: 0.0.0-use.local resolution: "@datadog/datadog-api-client-usage-metering@workspace:services/usage_metering"