Skip to content

Commit

Permalink
test: validate telemetry flags via stdout in CLI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
waynr committed Jan 16, 2025
1 parent 9be5dbd commit a99774b
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions influxdb3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ test_helpers.workspace = true
tonic.workspace = true
tower.workspace = true
test-log.workspace = true
predicates = "3.1.3"
2 changes: 2 additions & 0 deletions influxdb3/src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,10 @@ async fn setup_telemetry_store(
let storage_type = obj_store_type.as_str();

if disable_upload {
debug!("Initializing TelemetryStore with upload disabled.");
TelemetryStore::new_without_background_runners(persisted_files.map(|p| p as _))
} else {
debug!("Initializing TelemetryStore with upload enabled for {telemetry_endpoint}.");
TelemetryStore::new(
instance_id,
Arc::from(os),
Expand Down
101 changes: 101 additions & 0 deletions influxdb3/tests/server/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use std::{

use crate::{ConfigProvider, TestServer};
use assert_cmd::cargo::CommandCargoExt;
use assert_cmd::Command as AssertCmd;
use observability_deps::tracing::debug;
use predicates::boolean::PredicateBooleanExt;
use pretty_assertions::assert_eq;
use serde_json::{json, Value};
use test_helpers::assert_contains;
Expand Down Expand Up @@ -86,6 +88,105 @@ fn create_plugin_file(code: &str) -> NamedTempFile {
file
}

#[test_log::test(tokio::test)]
async fn test_telemetry_disabled_with_debug_msg() {
let serve_args = &[
"serve",
"--writer-id",
"the-best-writer",
"--object-store",
"memory",
];

let expected_disabled: &str = "Initializing TelemetryStore with upload disabled.";

// validate we get a debug message indicating upload disabled
AssertCmd::cargo_bin("influxdb3")
.unwrap()
.args(serve_args)
.arg("-vv")
.arg("--disable-telemetry-upload")
.timeout(std::time::Duration::from_millis(200))
.assert()
.failure()
.stdout(predicates::str::contains(expected_disabled));
}

#[test_log::test(tokio::test)]
async fn test_telemetry_disabled() {
let serve_args = &[
"serve",
"--writer-id",
"the-best-writer",
"--object-store",
"memory",
];

let expected_disabled: &str = "Initializing TelemetryStore with upload disabled.";
// validate no message when debug output disabled
AssertCmd::cargo_bin("influxdb3")
.unwrap()
.args(serve_args)
.arg("-v")
.arg("--disable-telemetry-upload")
.timeout(std::time::Duration::from_millis(200))
.assert()
.failure()
.stdout(predicates::str::contains(expected_disabled).not());
}

#[test_log::test(tokio::test)]
async fn test_telemetry_enabled_with_debug_msg() {
let serve_args = &[
"serve",
"--writer-id",
"the-best-writer",
"--object-store",
"memory",
];

let expected_enabled: &str =
"Initializing TelemetryStore with upload enabled for http://localhost:9999.";

// validate debug output shows which endpoint we are hitting when telemetry enabled
AssertCmd::cargo_bin("influxdb3")
.unwrap()
.args(serve_args)
.arg("-vv")
.arg("--telemetry-endpoint")
.arg("http://localhost:9999")
.timeout(std::time::Duration::from_millis(200))
.assert()
.failure()
.stdout(predicates::str::contains(expected_enabled));
}

#[test_log::test(tokio::test)]
async fn test_telementry_enabled() {
let serve_args = &[
"serve",
"--writer-id",
"the-best-writer",
"--object-store",
"memory",
];

let expected_enabled: &str =
"Initializing TelemetryStore with upload enabled for http://localhost:9999.";

// validate no telemetry endpoint reported when debug output not enabled
AssertCmd::cargo_bin("influxdb3")
.unwrap()
.args(serve_args)
.arg("-v")
.arg("--telemetry-endpoint")
.arg("http://localhost:9999")
.timeout(std::time::Duration::from_millis(200))
.assert()
.failure()
.stdout(predicates::str::contains(expected_enabled).not());
}

#[test_log::test(tokio::test)]
async fn test_show_databases() {
let server = TestServer::spawn().await;
Expand Down
1 change: 1 addition & 0 deletions influxdb3/tests/server/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ impl TestServer {
let mut command = Command::cargo_bin("influxdb3").expect("create the influxdb3 command");
let command = command
.arg("serve")
.arg("--disable-telemetry-upload")
// bind to port 0 to get a random port assigned:
.args(["--http-bind", "0.0.0.0:0"])
.args(["--wal-flush-interval", "10ms"])
Expand Down

0 comments on commit a99774b

Please sign in to comment.