-
Notifications
You must be signed in to change notification settings - Fork 7
(Chore): Better telemetry for quarantine query #1100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: tyler/reorganize-report-tests
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ use superconsole::{ | |
| }; | ||
| use tempfile::TempDir; | ||
|
|
||
| use crate::context_quarantine::QuarantineContext; | ||
| use crate::context_quarantine::{QuarantineContext, quarantine_query_result}; | ||
| use crate::validate_command::JunitReportValidations; | ||
| use crate::{ | ||
| context::{ | ||
|
|
@@ -360,6 +360,7 @@ pub async fn run_upload( | |
| pre_test_context: Option<PreTestContext>, | ||
| test_run_result: Option<TestRunResult>, | ||
| render_sender: Option<Sender<DisplayMessage>>, | ||
| quarantine_query_result_override: Option<proto::upload_metrics::trunk::QuarantineQueryResult>, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RSpec calls the quarantine config at a separate time than the upload flow. There's a gate above this where we conditionally call GetQuarantineConfig depending on if there are JUnits (which there aren't in RSpec). That's a smell, but I didn't want to undertake that refactor right now, and it's not a meaningful increase in burden to wire in a quarantine query result override here |
||
| ) -> anyhow::Result<UploadRunResult> { | ||
| // grab the exec start if provided (`test` subcommand) or use the current time | ||
| let cli_started_at = if let Some(test_run_result) = test_run_result.as_ref() { | ||
|
|
@@ -509,6 +510,8 @@ pub async fn run_upload( | |
| upload_args.dry_run, | ||
| ) | ||
| .await; | ||
| let quarantine_query_result = quarantine_query_result_override | ||
| .unwrap_or_else(|| quarantine_query_result(disable_quarantining, &quarantine_context)); | ||
| let upload_metrics = proto::upload_metrics::trunk::UploadMetrics { | ||
| client_version: Some(proto::upload_metrics::trunk::Semver { | ||
| major: env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap_or_default(), | ||
|
|
@@ -526,6 +529,7 @@ pub async fn run_upload( | |
| upload_finished_at: Some(chrono::Utc::now().into()), | ||
| failed: false, | ||
| failure_reason: "".into(), | ||
| quarantine_query_result: quarantine_query_result.into(), | ||
| }; | ||
| let mut request = api::message::TelemetryUploadMetricsRequest { upload_metrics }; | ||
| if !upload_args.dry_run { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ use lazy_static::lazy_static; | |
| use predicates::prelude::*; | ||
| use pretty_assertions::assert_eq; | ||
| use prost::Message; | ||
| use proto::upload_metrics::trunk::QuarantineQueryResult; | ||
| use tempfile::tempdir; | ||
| #[cfg(target_os = "macos")] | ||
| use test_utils::inputs::unpack_archive_to_dir; | ||
|
|
@@ -1277,6 +1278,10 @@ async fn telemetry_upload_metrics_on_upload_failure() { | |
| assert_eq!(telemetry_request_repo.owner, "trunk-io"); | ||
| assert_eq!(telemetry_request_repo.name, "analytics-cli"); | ||
| assert_eq!(telemetry_request.failure_reason, "400_bad_request"); | ||
| assert_eq!( | ||
| QuarantineQueryResult::try_from(telemetry_request.quarantine_query_result).unwrap(), | ||
| QuarantineQueryResult::Disabled | ||
| ); | ||
|
|
||
| // HINT: View CLI output with `cargo test -- --nocapture` | ||
| println!("{assert}"); | ||
|
|
@@ -1308,11 +1313,126 @@ async fn telemetry_upload_metrics_on_upload_success() { | |
| assert_eq!(telemetry_request_repo.owner, "trunk-io"); | ||
| assert_eq!(telemetry_request_repo.name, "analytics-cli"); | ||
| assert_eq!(telemetry_request.failure_reason, ""); | ||
| assert_eq!( | ||
| QuarantineQueryResult::try_from(telemetry_request.quarantine_query_result).unwrap(), | ||
| QuarantineQueryResult::Disabled | ||
| ); | ||
|
|
||
| // HINT: View CLI output with `cargo test -- --nocapture` | ||
| println!("{assert}"); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn telemetry_upload_metrics_quarantine_query_result_success() { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These CLI integration tests require a bit more custom setup because of the scenarios they test |
||
| let temp_dir = tempdir().unwrap(); | ||
| generate_mock_git_repo(&temp_dir); | ||
| generate_mock_valid_junit_xmls_with_failures(&temp_dir); | ||
|
|
||
| let state = MockServerBuilder::new().spawn_mock_server().await; | ||
|
|
||
| CommandBuilder::upload(temp_dir.path(), state.host.clone()) | ||
| .command() | ||
| .assert() | ||
| .failure(); | ||
|
|
||
| let requests = state.requests.lock().unwrap().clone(); | ||
| let quarantine_query_result = requests | ||
| .iter() | ||
| .rev() | ||
| .find_map(|req| match req { | ||
| RequestPayload::TelemetryUploadMetrics(ur) => Some(ur.quarantine_query_result), | ||
| _ => None, | ||
| }) | ||
| .expect("telemetry upload metrics request"); | ||
| assert_eq!( | ||
| QuarantineQueryResult::try_from(quarantine_query_result).unwrap(), | ||
| QuarantineQueryResult::Success | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn telemetry_upload_metrics_quarantine_query_result_failure() { | ||
| let temp_dir = tempdir().unwrap(); | ||
| generate_mock_git_repo(&temp_dir); | ||
| generate_mock_valid_junit_xmls_with_failures(&temp_dir); | ||
|
|
||
| let mut mock_server_builder = MockServerBuilder::new(); | ||
| mock_server_builder.set_get_quarantining_config_handler( | ||
| |Json(_): Json<GetQuarantineConfigRequest>| async { | ||
| Err::<Json<GetQuarantineConfigResponse>, StatusCode>(StatusCode::INTERNAL_SERVER_ERROR) | ||
| }, | ||
| ); | ||
| let state = mock_server_builder.spawn_mock_server().await; | ||
|
|
||
| CommandBuilder::upload(temp_dir.path(), state.host.clone()) | ||
| .command() | ||
| .assert() | ||
| .failure(); | ||
|
|
||
| let requests = state.requests.lock().unwrap().clone(); | ||
| let quarantine_query_result = requests | ||
| .iter() | ||
| .rev() | ||
| .find_map(|req| match req { | ||
| RequestPayload::TelemetryUploadMetrics(ur) => Some(ur.quarantine_query_result), | ||
| _ => None, | ||
| }) | ||
| .expect("telemetry upload metrics request"); | ||
| assert_eq!( | ||
| QuarantineQueryResult::try_from(quarantine_query_result).unwrap(), | ||
| QuarantineQueryResult::Failure | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn telemetry_upload_metrics_quarantine_query_result_skipped() { | ||
| let temp_dir = tempdir().unwrap(); | ||
| generate_mock_git_repo(&temp_dir); | ||
|
|
||
| // All-passing JUnit so quarantine lookup is skipped (no failed tests). | ||
| let test_case_options = junit_mock::TestCaseOptions { | ||
| test_case_names: Some(vec![String::from("test_case")]), | ||
| test_case_classnames: Some(vec![String::from("TestClass")]), | ||
| test_case_random_count: 0usize, | ||
| test_case_sys_out_percentage: 0u8, | ||
| test_case_sys_err_percentage: 0u8, | ||
| test_case_duration_range: vec![Duration::new(10, 0).into(), Duration::new(20, 0).into()], | ||
| test_case_success_to_skip_to_fail_to_error_percentage: vec![vec![100u8, 0u8, 0u8, 0u8]], | ||
| }; | ||
| let options = junit_mock::Options { | ||
| global: junit_mock::GlobalOptions::try_parse_from([""]).unwrap(), | ||
| report: junit_mock::ReportOptions::try_parse_from([""]).unwrap(), | ||
| test_suite: junit_mock::TestSuiteOptions::try_parse_from([""]).unwrap(), | ||
| test_case: test_case_options, | ||
| test_rerun: junit_mock::TestRerunOptions::try_parse_from([""]).unwrap(), | ||
| }; | ||
| let mut mock = JunitMock::new(options); | ||
| let reports = mock.generate_reports(); | ||
| mock.write_reports_to_file(temp_dir.as_ref(), reports) | ||
| .unwrap(); | ||
|
|
||
| let state = MockServerBuilder::new().spawn_mock_server().await; | ||
|
|
||
| CommandBuilder::upload(temp_dir.path(), state.host.clone()) | ||
| .command() | ||
| .assert() | ||
| .success(); | ||
|
|
||
| let requests = state.requests.lock().unwrap().clone(); | ||
| let quarantine_query_result = requests | ||
| .iter() | ||
| .rev() | ||
| .find_map(|req| match req { | ||
| RequestPayload::TelemetryUploadMetrics(ur) => Some(ur.quarantine_query_result), | ||
| _ => None, | ||
| }) | ||
| .expect("telemetry upload metrics request"); | ||
| assert_eq!( | ||
| QuarantineQueryResult::try_from(quarantine_query_result).unwrap(), | ||
| QuarantineQueryResult::Skipped | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn telemetry_does_not_impact_return() { | ||
| let temp_dir = tempdir().unwrap(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,16 @@ package trunk.oss.flakytests_cli.v1; | |
| import "common.proto"; | ||
| import "google/protobuf/timestamp.proto"; | ||
|
|
||
| enum QuarantineQueryResult { | ||
| QUARANTINE_QUERY_RESULT_UNSPECIFIED = 0; | ||
| QUARANTINE_QUERY_RESULT_SUCCESS = 1; | ||
| QUARANTINE_QUERY_RESULT_FAILURE = 2; | ||
| QUARANTINE_QUERY_RESULT_DISABLED = 3; | ||
| QUARANTINE_QUERY_RESULT_SKIPPED = 4; | ||
| // rspec only | ||
| QUARANTINE_QUERY_RESULT_CACHED = 5; | ||
| } | ||
|
Comment on lines
+8
to
+16
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth making any of those points an inline comment alongside any of those?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, I think those comments are nice :) |
||
|
|
||
| message UploadMetrics { | ||
| Semver client_version = 1; | ||
| Repo repo = 2; | ||
|
|
@@ -13,6 +23,7 @@ message UploadMetrics { | |
| google.protobuf.Timestamp upload_finished_at = 5; | ||
| bool failed = 6; | ||
| string failure_reason = 7; | ||
| QuarantineQueryResult quarantine_query_result = 8; | ||
| } | ||
|
|
||
| // Used by the analytics-uploader, kept here to avoid collisions in the future. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unit test for this