Skip to content

Commit 9727dd3

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add history field to flaky test management API (#3462)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent abefb46 commit 9727dd3

File tree

9 files changed

+430
-5
lines changed

9 files changed

+430
-5
lines changed

.generator/schemas/v2/openapi.yaml

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24023,6 +24023,22 @@ components:
2402324023
type: string
2402424024
flaky_state:
2402524025
$ref: '#/components/schemas/FlakyTestAttributesFlakyState'
24026+
history:
24027+
description: 'Chronological history of status changes for this flaky test,
24028+
ordered from most recent to oldest.
24029+
24030+
Includes state transitions like new -> quarantined -> fixed, along with
24031+
the associated commit SHA when available.'
24032+
example:
24033+
- commit_sha: abc123def456
24034+
status: quarantined
24035+
timestamp: 1704067200000
24036+
- commit_sha: ''
24037+
status: new
24038+
timestamp: 1703980800000
24039+
items:
24040+
$ref: '#/components/schemas/FlakyTestHistory'
24041+
type: array
2402624042
last_flaked_branch:
2402724043
description: The branch name where the test exhibited flakiness for the
2402824044
last time.
@@ -24107,6 +24123,29 @@ components:
2410724123
- FIXED
2410824124
- QUARANTINED
2410924125
- DISABLED
24126+
FlakyTestHistory:
24127+
description: A single history entry representing a status change for a flaky
24128+
test.
24129+
properties:
24130+
commit_sha:
24131+
description: The commit SHA associated with this status change. Will be
24132+
an empty string if the commit SHA is not available.
24133+
example: abc123def456
24134+
type: string
24135+
status:
24136+
description: The test status at this point in history.
24137+
example: quarantined
24138+
type: string
24139+
timestamp:
24140+
description: Unix timestamp in milliseconds when this status change occurred.
24141+
example: 1704067200000
24142+
format: int64
24143+
type: integer
24144+
required:
24145+
- status
24146+
- commit_sha
24147+
- timestamp
24148+
type: object
2411024149
FlakyTestPipelineStats:
2411124150
description: CI pipeline related statistics for the flaky test. This information
2411224151
is only available if test runs are associated with CI pipeline events from
@@ -24253,6 +24292,17 @@ components:
2425324292
properties:
2425424293
filter:
2425524294
$ref: '#/components/schemas/FlakyTestsSearchFilter'
24295+
include_history:
24296+
default: false
24297+
description: 'Whether to include the status change history for each flaky
24298+
test in the response.
24299+
24300+
When set to true, each test will include a `history` array with chronological
24301+
status changes.
24302+
24303+
Defaults to false.'
24304+
example: true
24305+
type: boolean
2425624306
page:
2425724307
$ref: '#/components/schemas/FlakyTestsSearchPageOptions'
2425824308
sort:
@@ -101085,8 +101135,33 @@ paths:
101085101135

101086101136
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).'
101087101137
post:
101088-
description: List endpoint returning flaky tests from Flaky Test Management.
101138+
description: 'List endpoint returning flaky tests from Flaky Test Management.
101089101139
Results are paginated.
101140+
101141+
101142+
The response includes comprehensive test information including:
101143+
101144+
- Test identification and metadata (module, suite, name)
101145+
101146+
- Flaky state and categorization
101147+
101148+
- First and last flake occurrences (timestamp, branch, commit SHA)
101149+
101150+
- Test execution statistics from the last 7 days (failure rate)
101151+
101152+
- Pipeline impact metrics (failed pipelines count, total lost time)
101153+
101154+
- Complete status change history (optional, ordered from most recent to oldest)
101155+
101156+
101157+
Set `include_history` to `true` in the request to receive the status change
101158+
history for each test.
101159+
101160+
History is disabled by default for better performance.
101161+
101162+
101163+
Results support filtering by various facets including service, environment,
101164+
repository, branch, and test state.'
101090101165
operationId: SearchFlakyTests
101091101166
requestBody:
101092101167
content:

examples/v2/test-optimization/SearchFlakyTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static void main(String[] args) {
3131
"""
3232
flaky_test_state:active @git.repository.id_v2:"github.com/datadog/shopist"
3333
"""))
34+
.includeHistory(true)
3435
.page(
3536
new FlakyTestsSearchPageOptions()
3637
.cursor(

examples/v2/test-optimization/SearchFlakyTests_1224086727.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static void main(String[] args) {
3131
"""
3232
flaky_test_state:active @git.repository.id_v2:"github.com/datadog/shopist"
3333
"""))
34+
.includeHistory(true)
3435
.page(
3536
new FlakyTestsSearchPageOptions()
3637
.cursor(
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Search flaky tests returns "OK" response with history
2+
3+
import com.datadog.api.client.ApiClient;
4+
import com.datadog.api.client.ApiException;
5+
import com.datadog.api.client.v2.api.TestOptimizationApi;
6+
import com.datadog.api.client.v2.api.TestOptimizationApi.SearchFlakyTestsOptionalParameters;
7+
import com.datadog.api.client.v2.model.FlakyTestsSearchFilter;
8+
import com.datadog.api.client.v2.model.FlakyTestsSearchPageOptions;
9+
import com.datadog.api.client.v2.model.FlakyTestsSearchRequest;
10+
import com.datadog.api.client.v2.model.FlakyTestsSearchRequestAttributes;
11+
import com.datadog.api.client.v2.model.FlakyTestsSearchRequestData;
12+
import com.datadog.api.client.v2.model.FlakyTestsSearchRequestDataType;
13+
import com.datadog.api.client.v2.model.FlakyTestsSearchResponse;
14+
import com.datadog.api.client.v2.model.FlakyTestsSearchSort;
15+
16+
public class Example {
17+
public static void main(String[] args) {
18+
ApiClient defaultClient = ApiClient.getDefaultApiClient();
19+
defaultClient.setUnstableOperationEnabled("v2.searchFlakyTests", true);
20+
TestOptimizationApi apiInstance = new TestOptimizationApi(defaultClient);
21+
22+
FlakyTestsSearchRequest body =
23+
new FlakyTestsSearchRequest()
24+
.data(
25+
new FlakyTestsSearchRequestData()
26+
.attributes(
27+
new FlakyTestsSearchRequestAttributes()
28+
.filter(
29+
new FlakyTestsSearchFilter()
30+
.query(
31+
"""
32+
flaky_test_state:active @git.repository.id_v2:"github.com/datadog/shopist"
33+
"""))
34+
.page(new FlakyTestsSearchPageOptions().limit(10L))
35+
.sort(FlakyTestsSearchSort.FQN_ASCENDING)
36+
.includeHistory(true))
37+
.type(FlakyTestsSearchRequestDataType.SEARCH_FLAKY_TESTS_REQUEST));
38+
39+
try {
40+
FlakyTestsSearchResponse result =
41+
apiInstance.searchFlakyTests(new SearchFlakyTestsOptionalParameters().body(body));
42+
System.out.println(result);
43+
} catch (ApiException e) {
44+
System.err.println("Exception when calling TestOptimizationApi#searchFlakyTests");
45+
System.err.println("Status code: " + e.getCode());
46+
System.err.println("Reason: " + e.getResponseBody());
47+
System.err.println("Response headers: " + e.getResponseHeaders());
48+
e.printStackTrace();
49+
}
50+
}
51+
}

src/main/java/com/datadog/api/client/v2/api/TestOptimizationApi.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ public PaginationIterable<FlakyTest> searchFlakyTestsWithPagination(
197197
/**
198198
* List endpoint returning flaky tests from Flaky Test Management. Results are paginated.
199199
*
200+
* <p>The response includes comprehensive test information including: - Test identification and
201+
* metadata (module, suite, name) - Flaky state and categorization - First and last flake
202+
* occurrences (timestamp, branch, commit SHA) - Test execution statistics from the last 7 days
203+
* (failure rate) - Pipeline impact metrics (failed pipelines count, total lost time) - Complete
204+
* status change history (optional, ordered from most recent to oldest)
205+
*
206+
* <p>Set <code>include_history</code> to <code>true</code> in the request to receive the status
207+
* change history for each test. History is disabled by default for better performance.
208+
*
209+
* <p>Results support filtering by various facets including service, environment, repository,
210+
* branch, and test state.
211+
*
200212
* @param parameters Optional parameters for the request.
201213
* @return ApiResponse&lt;FlakyTestsSearchResponse&gt;
202214
* @throws ApiException if fails to make API call

src/main/java/com/datadog/api/client/v2/model/FlakyTestAttributes.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
FlakyTestAttributes.JSON_PROPERTY_FIRST_FLAKED_TS,
3030
FlakyTestAttributes.JSON_PROPERTY_FLAKY_CATEGORY,
3131
FlakyTestAttributes.JSON_PROPERTY_FLAKY_STATE,
32+
FlakyTestAttributes.JSON_PROPERTY_HISTORY,
3233
FlakyTestAttributes.JSON_PROPERTY_LAST_FLAKED_BRANCH,
3334
FlakyTestAttributes.JSON_PROPERTY_LAST_FLAKED_SHA,
3435
FlakyTestAttributes.JSON_PROPERTY_LAST_FLAKED_TS,
@@ -68,6 +69,9 @@ public class FlakyTestAttributes {
6869
public static final String JSON_PROPERTY_FLAKY_STATE = "flaky_state";
6970
private FlakyTestAttributesFlakyState flakyState;
7071

72+
public static final String JSON_PROPERTY_HISTORY = "history";
73+
private List<FlakyTestHistory> history = null;
74+
7175
public static final String JSON_PROPERTY_LAST_FLAKED_BRANCH = "last_flaked_branch";
7276
private String lastFlakedBranch;
7377

@@ -302,6 +306,41 @@ public void setFlakyState(FlakyTestAttributesFlakyState flakyState) {
302306
this.flakyState = flakyState;
303307
}
304308

309+
public FlakyTestAttributes history(List<FlakyTestHistory> history) {
310+
this.history = history;
311+
for (FlakyTestHistory item : history) {
312+
this.unparsed |= item.unparsed;
313+
}
314+
return this;
315+
}
316+
317+
public FlakyTestAttributes addHistoryItem(FlakyTestHistory historyItem) {
318+
if (this.history == null) {
319+
this.history = new ArrayList<>();
320+
}
321+
this.history.add(historyItem);
322+
this.unparsed |= historyItem.unparsed;
323+
return this;
324+
}
325+
326+
/**
327+
* Chronological history of status changes for this flaky test, ordered from most recent to
328+
* oldest. Includes state transitions like new -&gt; quarantined -&gt; fixed, along with the
329+
* associated commit SHA when available.
330+
*
331+
* @return history
332+
*/
333+
@jakarta.annotation.Nullable
334+
@JsonProperty(JSON_PROPERTY_HISTORY)
335+
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
336+
public List<FlakyTestHistory> getHistory() {
337+
return history;
338+
}
339+
340+
public void setHistory(List<FlakyTestHistory> history) {
341+
this.history = history;
342+
}
343+
305344
public FlakyTestAttributes lastFlakedBranch(String lastFlakedBranch) {
306345
this.lastFlakedBranch = lastFlakedBranch;
307346
return this;
@@ -611,6 +650,7 @@ public boolean equals(Object o) {
611650
&& Objects.equals(this.firstFlakedTs, flakyTestAttributes.firstFlakedTs)
612651
&& Objects.equals(this.flakyCategory, flakyTestAttributes.flakyCategory)
613652
&& Objects.equals(this.flakyState, flakyTestAttributes.flakyState)
653+
&& Objects.equals(this.history, flakyTestAttributes.history)
614654
&& Objects.equals(this.lastFlakedBranch, flakyTestAttributes.lastFlakedBranch)
615655
&& Objects.equals(this.lastFlakedSha, flakyTestAttributes.lastFlakedSha)
616656
&& Objects.equals(this.lastFlakedTs, flakyTestAttributes.lastFlakedTs)
@@ -635,6 +675,7 @@ public int hashCode() {
635675
firstFlakedTs,
636676
flakyCategory,
637677
flakyState,
678+
history,
638679
lastFlakedBranch,
639680
lastFlakedSha,
640681
lastFlakedTs,
@@ -660,6 +701,7 @@ public String toString() {
660701
sb.append(" firstFlakedTs: ").append(toIndentedString(firstFlakedTs)).append("\n");
661702
sb.append(" flakyCategory: ").append(toIndentedString(flakyCategory)).append("\n");
662703
sb.append(" flakyState: ").append(toIndentedString(flakyState)).append("\n");
704+
sb.append(" history: ").append(toIndentedString(history)).append("\n");
663705
sb.append(" lastFlakedBranch: ").append(toIndentedString(lastFlakedBranch)).append("\n");
664706
sb.append(" lastFlakedSha: ").append(toIndentedString(lastFlakedSha)).append("\n");
665707
sb.append(" lastFlakedTs: ").append(toIndentedString(lastFlakedTs)).append("\n");

0 commit comments

Comments
 (0)