Skip to content
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

Add ShotoverProcessBuilder::with_observability_address #1073

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions shotover-proxy/tests/cassandra_int_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,21 @@ async fn cluster_multi_rack(#[case] driver: CassandraDriver) {
"example-configs/cassandra-cluster-multi-rack/topology_rack1.yaml",
)
.with_log_name("Rack1")
.with_observability_port(9001)
.start()
.await;
let shotover_rack2 = ShotoverProcessBuilder::new_with_topology(
"example-configs/cassandra-cluster-multi-rack/topology_rack2.yaml",
)
.with_log_name("Rack2")
.with_observability_port(9002)
.start()
.await;
let shotover_rack3 = ShotoverProcessBuilder::new_with_topology(
"example-configs/cassandra-cluster-multi-rack/topology_rack3.yaml",
)
.with_log_name("Rack3")
.with_observability_port(9003)
.start()
.await;

Expand All @@ -319,21 +322,9 @@ async fn cluster_multi_rack(#[case] driver: CassandraDriver) {
//Check for bugs in cross connection state
native_types::test(&connection().await).await;

// TODO: This can be removed by allowing the ShotoverProcessBuilder to specify the `observability_interface`.
let metrics_port_collision = [EventMatcher::new()
.with_level(Level::Error)
.with_target("shotover_proxy::observability")
.with_message(r#"Metrics HTTP server failed: Failed to bind to 0.0.0.0:9001"#)
.with_count(Count::Any)];
shotover_rack1
.shutdown_and_then_consume_events(&metrics_port_collision)
.await;
shotover_rack2
.shutdown_and_then_consume_events(&metrics_port_collision)
.await;
shotover_rack3
.shutdown_and_then_consume_events(&metrics_port_collision)
.await;
shotover_rack1.shutdown_and_then_consume_events(&[]).await;
shotover_rack2.shutdown_and_then_consume_events(&[]).await;
shotover_rack3.shutdown_and_then_consume_events(&[]).await;
}

cluster::multi_rack::test_topology_task(None).await;
Expand Down
24 changes: 24 additions & 0 deletions test-helpers/src/shotover_process.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::time::Duration;
use uuid::Uuid;

pub use tokio_bin_process::event::{Event, Level};
pub use tokio_bin_process::event_matcher::{Count, EventMatcher, Events};
Expand All @@ -8,6 +9,7 @@ pub struct ShotoverProcessBuilder {
topology_path: String,
log_name: Option<String>,
cores: Option<String>,
observability_port: Option<u16>,
}

impl ShotoverProcessBuilder {
Expand All @@ -16,6 +18,7 @@ impl ShotoverProcessBuilder {
topology_path: topology_path.to_owned(),
log_name: None,
cores: None,
observability_port: None,
}
}

Expand All @@ -29,11 +32,32 @@ impl ShotoverProcessBuilder {
self
}

pub fn with_observability_port(mut self, port: u16) -> Self {
self.observability_port = Some(port);
self
}

pub async fn start(&self) -> BinProcess {
let mut args = vec!["-t", &self.topology_path, "--log-format", "json"];
if let Some(cores) = &self.cores {
args.extend(["--core-threads", cores]);
}
let config_path = if let Some(observability_port) = self.observability_port {
let config_path = std::env::temp_dir().join(Uuid::new_v4().to_string());
let config_contents = format!(
r#"
---
main_log_level: "info,shotover_proxy=info"
observability_interface: "127.0.0.1:{observability_port}"
"#
);
std::fs::write(&config_path, config_contents).unwrap();
config_path.into_os_string().into_string().unwrap()
} else {
"config/config.yaml".to_owned()
};
args.extend(["-c", &config_path]);

let mut shotover = BinProcess::start_with_args(
"shotover-proxy",
&args,
Expand Down