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 Fleet Detection Plugin #6151

Merged
merged 17 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
11 changes: 11 additions & 0 deletions .changesets/feat_jr_add_fleet_awareness_plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Adds Fleet Awareness Plugin

Adds a new plugin that reports telemetry to Apollo on the configuration and deployment of the Router. Initially only
reports, memory and CPU usage but will be expanded to cover other non-intrusive measures in future. 🚀

As part of the above PluginPrivate has been extended with a new `activate` hook which is guaranteed to be called once
the OTEL meter has been refreshed. This ensures that code, particularly that concerned with gauges, will survive a hot
reload of the router.

By [@jonathanrainer](https://github.com/jonathanrainer), [@nmoutschen](https://github.com/nmoutschen), [@loshz](https://github.com/loshz)
in https://github.com/apollographql/router/pull/6151
77 changes: 77 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ dependencies = [
"static_assertions",
"strum_macros 0.26.4",
"sys-info",
"sysinfo",
"tempfile",
"test-log",
"thiserror",
Expand Down Expand Up @@ -4193,6 +4194,15 @@ dependencies = [
"windows-sys 0.48.0",
]

[[package]]
name = "ntapi"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4"
dependencies = [
"winapi",
]

[[package]]
name = "nu-ansi-term"
version = "0.46.0"
Expand Down Expand Up @@ -6373,6 +6383,20 @@ dependencies = [
"libc",
]

[[package]]
name = "sysinfo"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3b5ae3f4f7d64646c46c4cae4e3f01d1c5d255c7406fdd7c7f999a94e488791"
dependencies = [
"core-foundation-sys",
"libc",
"memchr",
"ntapi",
"rayon",
"windows",
]

[[package]]
name = "system-configuration"
version = "0.5.1"
Expand Down Expand Up @@ -7545,6 +7569,59 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

[[package]]
name = "windows"
version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143"
dependencies = [
"windows-core",
"windows-targets 0.52.6",
]

[[package]]
name = "windows-core"
version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d"
dependencies = [
"windows-implement",
"windows-interface",
"windows-result",
"windows-targets 0.52.6",
]

[[package]]
name = "windows-implement"
version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
]

[[package]]
name = "windows-interface"
version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
]

[[package]]
name = "windows-result"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8"
dependencies = [
"windows-targets 0.52.6",
]

[[package]]
name = "windows-sys"
version = "0.45.0"
Expand Down
1 change: 1 addition & 0 deletions apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ serde_yaml = "0.8.26"
static_assertions = "1.1.0"
strum_macros = "0.26.0"
sys-info = "0.9.1"
sysinfo = { version = "0.32.0", features = ["windows"] }
thiserror = "1.0.61"
tokio.workspace = true
tokio-stream = { version = "0.1.15", features = ["sync", "net"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,9 @@ expression: "&schema"
"type": "object"
},
"Conf5": {
"type": "object"
},
"Conf6": {
"anyOf": [
{
"additionalProperties": {
Expand All @@ -1277,7 +1280,7 @@ expression: "&schema"
],
"description": "Subgraph URL mappings"
},
"Conf6": {
"Conf7": {
"additionalProperties": false,
"description": "Configuration for the Rhai Plugin",
"properties": {
Expand All @@ -1294,7 +1297,7 @@ expression: "&schema"
},
"type": "object"
},
"Conf7": {
"Conf8": {
"additionalProperties": false,
"description": "Telemetry configuration",
"properties": {
Expand Down Expand Up @@ -8323,6 +8326,10 @@ expression: "&schema"
"description": "Type conditioned fetching configuration.",
"type": "boolean"
},
"fleet_detector": {
"$ref": "#/definitions/Conf5",
"description": "#/definitions/Conf5"
},
"forbid_mutations": {
"$ref": "#/definitions/ForbidMutationsConfig",
"description": "#/definitions/ForbidMutationsConfig"
Expand All @@ -8348,8 +8355,8 @@ expression: "&schema"
"description": "#/definitions/Config"
},
"override_subgraph_url": {
"$ref": "#/definitions/Conf5",
"description": "#/definitions/Conf5"
"$ref": "#/definitions/Conf6",
"description": "#/definitions/Conf6"
},
"persisted_queries": {
"$ref": "#/definitions/PersistedQueries",
Expand All @@ -8372,8 +8379,8 @@ expression: "&schema"
"description": "#/definitions/Config8"
},
"rhai": {
"$ref": "#/definitions/Conf6",
"description": "#/definitions/Conf6"
"$ref": "#/definitions/Conf7",
"description": "#/definitions/Conf7"
},
"sandbox": {
"$ref": "#/definitions/Sandbox",
Expand All @@ -8388,8 +8395,8 @@ expression: "&schema"
"description": "#/definitions/Supergraph"
},
"telemetry": {
"$ref": "#/definitions/Conf7",
"description": "#/definitions/Conf7"
"$ref": "#/definitions/Conf8",
"description": "#/definitions/Conf8"
},
"tls": {
"$ref": "#/definitions/Tls",
Expand Down
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
3 changes: 1 addition & 2 deletions apollo-router/src/metrics/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl FilterMeterProvider {
.delegate(delegate)
.allow(
Regex::new(
r"apollo\.(graphos\.cloud|router\.(operations?|lifecycle|config|schema|query|query_planning|telemetry))(\..*|$)|apollo_router_uplink_fetch_count_total|apollo_router_uplink_fetch_duration_seconds",
r"apollo\.(graphos\.cloud|router\.(operations?|lifecycle|config|schema|query|query_planning|telemetry|instance))(\..*|$)|apollo_router_uplink_fetch_count_total|apollo_router_uplink_fetch_duration_seconds",
)
.expect("regex should have been valid"),
)
Expand Down Expand Up @@ -244,7 +244,6 @@ impl opentelemetry::metrics::MeterProvider for FilterMeterProvider {

#[cfg(test)]
mod test {

use opentelemetry::metrics::MeterProvider;
use opentelemetry::metrics::Unit;
use opentelemetry::runtime;
Expand Down
21 changes: 21 additions & 0 deletions apollo-router/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ pub(crate) trait PluginPrivate: Send + Sync + 'static {
fn web_endpoints(&self) -> MultiMap<ListenAddr, Endpoint> {
MultiMap::new()
}

/// The point of no return this plugin is about to go live
fn activate(&self) {}
}

#[async_trait]
Expand Down Expand Up @@ -677,6 +680,8 @@ where
fn web_endpoints(&self) -> MultiMap<ListenAddr, Endpoint> {
PluginUnstable::web_endpoints(self)
}

fn activate(&self) {}
}

fn get_type_of<T>(_: &T) -> &'static str {
Expand Down Expand Up @@ -733,6 +738,9 @@ pub(crate) trait DynPlugin: Send + Sync + 'static {
/// Support downcasting
#[cfg(test)]
fn as_any_mut(&mut self) -> &mut dyn std::any::Any;

/// The point of no return, this plugin is about to go live
fn activate(&self) {}
}

#[async_trait]
Expand Down Expand Up @@ -783,6 +791,19 @@ where
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}

fn activate(&self) {
self.activate()
}
}

impl<T> From<T> for Box<dyn DynPlugin>
where
T: PluginPrivate,
{
fn from(value: T) -> Self {
Box::new(value)
}
}

/// Register a plugin with a group and a name
Expand Down
Loading