Skip to content

Commit bd388d4

Browse files
committed
wip: otel flaky test
Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
1 parent d98e13b commit bd388d4

File tree

1 file changed

+48
-37
lines changed

1 file changed

+48
-37
lines changed

tests/integration_test.rs

+48-37
Original file line numberDiff line numberDiff line change
@@ -941,11 +941,22 @@ async fn test_otel() {
941941
"OTEL_EXPORTER_OTLP_CLIENT_KEY",
942942
client_key_file.path().to_str().unwrap(),
943943
);
944+
std::env::set_var("OTEL_METRIC_EXPORT_INTERVAL", "1");
944945

945946
println!("Starting policy server");
946947
let mut config = default_test_config();
947948
config.metrics_enabled = true;
948949
config.log_fmt = "otlp".to_string();
950+
// config.policies = HashMap::from([(
951+
// "pod-privileged".to_owned(),
952+
// PolicyOrPolicyGroup::Policy {
953+
// module: "ghcr.io/kubewarden/tests/pod-privileged:v0.2.1".to_owned(),
954+
// policy_mode: PolicyMode::Protect,
955+
// allowed_to_mutate: None,
956+
// settings: None,
957+
// context_aware_resources: BTreeSet::new(),
958+
// },
959+
// )]);
949960
let host = config.addr.ip().to_string();
950961
let port = config.addr.port().to_string();
951962
let readiness_probe_port = config.readiness_probe_addr.port().to_string();
@@ -1022,43 +1033,43 @@ async fn test_otel() {
10221033
assert_eq!(spans["scope"]["name"], "kubewarden-policy-server");
10231034
println!("traces check");
10241035

1025-
// let metrics_output_json = (|| async {
1026-
// let out = otelc.stdout_to_vec().await.unwrap();
1027-
// println!(
1028-
// "stdout: {}",
1029-
// String::from_utf8(out).unwrap_or("cannot get stdout".to_string())
1030-
// );
1031-
// let out = otelc.stderr_to_vec().await.unwrap();
1032-
// println!(
1033-
// "stderr: {}",
1034-
// String::from_utf8(out).unwrap_or("cannot get stderr".to_string())
1035-
// );
1036-
// parse_exporter_output(metrics_output_file.as_file()).await
1037-
// })
1038-
// .retry(exponential_backoff)
1039-
// .await
1040-
// .unwrap();
1041-
// let metrics = &metrics_output_json["resourceMetrics"][0]["scopeMetrics"][0];
1042-
// assert_eq!(metrics["scope"]["name"], "kubewarden");
1043-
// assert!(
1044-
// metrics["metrics"]
1045-
// .as_array()
1046-
// .unwrap()
1047-
// .iter()
1048-
// .any(|m| { m["name"] == "kubewarden_policy_evaluation_latency_milliseconds" }),
1049-
// "metrics_output_json: {}",
1050-
// serde_json::to_string_pretty(&metrics_output_json).unwrap()
1051-
// );
1052-
// assert!(
1053-
// metrics["metrics"]
1054-
// .as_array()
1055-
// .unwrap()
1056-
// .iter()
1057-
// .any(|m| { m["name"] == "kubewarden_policy_evaluations_total" }),
1058-
// "metrics_output_json: {}",
1059-
// serde_json::to_string_pretty(&metrics_output_json).unwrap()
1060-
// );
1061-
// println!("metrics check");
1036+
let metrics_output_json = (|| async {
1037+
let out = otelc.stdout_to_vec().await.unwrap();
1038+
println!(
1039+
"stdout: {}",
1040+
String::from_utf8(out).unwrap_or("cannot get stdout".to_string())
1041+
);
1042+
let out = otelc.stderr_to_vec().await.unwrap();
1043+
println!(
1044+
"stderr: {}",
1045+
String::from_utf8(out).unwrap_or("cannot get stderr".to_string())
1046+
);
1047+
parse_exporter_output(metrics_output_file.as_file()).await
1048+
})
1049+
.retry(exponential_backoff)
1050+
.await
1051+
.unwrap();
1052+
let metrics = &metrics_output_json["resourceMetrics"][0]["scopeMetrics"][0];
1053+
assert_eq!(metrics["scope"]["name"], "kubewarden");
1054+
assert!(
1055+
metrics["metrics"]
1056+
.as_array()
1057+
.unwrap()
1058+
.iter()
1059+
.any(|m| { m["name"] == "kubewarden_policy_evaluation_latency_milliseconds" }),
1060+
"metrics_output_json: {}",
1061+
serde_json::to_string_pretty(&metrics_output_json).unwrap()
1062+
);
1063+
assert!(
1064+
metrics["metrics"]
1065+
.as_array()
1066+
.unwrap()
1067+
.iter()
1068+
.any(|m| { m["name"] == "kubewarden_policy_evaluations_total" }),
1069+
"metrics_output_json: {}",
1070+
serde_json::to_string_pretty(&metrics_output_json).unwrap()
1071+
);
1072+
println!("metrics check");
10621073

10631074
otelc.stop().await.unwrap();
10641075
}

0 commit comments

Comments
 (0)