Skip to content

Commit

Permalink
FLEET-19 Turn off Fleet Detection if APOLLO_TELEMETRY_DISABLED is det…
Browse files Browse the repository at this point in the history
…ected
  • Loading branch information
jonathanrainer committed Nov 12, 2024
1 parent e3e5c24 commit 4bd425c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion apollo-router/src/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub(crate) static mut DHAT_HEAP_PROFILER: OnceCell<dhat::Profiler> = OnceCell::n
pub(crate) static mut DHAT_AD_HOC_PROFILER: OnceCell<dhat::Profiler> = OnceCell::new();

pub(crate) const APOLLO_ROUTER_DEV_ENV: &str = "APOLLO_ROUTER_DEV";
pub(crate) const APOLLO_TELEMETRY_DISABLED: &str = "APOLLO_TELEMETRY_DISABLED";

// Note: Constructor/Destructor functions may not play nicely with tracing, since they run after
// main completes, so don't use tracing, use println!() and eprintln!()..
Expand Down Expand Up @@ -240,7 +241,7 @@ pub struct Opt {
apollo_uplink_poll_interval: Duration,

/// Disable sending anonymous usage information to Apollo.
#[clap(long, env = "APOLLO_TELEMETRY_DISABLED", value_parser = FalseyValueParser::new())]
#[clap(long, env = APOLLO_TELEMETRY_DISABLED, value_parser = FalseyValueParser::new())]
anonymous_telemetry_disabled: bool,

/// The timeout for an http call to Apollo uplink. Defaults to 30s.
Expand Down
16 changes: 13 additions & 3 deletions apollo-router/src/plugins/fleet_detector.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::env::consts::ARCH;
use std::sync::Arc;
use std::sync::Mutex;
Expand All @@ -15,6 +16,7 @@ use tokio::sync::mpsc::Sender;
use tower::BoxError;
use tracing::debug;

use crate::executable::APOLLO_TELEMETRY_DISABLED;
use crate::metrics::meter_provider;
use crate::plugin::PluginInit;
use crate::plugin::PluginPrivate;
Expand Down Expand Up @@ -138,6 +140,12 @@ impl PluginPrivate for FleetDetector {
debug!("initialising fleet detection plugin");
let (gauge_initializer, mut rx) = tokio::sync::mpsc::channel(1);

if env::var(APOLLO_TELEMETRY_DISABLED).is_ok() {
debug!("fleet detection disabled, no telemetry will be sent");
rx.close();
return Ok(FleetDetector { gauge_initializer });
}

debug!("spawning gauge initializer task");
tokio::spawn(async move {
let mut gauge_store = GaugeStore::new();
Expand All @@ -152,9 +160,11 @@ impl PluginPrivate for FleetDetector {
}

async fn activate(&self) {
debug!("initializing gauges");
if let Err(e) = self.gauge_initializer.send(()).await {
debug!("failed to activate fleet detector plugin: {:?}", e);
if !self.gauge_initializer.is_closed() {
debug!("initializing gauges");
if let Err(e) = self.gauge_initializer.send(()).await {
debug!("failed to activate fleet detector plugin: {:?}", e);
}
}
}
}
Expand Down

0 comments on commit 4bd425c

Please sign in to comment.