diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 45c7a5c590..cb001b9022 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -26392,9 +26392,18 @@ components: Includes state transitions like new -> quarantined -> fixed, along with the associated commit SHA when available. example: - commit_sha: abc123def456 + policy_id: ftm_policy.quarantine.failure_rate + policy_meta: + config: + failure_rate: 0.1 + required_runs: 100 + failure_rate: 0.25 + total_runs: 200 status: quarantined timestamp: 1704067200000 - commit_sha: "" + policy_id: unknown + policy_meta: status: new timestamp: 1703980800000 items: @@ -26464,6 +26473,11 @@ components: description: The commit SHA associated with this status change. Will be an empty string if the commit SHA is not available. example: abc123def456 type: string + policy_id: + $ref: "#/components/schemas/FlakyTestHistoryPolicyId" + policy_meta: + $ref: "#/components/schemas/FlakyTestHistoryPolicyMeta" + nullable: true status: description: The test status at this point in history. example: quarantined @@ -26478,6 +26492,131 @@ components: - commit_sha - timestamp type: object + FlakyTestHistoryPolicyId: + description: The policy that triggered this status change. + enum: + - ftm_policy.manual + - ftm_policy.fixed + - ftm_policy.disable.failure_rate + - ftm_policy.disable.branch_flake + - ftm_policy.disable.days_active + - ftm_policy.quarantine.failure_rate + - ftm_policy.quarantine.branch_flake + - ftm_policy.quarantine.days_active + - unknown + example: ftm_policy.quarantine.failure_rate + nullable: false + type: string + x-enum-varnames: + - MANUAL + - FIXED + - DISABLE_FAILURE_RATE + - DISABLE_BRANCH_FLAKE + - DISABLE_DAYS_ACTIVE + - QUARANTINE_FAILURE_RATE + - QUARANTINE_BRANCH_FLAKE + - QUARANTINE_DAYS_ACTIVE + - UNKNOWN + FlakyTestHistoryPolicyMeta: + description: Metadata about the policy that triggered this status change. + properties: + branches: + description: Branches where the test was flaky at the time of the status change. + example: ["main", "develop"] + items: + type: string + nullable: true + type: array + config: + $ref: "#/components/schemas/FlakyTestHistoryPolicyMetaConfig" + nullable: true + days_active: + description: The number of days the test has been active at the time of the status change. + example: 15 + format: int32 + maximum: 2147483647 + nullable: true + type: integer + days_without_flake: + description: The number of days since the test last exhibited flakiness. + example: 30 + format: int32 + maximum: 2147483647 + nullable: true + type: integer + failure_rate: + description: The failure rate of the test at the time of the status change. + example: 0.25 + format: double + maximum: 1 + minimum: 0 + nullable: true + type: number + state: + description: The previous state of the test. + example: quarantined + nullable: true + type: string + total_runs: + description: The total number of test runs at the time of the status change. + example: 200 + format: int32 + maximum: 2147483647 + nullable: true + type: integer + type: object + FlakyTestHistoryPolicyMetaConfig: + description: Configuration parameters of the policy that triggered this status change. + properties: + branches: + description: The branches considered by the policy. + example: ["main"] + items: + type: string + nullable: true + type: array + days_active: + description: The number of days a test must have been active for the policy to trigger. + example: 30 + format: int32 + maximum: 2147483647 + nullable: true + type: integer + failure_rate: + description: The failure rate threshold for the policy to trigger. + example: 0.7 + format: double + maximum: 1 + minimum: 0 + nullable: true + type: number + forget_branches: + description: Branches excluded from the policy evaluation. + example: ["release"] + items: + type: string + nullable: true + type: array + required_runs: + description: The minimum number of test runs required for the policy to trigger. + example: 100 + format: int32 + maximum: 2147483647 + nullable: true + type: integer + state: + description: The target state the policy transitions the test from. + example: quarantined + nullable: true + type: string + test_services: + description: Test services excluded from the policy evaluation. + example: ["my-service"] + items: + type: string + nullable: true + type: array + type: object 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: @@ -26557,6 +26696,14 @@ components: FlakyTestsSearchFilter: description: Search filter settings. properties: + include_history: + default: false + description: |- + Whether to include the status change history for each flaky test in the response. + When set to true, each test will include a `history` array with chronological status changes. + Defaults to false. + example: true + type: boolean query: default: "*" description: |- @@ -26602,14 +26749,6 @@ components: properties: filter: $ref: "#/components/schemas/FlakyTestsSearchFilter" - include_history: - default: false - description: |- - Whether to include the status change history for each flaky test in the response. - When set to true, each test will include a `history` array with chronological status changes. - Defaults to false. - example: true - type: boolean page: $ref: "#/components/schemas/FlakyTestsSearchPageOptions" sort: diff --git a/examples/v2_test-optimization_SearchFlakyTests.rs b/examples/v2_test-optimization_SearchFlakyTests.rs index 02af77d0b5..11f46b3366 100644 --- a/examples/v2_test-optimization_SearchFlakyTests.rs +++ b/examples/v2_test-optimization_SearchFlakyTests.rs @@ -19,12 +19,12 @@ async fn main() { .attributes( FlakyTestsSearchRequestAttributes::new() .filter( - FlakyTestsSearchFilter - ::new().query( - r#"flaky_test_state:active @git.repository.id_v2:"github.com/datadog/shopist""#.to_string(), - ), + FlakyTestsSearchFilter::new() + .include_history(true) + .query( + r#"flaky_test_state:active @git.repository.id_v2:"github.com/datadog/shopist""#.to_string(), + ), ) - .include_history(true) .page( FlakyTestsSearchPageOptions::new() .cursor( diff --git a/examples/v2_test-optimization_SearchFlakyTests_1224086727.rs b/examples/v2_test-optimization_SearchFlakyTests_1224086727.rs index fed7915e54..7b22e4ac88 100644 --- a/examples/v2_test-optimization_SearchFlakyTests_1224086727.rs +++ b/examples/v2_test-optimization_SearchFlakyTests_1224086727.rs @@ -21,12 +21,12 @@ async fn main() { .attributes( FlakyTestsSearchRequestAttributes::new() .filter( - FlakyTestsSearchFilter - ::new().query( - r#"flaky_test_state:active @git.repository.id_v2:"github.com/datadog/shopist""#.to_string(), - ), + FlakyTestsSearchFilter::new() + .include_history(true) + .query( + r#"flaky_test_state:active @git.repository.id_v2:"github.com/datadog/shopist""#.to_string(), + ), ) - .include_history(true) .page( FlakyTestsSearchPageOptions::new() .cursor( diff --git a/examples/v2_test-optimization_SearchFlakyTests_209064879.rs b/examples/v2_test-optimization_SearchFlakyTests_209064879.rs index 498ba3cf9f..5c54ab3e6c 100644 --- a/examples/v2_test-optimization_SearchFlakyTests_209064879.rs +++ b/examples/v2_test-optimization_SearchFlakyTests_209064879.rs @@ -19,12 +19,12 @@ async fn main() { .attributes( FlakyTestsSearchRequestAttributes::new() .filter( - FlakyTestsSearchFilter - ::new().query( - r#"flaky_test_state:active @git.repository.id_v2:"github.com/datadog/shopist""#.to_string(), - ), + FlakyTestsSearchFilter::new() + .include_history(true) + .query( + r#"flaky_test_state:active @git.repository.id_v2:"github.com/datadog/shopist""#.to_string(), + ), ) - .include_history(true) .page(FlakyTestsSearchPageOptions::new().limit(10)) .sort(FlakyTestsSearchSort::FQN_ASCENDING), ) diff --git a/src/datadogV2/model/mod.rs b/src/datadogV2/model/mod.rs index f0689d162b..3068644c6f 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -9274,6 +9274,12 @@ pub mod model_flaky_test_attributes_flaky_state; pub use self::model_flaky_test_attributes_flaky_state::FlakyTestAttributesFlakyState; pub mod model_flaky_test_history; pub use self::model_flaky_test_history::FlakyTestHistory; +pub mod model_flaky_test_history_policy_id; +pub use self::model_flaky_test_history_policy_id::FlakyTestHistoryPolicyId; +pub mod model_flaky_test_history_policy_meta; +pub use self::model_flaky_test_history_policy_meta::FlakyTestHistoryPolicyMeta; +pub mod model_flaky_test_history_policy_meta_config; +pub use self::model_flaky_test_history_policy_meta_config::FlakyTestHistoryPolicyMetaConfig; pub mod model_flaky_test_pipeline_stats; pub use self::model_flaky_test_pipeline_stats::FlakyTestPipelineStats; pub mod model_flaky_test_run_metadata; diff --git a/src/datadogV2/model/model_flaky_test_history.rs b/src/datadogV2/model/model_flaky_test_history.rs index d51ea712d6..1cab04a3d1 100644 --- a/src/datadogV2/model/model_flaky_test_history.rs +++ b/src/datadogV2/model/model_flaky_test_history.rs @@ -14,6 +14,12 @@ pub struct FlakyTestHistory { /// The commit SHA associated with this status change. Will be an empty string if the commit SHA is not available. #[serde(rename = "commit_sha")] pub commit_sha: String, + /// The policy that triggered this status change. + #[serde(rename = "policy_id")] + pub policy_id: Option, + /// Metadata about the policy that triggered this status change. + #[serde(rename = "policy_meta")] + pub policy_meta: Option, /// The test status at this point in history. #[serde(rename = "status")] pub status: String, @@ -31,6 +37,8 @@ impl FlakyTestHistory { pub fn new(commit_sha: String, status: String, timestamp: i64) -> FlakyTestHistory { FlakyTestHistory { commit_sha, + policy_id: None, + policy_meta: None, status, timestamp, additional_properties: std::collections::BTreeMap::new(), @@ -38,6 +46,19 @@ impl FlakyTestHistory { } } + pub fn policy_id(mut self, value: crate::datadogV2::model::FlakyTestHistoryPolicyId) -> Self { + self.policy_id = Some(value); + self + } + + pub fn policy_meta( + mut self, + value: crate::datadogV2::model::FlakyTestHistoryPolicyMeta, + ) -> Self { + self.policy_meta = Some(value); + self + } + pub fn additional_properties( mut self, value: std::collections::BTreeMap, @@ -65,6 +86,9 @@ impl<'de> Deserialize<'de> for FlakyTestHistory { M: MapAccess<'a>, { let mut commit_sha: Option = None; + let mut policy_id: Option = None; + let mut policy_meta: Option = + None; let mut status: Option = None; let mut timestamp: Option = None; let mut additional_properties: std::collections::BTreeMap< @@ -78,6 +102,27 @@ impl<'de> Deserialize<'de> for FlakyTestHistory { "commit_sha" => { commit_sha = Some(serde_json::from_value(v).map_err(M::Error::custom)?); } + "policy_id" => { + if v.is_null() { + continue; + } + policy_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _policy_id) = policy_id { + match _policy_id { + crate::datadogV2::model::FlakyTestHistoryPolicyId::UnparsedObject(_policy_id) => { + _unparsed = true; + }, + _ => {} + } + } + } + "policy_meta" => { + if v.is_null() { + continue; + } + policy_meta = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } "status" => { status = Some(serde_json::from_value(v).map_err(M::Error::custom)?); } @@ -97,6 +142,8 @@ impl<'de> Deserialize<'de> for FlakyTestHistory { let content = FlakyTestHistory { commit_sha, + policy_id, + policy_meta, status, timestamp, additional_properties, diff --git a/src/datadogV2/model/model_flaky_test_history_policy_id.rs b/src/datadogV2/model/model_flaky_test_history_policy_id.rs new file mode 100644 index 0000000000..cfa8ebe7bc --- /dev/null +++ b/src/datadogV2/model/model_flaky_test_history_policy_id.rs @@ -0,0 +1,72 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum FlakyTestHistoryPolicyId { + MANUAL, + FIXED, + DISABLE_FAILURE_RATE, + DISABLE_BRANCH_FLAKE, + DISABLE_DAYS_ACTIVE, + QUARANTINE_FAILURE_RATE, + QUARANTINE_BRANCH_FLAKE, + QUARANTINE_DAYS_ACTIVE, + UNKNOWN, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for FlakyTestHistoryPolicyId { + fn to_string(&self) -> String { + match self { + Self::MANUAL => String::from("ftm_policy.manual"), + Self::FIXED => String::from("ftm_policy.fixed"), + Self::DISABLE_FAILURE_RATE => String::from("ftm_policy.disable.failure_rate"), + Self::DISABLE_BRANCH_FLAKE => String::from("ftm_policy.disable.branch_flake"), + Self::DISABLE_DAYS_ACTIVE => String::from("ftm_policy.disable.days_active"), + Self::QUARANTINE_FAILURE_RATE => String::from("ftm_policy.quarantine.failure_rate"), + Self::QUARANTINE_BRANCH_FLAKE => String::from("ftm_policy.quarantine.branch_flake"), + Self::QUARANTINE_DAYS_ACTIVE => String::from("ftm_policy.quarantine.days_active"), + Self::UNKNOWN => String::from("unknown"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for FlakyTestHistoryPolicyId { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for FlakyTestHistoryPolicyId { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "ftm_policy.manual" => Self::MANUAL, + "ftm_policy.fixed" => Self::FIXED, + "ftm_policy.disable.failure_rate" => Self::DISABLE_FAILURE_RATE, + "ftm_policy.disable.branch_flake" => Self::DISABLE_BRANCH_FLAKE, + "ftm_policy.disable.days_active" => Self::DISABLE_DAYS_ACTIVE, + "ftm_policy.quarantine.failure_rate" => Self::QUARANTINE_FAILURE_RATE, + "ftm_policy.quarantine.branch_flake" => Self::QUARANTINE_BRANCH_FLAKE, + "ftm_policy.quarantine.days_active" => Self::QUARANTINE_DAYS_ACTIVE, + "unknown" => Self::UNKNOWN, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_flaky_test_history_policy_meta.rs b/src/datadogV2/model/model_flaky_test_history_policy_meta.rs new file mode 100644 index 0000000000..2a558e2dca --- /dev/null +++ b/src/datadogV2/model/model_flaky_test_history_policy_meta.rs @@ -0,0 +1,219 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Metadata about the policy that triggered this status change. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct FlakyTestHistoryPolicyMeta { + /// Branches where the test was flaky at the time of the status change. + #[serde( + rename = "branches", + default, + with = "::serde_with::rust::double_option" + )] + pub branches: Option>>, + /// Configuration parameters of the policy that triggered this status change. + #[serde(rename = "config")] + pub config: Option, + /// The number of days the test has been active at the time of the status change. + #[serde( + rename = "days_active", + default, + with = "::serde_with::rust::double_option" + )] + pub days_active: Option>, + /// The number of days since the test last exhibited flakiness. + #[serde( + rename = "days_without_flake", + default, + with = "::serde_with::rust::double_option" + )] + pub days_without_flake: Option>, + /// The failure rate of the test at the time of the status change. + #[serde( + rename = "failure_rate", + default, + with = "::serde_with::rust::double_option" + )] + pub failure_rate: Option>, + /// The previous state of the test. + #[serde(rename = "state", default, with = "::serde_with::rust::double_option")] + pub state: Option>, + /// The total number of test runs at the time of the status change. + #[serde( + rename = "total_runs", + default, + with = "::serde_with::rust::double_option" + )] + pub total_runs: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl FlakyTestHistoryPolicyMeta { + pub fn new() -> FlakyTestHistoryPolicyMeta { + FlakyTestHistoryPolicyMeta { + branches: None, + config: None, + days_active: None, + days_without_flake: None, + failure_rate: None, + state: None, + total_runs: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn branches(mut self, value: Option>) -> Self { + self.branches = Some(value); + self + } + + pub fn config( + mut self, + value: crate::datadogV2::model::FlakyTestHistoryPolicyMetaConfig, + ) -> Self { + self.config = Some(value); + self + } + + pub fn days_active(mut self, value: Option) -> Self { + self.days_active = Some(value); + self + } + + pub fn days_without_flake(mut self, value: Option) -> Self { + self.days_without_flake = Some(value); + self + } + + pub fn failure_rate(mut self, value: Option) -> Self { + self.failure_rate = Some(value); + self + } + + pub fn state(mut self, value: Option) -> Self { + self.state = Some(value); + self + } + + pub fn total_runs(mut self, value: Option) -> Self { + self.total_runs = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for FlakyTestHistoryPolicyMeta { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for FlakyTestHistoryPolicyMeta { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FlakyTestHistoryPolicyMetaVisitor; + impl<'a> Visitor<'a> for FlakyTestHistoryPolicyMetaVisitor { + type Value = FlakyTestHistoryPolicyMeta; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut branches: Option>> = None; + let mut config: Option = + None; + let mut days_active: Option> = None; + let mut days_without_flake: Option> = None; + let mut failure_rate: Option> = None; + let mut state: Option> = None; + let mut total_runs: Option> = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "branches" => { + branches = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "config" => { + if v.is_null() { + continue; + } + config = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "days_active" => { + days_active = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "days_without_flake" => { + days_without_flake = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "failure_rate" => { + if v.as_str() == Some("") { + continue; + } + failure_rate = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "state" => { + state = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "total_runs" => { + total_runs = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = FlakyTestHistoryPolicyMeta { + branches, + config, + days_active, + days_without_flake, + failure_rate, + state, + total_runs, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(FlakyTestHistoryPolicyMetaVisitor) + } +} diff --git a/src/datadogV2/model/model_flaky_test_history_policy_meta_config.rs b/src/datadogV2/model/model_flaky_test_history_policy_meta_config.rs new file mode 100644 index 0000000000..3aac373ab1 --- /dev/null +++ b/src/datadogV2/model/model_flaky_test_history_policy_meta_config.rs @@ -0,0 +1,218 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Configuration parameters of the policy that triggered this status change. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct FlakyTestHistoryPolicyMetaConfig { + /// The branches considered by the policy. + #[serde( + rename = "branches", + default, + with = "::serde_with::rust::double_option" + )] + pub branches: Option>>, + /// The number of days a test must have been active for the policy to trigger. + #[serde( + rename = "days_active", + default, + with = "::serde_with::rust::double_option" + )] + pub days_active: Option>, + /// The failure rate threshold for the policy to trigger. + #[serde( + rename = "failure_rate", + default, + with = "::serde_with::rust::double_option" + )] + pub failure_rate: Option>, + /// Branches excluded from the policy evaluation. + #[serde( + rename = "forget_branches", + default, + with = "::serde_with::rust::double_option" + )] + pub forget_branches: Option>>, + /// The minimum number of test runs required for the policy to trigger. + #[serde( + rename = "required_runs", + default, + with = "::serde_with::rust::double_option" + )] + pub required_runs: Option>, + /// The target state the policy transitions the test from. + #[serde(rename = "state", default, with = "::serde_with::rust::double_option")] + pub state: Option>, + /// Test services excluded from the policy evaluation. + #[serde( + rename = "test_services", + default, + with = "::serde_with::rust::double_option" + )] + pub test_services: Option>>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl FlakyTestHistoryPolicyMetaConfig { + pub fn new() -> FlakyTestHistoryPolicyMetaConfig { + FlakyTestHistoryPolicyMetaConfig { + branches: None, + days_active: None, + failure_rate: None, + forget_branches: None, + required_runs: None, + state: None, + test_services: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn branches(mut self, value: Option>) -> Self { + self.branches = Some(value); + self + } + + pub fn days_active(mut self, value: Option) -> Self { + self.days_active = Some(value); + self + } + + pub fn failure_rate(mut self, value: Option) -> Self { + self.failure_rate = Some(value); + self + } + + pub fn forget_branches(mut self, value: Option>) -> Self { + self.forget_branches = Some(value); + self + } + + pub fn required_runs(mut self, value: Option) -> Self { + self.required_runs = Some(value); + self + } + + pub fn state(mut self, value: Option) -> Self { + self.state = Some(value); + self + } + + pub fn test_services(mut self, value: Option>) -> Self { + self.test_services = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for FlakyTestHistoryPolicyMetaConfig { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for FlakyTestHistoryPolicyMetaConfig { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FlakyTestHistoryPolicyMetaConfigVisitor; + impl<'a> Visitor<'a> for FlakyTestHistoryPolicyMetaConfigVisitor { + type Value = FlakyTestHistoryPolicyMetaConfig; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut branches: Option>> = None; + let mut days_active: Option> = None; + let mut failure_rate: Option> = None; + let mut forget_branches: Option>> = None; + let mut required_runs: Option> = None; + let mut state: Option> = None; + let mut test_services: Option>> = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "branches" => { + branches = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "days_active" => { + days_active = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "failure_rate" => { + if v.as_str() == Some("") { + continue; + } + failure_rate = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "forget_branches" => { + forget_branches = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "required_runs" => { + required_runs = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "state" => { + state = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "test_services" => { + test_services = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = FlakyTestHistoryPolicyMetaConfig { + branches, + days_active, + failure_rate, + forget_branches, + required_runs, + state, + test_services, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(FlakyTestHistoryPolicyMetaConfigVisitor) + } +} diff --git a/src/datadogV2/model/model_flaky_tests_search_filter.rs b/src/datadogV2/model/model_flaky_tests_search_filter.rs index 512d35793c..749af0df7d 100644 --- a/src/datadogV2/model/model_flaky_tests_search_filter.rs +++ b/src/datadogV2/model/model_flaky_tests_search_filter.rs @@ -11,6 +11,11 @@ use std::fmt::{self, Formatter}; #[skip_serializing_none] #[derive(Clone, Debug, PartialEq, Serialize)] pub struct FlakyTestsSearchFilter { + /// Whether to include the status change history for each flaky test in the response. + /// When set to true, each test will include a `history` array with chronological status changes. + /// Defaults to false. + #[serde(rename = "include_history")] + pub include_history: Option, /// 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` @@ -34,12 +39,18 @@ pub struct FlakyTestsSearchFilter { impl FlakyTestsSearchFilter { pub fn new() -> FlakyTestsSearchFilter { FlakyTestsSearchFilter { + include_history: None, query: None, additional_properties: std::collections::BTreeMap::new(), _unparsed: false, } } + pub fn include_history(mut self, value: bool) -> Self { + self.include_history = Some(value); + self + } + pub fn query(mut self, value: String) -> Self { self.query = Some(value); self @@ -77,6 +88,7 @@ impl<'de> Deserialize<'de> for FlakyTestsSearchFilter { where M: MapAccess<'a>, { + let mut include_history: Option = None; let mut query: Option = None; let mut additional_properties: std::collections::BTreeMap< String, @@ -86,6 +98,13 @@ impl<'de> Deserialize<'de> for FlakyTestsSearchFilter { while let Some((k, v)) = map.next_entry::()? { match k.as_str() { + "include_history" => { + if v.is_null() { + continue; + } + include_history = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } "query" => { if v.is_null() { continue; @@ -101,6 +120,7 @@ impl<'de> Deserialize<'de> for FlakyTestsSearchFilter { } let content = FlakyTestsSearchFilter { + include_history, query, additional_properties, _unparsed, diff --git a/src/datadogV2/model/model_flaky_tests_search_request_attributes.rs b/src/datadogV2/model/model_flaky_tests_search_request_attributes.rs index bcbe56aa66..96bef8465e 100644 --- a/src/datadogV2/model/model_flaky_tests_search_request_attributes.rs +++ b/src/datadogV2/model/model_flaky_tests_search_request_attributes.rs @@ -14,11 +14,6 @@ pub struct FlakyTestsSearchRequestAttributes { /// Search filter settings. #[serde(rename = "filter")] pub filter: Option, - /// Whether to include the status change history for each flaky test in the response. - /// When set to true, each test will include a `history` array with chronological status changes. - /// Defaults to false. - #[serde(rename = "include_history")] - pub include_history: Option, /// Pagination attributes for listing flaky tests. #[serde(rename = "page")] pub page: Option, @@ -36,7 +31,6 @@ impl FlakyTestsSearchRequestAttributes { pub fn new() -> FlakyTestsSearchRequestAttributes { FlakyTestsSearchRequestAttributes { filter: None, - include_history: None, page: None, sort: None, additional_properties: std::collections::BTreeMap::new(), @@ -49,11 +43,6 @@ impl FlakyTestsSearchRequestAttributes { self } - pub fn include_history(mut self, value: bool) -> Self { - self.include_history = Some(value); - self - } - pub fn page(mut self, value: crate::datadogV2::model::FlakyTestsSearchPageOptions) -> Self { self.page = Some(value); self @@ -97,7 +86,6 @@ impl<'de> Deserialize<'de> for FlakyTestsSearchRequestAttributes { M: MapAccess<'a>, { let mut filter: Option = None; - let mut include_history: Option = None; let mut page: Option = None; let mut sort: Option = None; let mut additional_properties: std::collections::BTreeMap< @@ -114,13 +102,6 @@ impl<'de> Deserialize<'de> for FlakyTestsSearchRequestAttributes { } filter = Some(serde_json::from_value(v).map_err(M::Error::custom)?); } - "include_history" => { - if v.is_null() { - continue; - } - include_history = - Some(serde_json::from_value(v).map_err(M::Error::custom)?); - } "page" => { if v.is_null() { continue; @@ -151,7 +132,6 @@ impl<'de> Deserialize<'de> for FlakyTestsSearchRequestAttributes { let content = FlakyTestsSearchRequestAttributes { filter, - include_history, page, sort, additional_properties, diff --git a/tests/scenarios/features/v2/test_optimization.feature b/tests/scenarios/features/v2/test_optimization.feature index 427db05baf..27f337f929 100644 --- a/tests/scenarios/features/v2/test_optimization.feature +++ b/tests/scenarios/features/v2/test_optimization.feature @@ -85,7 +85,7 @@ Feature: Test Optimization Scenario: Search flaky tests returns "Bad Request" response Given operation "SearchFlakyTests" enabled And new "SearchFlakyTests" request - And body with value {"data": {"attributes": {"filter": {"query": "flaky_test_state:active @git.repository.id_v2:\"github.com/datadog/shopist\""}, "include_history": true, "page": {"cursor": "eyJzdGFydEF0IjoiQVFBQUFYS2tMS3pPbm40NGV3QUFBQUJCV0V0clRFdDZVbG8zY3pCRmNsbHJiVmxDWlEifQ==", "limit": 25}, "sort": "failure_rate"}, "type": "search_flaky_tests_request"}} + And body with value {"data": {"attributes": {"filter": {"include_history": true, "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 @@ -101,7 +101,7 @@ Feature: Test Optimization Scenario: Search flaky tests returns "OK" response Given operation "SearchFlakyTests" enabled And new "SearchFlakyTests" request - And body with value {"data": {"attributes": {"filter": {"query": "flaky_test_state:active @git.repository.id_v2:\"github.com/datadog/shopist\""}, "include_history": true, "page": {"cursor": "eyJzdGFydEF0IjoiQVFBQUFYS2tMS3pPbm40NGV3QUFBQUJCV0V0clRFdDZVbG8zY3pCRmNsbHJiVmxDWlEifQ==", "limit": 25}, "sort": "failure_rate"}, "type": "search_flaky_tests_request"}} + And body with value {"data": {"attributes": {"filter": {"include_history": true, "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 @@ -117,19 +117,21 @@ Feature: Test Optimization Scenario: Search flaky tests returns "OK" response with history Given operation "SearchFlakyTests" enabled And new "SearchFlakyTests" request - And body with value {"data": {"attributes": {"filter": {"query": "flaky_test_state:active @git.repository.id_v2:\"github.com/datadog/shopist\""}, "page": {"limit": 10}, "sort": "fqn", "include_history": true}, "type": "search_flaky_tests_request"}} + And body with value {"data": {"attributes": {"filter": {"query": "flaky_test_state:active @git.repository.id_v2:\"github.com/datadog/shopist\"", "include_history": true}, "page": {"limit": 10}, "sort": "fqn"}, "type": "search_flaky_tests_request"}} When the request is sent Then the response status is 200 OK And the response "data[0].attributes" has field "history" And the response "data[0].attributes.history[0]" has field "status" And the response "data[0].attributes.history[0]" has field "commit_sha" And the response "data[0].attributes.history[0]" has field "timestamp" + And the response "data[0].attributes.history[0]" has field "policy_id" + And the response "data[0].attributes.history[0]" has field "policy_meta" @generated @skip @team:DataDog/ci-app-backend @with-pagination Scenario: Search flaky tests returns "OK" response with pagination Given operation "SearchFlakyTests" enabled And new "SearchFlakyTests" request - And body with value {"data": {"attributes": {"filter": {"query": "flaky_test_state:active @git.repository.id_v2:\"github.com/datadog/shopist\""}, "include_history": true, "page": {"cursor": "eyJzdGFydEF0IjoiQVFBQUFYS2tMS3pPbm40NGV3QUFBQUJCV0V0clRFdDZVbG8zY3pCRmNsbHJiVmxDWlEifQ==", "limit": 25}, "sort": "failure_rate"}, "type": "search_flaky_tests_request"}} + And body with value {"data": {"attributes": {"filter": {"include_history": true, "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