Update flaky test states

PATCH https://api.ap1.datadoghq.com/api/v2/test/flaky-test-management/testshttps://api.ap2.datadoghq.com/api/v2/test/flaky-test-management/testshttps://api.datadoghq.eu/api/v2/test/flaky-test-management/testshttps://api.ddog-gov.com/api/v2/test/flaky-test-management/testshttps://api.us2.ddog-gov.com/api/v2/test/flaky-test-management/testshttps://api.datadoghq.com/api/v2/test/flaky-test-management/testshttps://api.us3.datadoghq.com/api/v2/test/flaky-test-management/testshttps://api.us5.datadoghq.com/api/v2/test/flaky-test-management/tests

Overview

Update the state of multiple flaky tests in Flaky Test Management. This endpoint requires the test_optimization_write permission.

OAuth apps require the test_optimization_write authorization scope to access this endpoint.

Request

Body Data (required)

Expand All

Field

Type

Description

data [required]

object

The JSON:API data for updating flaky test states.

attributes [required]

object

Attributes for updating flaky test states.

tests [required]

[object]

List of flaky tests to update.

id [required]

string

The ID of the flaky test. This is the same ID returned by the Search flaky tests endpoint and corresponds to the test_fingerprint_fqn field in test run events.

new_state [required]

enum

The new state to set for the flaky test. Allowed enum values: active,quarantined,disabled,fixed

type [required]

enum

The definition of UpdateFlakyTestsRequestDataType object. Allowed enum values: update_flaky_test_state_request

{
  "data": {
    "attributes": {
      "tests": [
        {
          "id": "4eb1887a8adb1847",
          "new_state": "active"
        }
      ]
    },
    "type": "update_flaky_test_state_request"
  }
}

Response

OK

Response object for updating flaky test states.

Expand All

Field

Type

Description

data

object

Summary of the update operations. Tells whether a test succeeded or failed to be updated.

attributes

object

Attributes for the update flaky test state response.

has_errors [required]

boolean

True if any errors occurred during the update operations. False if all tests succeeded to be updated.

results [required]

[object]

Results of the update operation for each test.

error

string

Error message if the update failed.

id [required]

string

The ID of the flaky test from the request. This is the same ID returned by the Search flaky tests endpoint and corresponds to the test_fingerprint_fqn field in test run events.

success [required]

boolean

True if the update was successful, False if there were any errors.

id

string

The ID of the response.

type

enum

The definition of UpdateFlakyTestsResponseDataType object. Allowed enum values: update_flaky_test_state_response

{
  "data": {
    "attributes": {
      "has_errors": true,
      "results": [
        {
          "error": "string",
          "id": "4eb1887a8adb1847",
          "success": false
        }
      ]
    },
    "id": "string",
    "type": "string"
  }
}

Bad Request

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Not Authorized

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Code Example

                  ## default
# 

# Curl command
curl -X PATCH "https://api.ap1.datadoghq.com"https://api.ap2.datadoghq.com"https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.us2.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com"https://api.us5.datadoghq.com/api/v2/test/flaky-test-management/tests" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "DD-API-KEY: ${DD_API_KEY}" \ -H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \ -d @- << EOF { "data": { "attributes": { "tests": [ { "id": "4eb1887a8adb1847", "new_state": "active" } ] }, "type": "update_flaky_test_state_request" } } EOF
"""
Update flaky test states returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.test_optimization_api import TestOptimizationApi
from datadog_api_client.v2.model.update_flaky_tests_request import UpdateFlakyTestsRequest
from datadog_api_client.v2.model.update_flaky_tests_request_attributes import UpdateFlakyTestsRequestAttributes
from datadog_api_client.v2.model.update_flaky_tests_request_data import UpdateFlakyTestsRequestData
from datadog_api_client.v2.model.update_flaky_tests_request_data_type import UpdateFlakyTestsRequestDataType
from datadog_api_client.v2.model.update_flaky_tests_request_test import UpdateFlakyTestsRequestTest
from datadog_api_client.v2.model.update_flaky_tests_request_test_new_state import UpdateFlakyTestsRequestTestNewState

body = UpdateFlakyTestsRequest(
    data=UpdateFlakyTestsRequestData(
        attributes=UpdateFlakyTestsRequestAttributes(
            tests=[
                UpdateFlakyTestsRequestTest(
                    id="4eb1887a8adb1847",
                    new_state=UpdateFlakyTestsRequestTestNewState.ACTIVE,
                ),
            ],
        ),
        type=UpdateFlakyTestsRequestDataType.UPDATE_FLAKY_TEST_STATE_REQUEST,
    ),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = TestOptimizationApi(api_client)
    response = api_instance.update_flaky_tests(body=body)

    print(response)

Instructions

First install the library and its dependencies and then save the example to example.py and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" python3 "example.py"
# Update flaky test states returns "OK" response

require "datadog_api_client"
api_instance = DatadogAPIClient::V2::TestOptimizationAPI.new

body = DatadogAPIClient::V2::UpdateFlakyTestsRequest.new({
  data: DatadogAPIClient::V2::UpdateFlakyTestsRequestData.new({
    attributes: DatadogAPIClient::V2::UpdateFlakyTestsRequestAttributes.new({
      tests: [
        DatadogAPIClient::V2::UpdateFlakyTestsRequestTest.new({
          id: "4eb1887a8adb1847",
          new_state: DatadogAPIClient::V2::UpdateFlakyTestsRequestTestNewState::ACTIVE,
        }),
      ],
    }),
    type: DatadogAPIClient::V2::UpdateFlakyTestsRequestDataType::UPDATE_FLAKY_TEST_STATE_REQUEST,
  }),
})
p api_instance.update_flaky_tests(body)

Instructions

First install the library and its dependencies and then save the example to example.rb and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" rb "example.rb"
// Update flaky test states returns "OK" response

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
	body := datadogV2.UpdateFlakyTestsRequest{
		Data: datadogV2.UpdateFlakyTestsRequestData{
			Attributes: datadogV2.UpdateFlakyTestsRequestAttributes{
				Tests: []datadogV2.UpdateFlakyTestsRequestTest{
					{
						Id:       "4eb1887a8adb1847",
						NewState: datadogV2.UPDATEFLAKYTESTSREQUESTTESTNEWSTATE_ACTIVE,
					},
				},
			},
			Type: datadogV2.UPDATEFLAKYTESTSREQUESTDATATYPE_UPDATE_FLAKY_TEST_STATE_REQUEST,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewTestOptimizationApi(apiClient)
	resp, r, err := api.UpdateFlakyTests(ctx, body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `TestOptimizationApi.UpdateFlakyTests`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `TestOptimizationApi.UpdateFlakyTests`:\n%s\n", responseContent)
}

Instructions

First install the library and its dependencies and then save the example to main.go and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" go run "main.go"
// Update flaky test states returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.TestOptimizationApi;
import com.datadog.api.client.v2.model.UpdateFlakyTestsRequest;
import com.datadog.api.client.v2.model.UpdateFlakyTestsRequestAttributes;
import com.datadog.api.client.v2.model.UpdateFlakyTestsRequestData;
import com.datadog.api.client.v2.model.UpdateFlakyTestsRequestDataType;
import com.datadog.api.client.v2.model.UpdateFlakyTestsRequestTest;
import com.datadog.api.client.v2.model.UpdateFlakyTestsRequestTestNewState;
import com.datadog.api.client.v2.model.UpdateFlakyTestsResponse;
import java.util.Collections;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    TestOptimizationApi apiInstance = new TestOptimizationApi(defaultClient);

    UpdateFlakyTestsRequest body =
        new UpdateFlakyTestsRequest()
            .data(
                new UpdateFlakyTestsRequestData()
                    .attributes(
                        new UpdateFlakyTestsRequestAttributes()
                            .tests(
                                Collections.singletonList(
                                    new UpdateFlakyTestsRequestTest()
                                        .id("4eb1887a8adb1847")
                                        .newState(UpdateFlakyTestsRequestTestNewState.ACTIVE))))
                    .type(UpdateFlakyTestsRequestDataType.UPDATE_FLAKY_TEST_STATE_REQUEST));

    try {
      UpdateFlakyTestsResponse result = apiInstance.updateFlakyTests(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling TestOptimizationApi#updateFlakyTests");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Instructions

First install the library and its dependencies and then save the example to Example.java and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" java "Example.java"
// Update flaky test states returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_test_optimization::TestOptimizationAPI;
use datadog_api_client::datadogV2::model::UpdateFlakyTestsRequest;
use datadog_api_client::datadogV2::model::UpdateFlakyTestsRequestAttributes;
use datadog_api_client::datadogV2::model::UpdateFlakyTestsRequestData;
use datadog_api_client::datadogV2::model::UpdateFlakyTestsRequestDataType;
use datadog_api_client::datadogV2::model::UpdateFlakyTestsRequestTest;
use datadog_api_client::datadogV2::model::UpdateFlakyTestsRequestTestNewState;

#[tokio::main]
async fn main() {
    let body = UpdateFlakyTestsRequest::new(UpdateFlakyTestsRequestData::new(
        UpdateFlakyTestsRequestAttributes::new(vec![UpdateFlakyTestsRequestTest::new(
            "4eb1887a8adb1847".to_string(),
            UpdateFlakyTestsRequestTestNewState::ACTIVE,
        )]),
        UpdateFlakyTestsRequestDataType::UPDATE_FLAKY_TEST_STATE_REQUEST,
    ));
    let configuration = datadog::Configuration::new();
    let api = TestOptimizationAPI::with_config(configuration);
    let resp = api.update_flaky_tests(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}

Instructions

First install the library and its dependencies and then save the example to src/main.rs and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
/**
 * Update flaky test states returns "OK" response
 */

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration();
const apiInstance = new v2.TestOptimizationApi(configuration);

const params: v2.TestOptimizationApiUpdateFlakyTestsRequest = {
  body: {
    data: {
      attributes: {
        tests: [
          {
            id: "4eb1887a8adb1847",
            newState: "active",
          },
        ],
      },
      type: "update_flaky_test_state_request",
    },
  },
};

apiInstance
  .updateFlakyTests(params)
  .then((data: v2.UpdateFlakyTestsResponse) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));

Instructions

First install the library and its dependencies and then save the example to example.ts and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" tsc "example.ts"