From 331c20ea8b0df73730bf97380351474b30196233 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Tue, 6 Aug 2024 18:19:11 +0200 Subject: [PATCH 01/13] add metrics tracking the V8 heap usage --- Cargo.lock | 27 ++++++- apollo-router/Cargo.toml | 2 +- .../bridge_query_planner_pool.rs | 76 ++++++++++++++++++- 3 files changed, 100 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b66ac53f6e..0de85308b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -571,7 +571,7 @@ dependencies = [ "reqwest", "rhai", "rmp", - "router-bridge", + "router-bridge 0.5.29+v2.8.3", "rstack", "rust-embed", "rustls", @@ -6113,6 +6113,29 @@ dependencies = [ "which", ] +[[package]] +name = "router-bridge" +version = "0.5.29+v2.8.3" +source = "git+https://github.com/apollographql/federation-rs.git?branch=geal/get_heap_statistics#989735fc863d7b4ad6c488fe8ee37ec29fe014e7" +dependencies = [ + "anyhow", + "async-channel 1.9.0", + "deno_console", + "deno_core", + "deno_url", + "deno_web", + "deno_webidl", + "rand 0.8.5", + "serde", + "serde_json", + "thiserror", + "tokio", + "tower", + "tower-service", + "tracing", + "which", +] + [[package]] name = "router-fuzz" version = "0.0.0" @@ -6128,7 +6151,7 @@ dependencies = [ "libfuzzer-sys", "log", "reqwest", - "router-bridge", + "router-bridge 0.5.27+v2.8.1", "schemars", "serde", "serde_json", diff --git a/apollo-router/Cargo.toml b/apollo-router/Cargo.toml index 26618a16a6..c8a5e3496b 100644 --- a/apollo-router/Cargo.toml +++ b/apollo-router/Cargo.toml @@ -195,7 +195,7 @@ regex = "1.10.5" reqwest.workspace = true # note: this dependency should _always_ be pinned, prefix the version with an `=` -router-bridge = "=0.5.27+v2.8.1" +router-bridge = { branch = "geal/get_heap_statistics", git = "https://github.com/apollographql/federation-rs.git" } rust-embed = { version = "8.4.0", features = ["include-exclude"] } rustls = "0.21.12" diff --git a/apollo-router/src/query_planner/bridge_query_planner_pool.rs b/apollo-router/src/query_planner/bridge_query_planner_pool.rs index a306f19b6b..3b154fd26e 100644 --- a/apollo-router/src/query_planner/bridge_query_planner_pool.rs +++ b/apollo-router/src/query_planner/bridge_query_planner_pool.rs @@ -1,5 +1,7 @@ use std::collections::HashMap; use std::num::NonZeroUsize; +use std::sync::atomic::AtomicU64; +use std::sync::atomic::Ordering; use std::sync::Arc; use std::time::Instant; @@ -8,6 +10,8 @@ use async_channel::bounded; use async_channel::Sender; use futures::future::BoxFuture; use opentelemetry::metrics::MeterProvider; +use opentelemetry::metrics::ObservableGauge; +use opentelemetry_api::metrics::Meter; use router_bridge::planner::Planner; use tokio::sync::oneshot; use tokio::task::JoinSet; @@ -37,6 +41,10 @@ pub(crate) struct BridgeQueryPlannerPool { schema: Arc, subgraph_schemas: Arc>>>, _pool_size_gauge: opentelemetry::metrics::ObservableGauge, + v8_heap_used: Arc, + _v8_heap_used_gauge: ObservableGauge, + v8_heap_total: Arc, + _v8_heap_total_gauge: ObservableGauge, } impl BridgeQueryPlannerPool { @@ -119,21 +127,54 @@ impl BridgeQueryPlannerPool { }); } let sender_for_gauge = sender.clone(); - let pool_size_gauge = meter_provider() - .meter("apollo/router") + let meter = meter_provider().meter("apollo/router"); + let pool_size_gauge = meter .u64_observable_gauge("apollo.router.query_planning.queued") .with_callback(move |m| m.observe(sender_for_gauge.len() as u64, &[])) .init(); + let (v8_heap_used, _v8_heap_used_gauge) = Self::create_heap_used_gauge(&meter); + let (v8_heap_total, _v8_heap_total_gauge) = Self::create_heap_total_gauge(&meter); + Ok(Self { js_planners: planners, sender, schema, subgraph_schemas, _pool_size_gauge: pool_size_gauge, + v8_heap_used, + _v8_heap_used_gauge, + v8_heap_total, + _v8_heap_total_gauge, }) } + fn create_heap_used_gauge(meter: &Meter) -> (Arc, ObservableGauge) { + let current_heap_used = Arc::new(AtomicU64::new(0)); + let current_heap_used_for_gauge = current_heap_used.clone(); + let heap_used_gauge = meter + .u64_observable_gauge("apollo.router.v8.heap.used") + .with_description("V8 heap used, in bytes") + .with_callback(move |i| { + i.observe(current_heap_used_for_gauge.load(Ordering::SeqCst), &[]) + }) + .init(); + (current_heap_used, heap_used_gauge) + } + + fn create_heap_total_gauge(meter: &Meter) -> (Arc, ObservableGauge) { + let current_heap_total = Arc::new(AtomicU64::new(0)); + let current_heap_total_for_gauge = current_heap_total.clone(); + let heap_total_gauge = meter + .u64_observable_gauge("apollo.router.v8.heap.total") + .with_description("V8 heap total, in bytes") + .with_callback(move |i| { + i.observe(current_heap_total_for_gauge.load(Ordering::SeqCst), &[]) + }) + .init(); + (current_heap_total, heap_total_gauge) + } + pub(crate) fn planners(&self) -> Vec>> { self.js_planners.clone() } @@ -147,6 +188,18 @@ impl BridgeQueryPlannerPool { ) -> Arc>>> { self.subgraph_schemas.clone() } + + async fn get_v8_metrics( + planner: Arc>, + v8_heap_used: Arc, + v8_heap_total: Arc, + ) { + let metrics = planner.get_heap_statistics().await; + if let Ok(metrics) = metrics { + v8_heap_used.store(metrics.heap_used, Ordering::SeqCst); + v8_heap_total.store(metrics.heap_total, Ordering::SeqCst); + } + } } impl tower::Service for BridgeQueryPlannerPool { @@ -173,6 +226,20 @@ impl tower::Service for BridgeQueryPlannerPool { let (response_sender, response_receiver) = oneshot::channel(); let sender = self.sender.clone(); + let get_metrics_future = + if let Some(bridge_query_planner) = self.js_planners.first().cloned() { + let v8_heap_used = self.v8_heap_used.clone(); + let v8_heap_total = self.v8_heap_total.clone(); + + Some(Self::get_v8_metrics( + bridge_query_planner, + v8_heap_used, + v8_heap_total, + )) + } else { + None + }; + Box::pin(async move { let start = Instant::now(); let _ = sender.send((req, response_sender)).await; @@ -187,6 +254,11 @@ impl tower::Service for BridgeQueryPlannerPool { start.elapsed().as_secs_f64() ); + if let Some(f) = get_metrics_future { + // execute in a separate task to avoid blocking the request + tokio::task::spawn(f); + } + res }) } From 1d7a026afa7a06da5f96bfd8a660351fc7abe40f Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Tue, 6 Aug 2024 18:40:43 +0200 Subject: [PATCH 02/13] changeset --- .changesets/feat_geal_v8_heap_statistics.md | 7 +++++++ .../telemetry/instrumentation/standard-instruments.mdx | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 .changesets/feat_geal_v8_heap_statistics.md diff --git a/.changesets/feat_geal_v8_heap_statistics.md b/.changesets/feat_geal_v8_heap_statistics.md new file mode 100644 index 0000000000..1a596bdba8 --- /dev/null +++ b/.changesets/feat_geal_v8_heap_statistics.md @@ -0,0 +1,7 @@ +### add metrics tracking the V8 heap usage ([PR #5781](https://github.com/apollographql/router/pull/5781)) + +We add new gauge metrics tracking V8 memory usage: +- `apollo.router.v8.heap.used`: heap memory used by V8, in bytes +- `apollo.router.v8.heap.total`: total heap allocated by V8, in bytes + +By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/5781 \ No newline at end of file diff --git a/docs/source/configuration/telemetry/instrumentation/standard-instruments.mdx b/docs/source/configuration/telemetry/instrumentation/standard-instruments.mdx index 1a3358a38e..82ba237998 100644 --- a/docs/source/configuration/telemetry/instrumentation/standard-instruments.mdx +++ b/docs/source/configuration/telemetry/instrumentation/standard-instruments.mdx @@ -65,6 +65,8 @@ The coprocessor operations metric has the following attributes: - `apollo.router.query_planning.plan.duration` - Histogram of plan durations isolated to query planning time only. - `apollo.router.query_planning.total.duration` - Histogram of plan durations including queue time. - `apollo.router.query_planning.queued` - A gauge of the number of queued plans requests. +- `apollo.router.v8.heap.used` - heap memory used by V8, in bytes. +- `apollo.router.v8.heap.total` - total heap allocated by V8, in bytes. ### Uplink From 09e54532629f95bd07b72064d5d0d99f7d4fb6fb Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Tue, 6 Aug 2024 18:55:32 +0200 Subject: [PATCH 03/13] add a test --- .../bridge_query_planner_pool.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/apollo-router/src/query_planner/bridge_query_planner_pool.rs b/apollo-router/src/query_planner/bridge_query_planner_pool.rs index 3b154fd26e..c2dadbaef2 100644 --- a/apollo-router/src/query_planner/bridge_query_planner_pool.rs +++ b/apollo-router/src/query_planner/bridge_query_planner_pool.rs @@ -263,3 +263,39 @@ impl tower::Service for BridgeQueryPlannerPool { }) } } + +#[cfg(test)] + +mod tests { + use crate::Context; + + use super::*; + + #[tokio::test] + async fn test_v8_metrics() { + let sdl = include_str!("../testdata/minimal_fed2_supergraph.graphql"); + let config = Arc::default(); + let schema = Schema::parse(sdl, &config).unwrap(); + + let mut pool = + BridgeQueryPlannerPool::new(Arc::new(schema), config, NonZeroUsize::new(2).unwrap()) + .await + .unwrap(); + pool.call(QueryPlannerRequest::new( + include_str!("../query_planner/testdata/query.graphql").to_string(), + None, + Context::new(), + )) + .await + .unwrap(); + + let metrics = crate::metrics::collect_metrics(); + let heap_used = metrics.find("apollo.router.v8.heap.used").unwrap(); + let heap_total = metrics.find("apollo.router.v8.heap.total").unwrap(); + + println!( + "got heap_used: {:?}, heap_total: {:?}", + heap_used, heap_total + ); + } +} From 03368e3cf8478bd3de0689618d50ac1f07b76f49 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Wed, 7 Aug 2024 09:44:35 +0200 Subject: [PATCH 04/13] fix --- .../bridge_query_planner_pool.rs | 81 ++++++++++++++----- 1 file changed, 59 insertions(+), 22 deletions(-) diff --git a/apollo-router/src/query_planner/bridge_query_planner_pool.rs b/apollo-router/src/query_planner/bridge_query_planner_pool.rs index c2dadbaef2..7024f0c6c8 100644 --- a/apollo-router/src/query_planner/bridge_query_planner_pool.rs +++ b/apollo-router/src/query_planner/bridge_query_planner_pool.rs @@ -136,6 +136,16 @@ impl BridgeQueryPlannerPool { let (v8_heap_used, _v8_heap_used_gauge) = Self::create_heap_used_gauge(&meter); let (v8_heap_total, _v8_heap_total_gauge) = Self::create_heap_total_gauge(&meter); + // initialize v8 metrics + if let Some(bridge_query_planner) = planners.first().cloned() { + Self::get_v8_metrics( + bridge_query_planner, + v8_heap_used.clone(), + v8_heap_total.clone(), + ) + .await; + } + Ok(Self { js_planners: planners, sender, @@ -267,35 +277,62 @@ impl tower::Service for BridgeQueryPlannerPool { #[cfg(test)] mod tests { - use crate::Context; + use opentelemetry_sdk::metrics::data::Gauge; use super::*; + use crate::metrics::FutureMetricsExt; + use crate::spec::Query; + use crate::Context; #[tokio::test] async fn test_v8_metrics() { - let sdl = include_str!("../testdata/minimal_fed2_supergraph.graphql"); + let sdl = include_str!("../testdata/supergraph.graphql"); let config = Arc::default(); - let schema = Schema::parse(sdl, &config).unwrap(); - - let mut pool = - BridgeQueryPlannerPool::new(Arc::new(schema), config, NonZeroUsize::new(2).unwrap()) + let schema = Arc::new(Schema::parse(sdl, &config).unwrap()); + + async move { + let mut pool = BridgeQueryPlannerPool::new( + schema.clone(), + config.clone(), + NonZeroUsize::new(2).unwrap(), + ) + .await + .unwrap(); + let query = "query { me { name } }".to_string(); + + let doc = Query::parse_document(&query, None, &schema, &config).unwrap(); + let context = Context::new(); + context.extensions().with_lock(|mut lock| lock.insert(doc)); + + pool.call(QueryPlannerRequest::new(query, None, context)) .await .unwrap(); - pool.call(QueryPlannerRequest::new( - include_str!("../query_planner/testdata/query.graphql").to_string(), - None, - Context::new(), - )) - .await - .unwrap(); - - let metrics = crate::metrics::collect_metrics(); - let heap_used = metrics.find("apollo.router.v8.heap.used").unwrap(); - let heap_total = metrics.find("apollo.router.v8.heap.total").unwrap(); - - println!( - "got heap_used: {:?}, heap_total: {:?}", - heap_used, heap_total - ); + + let metrics = crate::metrics::collect_metrics(); + let heap_used = metrics.find("apollo.router.v8.heap.used").unwrap(); + let heap_total = metrics.find("apollo.router.v8.heap.total").unwrap(); + + println!( + "got heap_used: {:?}, heap_total: {:?}", + heap_used + .data + .as_any() + .downcast_ref::>() + .unwrap() + .data_points[0] + .value, + heap_total + .data + .as_any() + .downcast_ref::>() + .unwrap() + .data_points[0] + .value + ); + } + .with_metrics() + .await; + + panic!() } } From 8f06e33c863b471d71fcbfe1b4c8b2004510c54e Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Wed, 7 Aug 2024 09:47:29 +0200 Subject: [PATCH 05/13] remove explicit panic --- apollo-router/src/query_planner/bridge_query_planner_pool.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apollo-router/src/query_planner/bridge_query_planner_pool.rs b/apollo-router/src/query_planner/bridge_query_planner_pool.rs index 7024f0c6c8..c8c364d28e 100644 --- a/apollo-router/src/query_planner/bridge_query_planner_pool.rs +++ b/apollo-router/src/query_planner/bridge_query_planner_pool.rs @@ -101,7 +101,7 @@ impl BridgeQueryPlannerPool { })? .subgraph_schemas(); - let planners = bridge_query_planners + let planners: Vec<_> = bridge_query_planners .iter() .map(|p| p.planner().clone()) .collect(); @@ -332,7 +332,5 @@ mod tests { } .with_metrics() .await; - - panic!() } } From 9e9447d171224820ded055d70bb7b83505299782 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Thu, 8 Aug 2024 14:32:15 +0200 Subject: [PATCH 06/13] update router-bridge --- Cargo.lock | 31 ++++--------------------------- apollo-router/Cargo.toml | 2 +- fuzz/Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0de85308b3..087d5e6560 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -571,7 +571,7 @@ dependencies = [ "reqwest", "rhai", "rmp", - "router-bridge 0.5.29+v2.8.3", + "router-bridge", "rstack", "rust-embed", "rustls", @@ -6091,32 +6091,9 @@ dependencies = [ [[package]] name = "router-bridge" -version = "0.5.27+v2.8.1" +version = "0.5.30+v2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "288fa40fc4e0a76fb911410e05d4525e8bf7558622bd02403f89f871c4d0785b" -dependencies = [ - "anyhow", - "async-channel 1.9.0", - "deno_console", - "deno_core", - "deno_url", - "deno_web", - "deno_webidl", - "rand 0.8.5", - "serde", - "serde_json", - "thiserror", - "tokio", - "tower", - "tower-service", - "tracing", - "which", -] - -[[package]] -name = "router-bridge" -version = "0.5.29+v2.8.3" -source = "git+https://github.com/apollographql/federation-rs.git?branch=geal/get_heap_statistics#989735fc863d7b4ad6c488fe8ee37ec29fe014e7" +checksum = "9b2b67ccfc13842df12e473cbb93fe306a8dc3d120cfa2be57e3537c71bf0e63" dependencies = [ "anyhow", "async-channel 1.9.0", @@ -6151,7 +6128,7 @@ dependencies = [ "libfuzzer-sys", "log", "reqwest", - "router-bridge 0.5.27+v2.8.1", + "router-bridge", "schemars", "serde", "serde_json", diff --git a/apollo-router/Cargo.toml b/apollo-router/Cargo.toml index c8a5e3496b..ea78989336 100644 --- a/apollo-router/Cargo.toml +++ b/apollo-router/Cargo.toml @@ -195,7 +195,7 @@ regex = "1.10.5" reqwest.workspace = true # note: this dependency should _always_ be pinned, prefix the version with an `=` -router-bridge = { branch = "geal/get_heap_statistics", git = "https://github.com/apollographql/federation-rs.git" } +router-bridge = "=0.5.30+v2.8.3" rust-embed = { version = "8.4.0", features = ["include-exclude"] } rustls = "0.21.12" diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 451ea09375..781b40cc11 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -20,7 +20,7 @@ reqwest = { workspace = true, features = ["json", "blocking"] } serde_json.workspace = true tokio.workspace = true # note: this dependency should _always_ be pinned, prefix the version with an `=` -router-bridge = "=0.5.27+v2.8.1" +router-bridge = "=0.5.30+v2.8.3" [dev-dependencies] anyhow = "1" From 04e354f5d3964833a2d05015123966719540e9aa Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Thu, 8 Aug 2024 15:48:56 +0200 Subject: [PATCH 07/13] update federation version in tests --- apollo-router/tests/integration/redis.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apollo-router/tests/integration/redis.rs b/apollo-router/tests/integration/redis.rs index cb8b79959e..6b0ff6b404 100644 --- a/apollo-router/tests/integration/redis.rs +++ b/apollo-router/tests/integration/redis.rs @@ -26,7 +26,7 @@ async fn query_planner_cache() -> Result<(), BoxError> { // 2. run `docker compose up -d` and connect to the redis container by running `docker-compose exec redis /bin/bash`. // 3. Run the `redis-cli` command from the shell and start the redis `monitor` command. // 4. Run this test and yank the updated cache key from the redis logs. - let known_cache_key = "plan:0:v2.8.1:16385ebef77959fcdc520ad507eb1f7f7df28f1d54a0569e3adabcb4cd00d7ce:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:3106dfc3339d8c3f3020434024bff0f566a8be5995199954db5a7525a7d7e67a"; + let known_cache_key = "plan:0:v2.8.3:16385ebef77959fcdc520ad507eb1f7f7df28f1d54a0569e3adabcb4cd00d7ce:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:3106dfc3339d8c3f3020434024bff0f566a8be5995199954db5a7525a7d7e67a"; let config = RedisConfig::from_url("redis://127.0.0.1:6379").unwrap(); let client = RedisClient::new(config, None, None, None); @@ -921,7 +921,7 @@ async fn connection_failure_blocks_startup() { async fn query_planner_redis_update_query_fragments() { test_redis_query_plan_config_update( include_str!("fixtures/query_planner_redis_config_update_query_fragments.router.yaml"), - "plan:0:v2.8.1:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:9054d19854e1d9e282ac7645c612bc70b8a7143d43b73d44dade4a5ec43938b4", + "plan:0:v2.8.3:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:9054d19854e1d9e282ac7645c612bc70b8a7143d43b73d44dade4a5ec43938b4", ) .await; } @@ -940,7 +940,7 @@ async fn query_planner_redis_update_planner_mode() { async fn query_planner_redis_update_introspection() { test_redis_query_plan_config_update( include_str!("fixtures/query_planner_redis_config_update_introspection.router.yaml"), - "plan:0:v2.8.1:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:04b3051125b5994fba6b0a22b2d8b4246cadc145be030c491a3431655d2ba07a", + "plan:0:v2.8.3:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:04b3051125b5994fba6b0a22b2d8b4246cadc145be030c491a3431655d2ba07a", ) .await; } @@ -949,7 +949,7 @@ async fn query_planner_redis_update_introspection() { async fn query_planner_redis_update_defer() { test_redis_query_plan_config_update( include_str!("fixtures/query_planner_redis_config_update_defer.router.yaml"), - "plan:0:v2.8.1:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:3b7241b0db2cd878b79c0810121953ba544543f3cb2692aaf1a59184470747b0", + "plan:0:v2.8.3:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:3b7241b0db2cd878b79c0810121953ba544543f3cb2692aaf1a59184470747b0", ) .await; } @@ -960,7 +960,7 @@ async fn query_planner_redis_update_type_conditional_fetching() { include_str!( "fixtures/query_planner_redis_config_update_type_conditional_fetching.router.yaml" ), - "plan:0:v2.8.1:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:0ca695a8c4c448b65fa04229c663f44150af53b184ebdcbb0ad6862290efed76", + "plan:0:v2.8.3:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:0ca695a8c4c448b65fa04229c663f44150af53b184ebdcbb0ad6862290efed76", ) .await; } @@ -971,7 +971,7 @@ async fn query_planner_redis_update_reuse_query_fragments() { include_str!( "fixtures/query_planner_redis_config_update_reuse_query_fragments.router.yaml" ), - "plan:0:v2.8.1:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:f7c04319556397ec4b550aa5aaa96c73689cee09026b661b6a9fc20b49e6fa77", + "plan:0:v2.8.3:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:f7c04319556397ec4b550aa5aaa96c73689cee09026b661b6a9fc20b49e6fa77", ) .await; } @@ -994,7 +994,7 @@ async fn test_redis_query_plan_config_update(updated_config: &str, new_cache_key router.assert_started().await; router.clear_redis_cache().await; - let starting_key = "plan:0:v2.8.1:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:4a5827854a6d2efc85045f0d5bede402e15958390f1073d2e77df56188338e5a"; + let starting_key = "plan:0:v2.8.3:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:4a5827854a6d2efc85045f0d5bede402e15958390f1073d2e77df56188338e5a"; router.execute_default_query().await; router.assert_redis_cache_contains(starting_key, None).await; router.update_config(updated_config).await; From 82a506ffb72435aa375debf8e4d40292ac21b1e2 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Thu, 8 Aug 2024 16:34:46 +0200 Subject: [PATCH 08/13] add a changeset for the federation update --- .changesets/feat_update_federation.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .changesets/feat_update_federation.md diff --git a/.changesets/feat_update_federation.md b/.changesets/feat_update_federation.md new file mode 100644 index 0000000000..b8299fd533 --- /dev/null +++ b/.changesets/feat_update_federation.md @@ -0,0 +1,9 @@ +### Update federation to 2.8.3 ([PR #5781](https://github.com/apollographql/router/pull/5781)) + +> [!IMPORTANT] +> If you have enabled [Distributed query plan caching](https://www.apollographql.com/docs/router/configuration/distributed-caching/#distributed-query-plan-caching), this release changes the hashing algorithm used for the cache keys. On account of this, you should anticipate additional cache regeneration cost when updating between these versions while the new hashing algorithm comes into service. + +This updates the router from federation version 2.8.1 to 2.8.3. This updates addresses the following points: +- + +By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/5781 \ No newline at end of file From 2008d8ac6f2d1e267184fdbba063869bff3f6b9c Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Thu, 8 Aug 2024 17:42:35 +0200 Subject: [PATCH 09/13] Update feat_update_federation.md --- .changesets/feat_update_federation.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.changesets/feat_update_federation.md b/.changesets/feat_update_federation.md index b8299fd533..b3c0670daa 100644 --- a/.changesets/feat_update_federation.md +++ b/.changesets/feat_update_federation.md @@ -3,7 +3,6 @@ > [!IMPORTANT] > If you have enabled [Distributed query plan caching](https://www.apollographql.com/docs/router/configuration/distributed-caching/#distributed-query-plan-caching), this release changes the hashing algorithm used for the cache keys. On account of this, you should anticipate additional cache regeneration cost when updating between these versions while the new hashing algorithm comes into service. -This updates the router from federation version 2.8.1 to 2.8.3. This updates addresses the following points: -- +This updates the router from federation version 2.8.1 to 2.8.3, with a [fix for fragment generation](https://github.com/apollographql/federation/pull/3043). -By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/5781 \ No newline at end of file +By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/5781 From ed41e1b0b39e01044309b90dc22e7a2819013f7e Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Mon, 19 Aug 2024 18:08:54 +0200 Subject: [PATCH 10/13] Update .changesets/feat_geal_v8_heap_statistics.md Co-authored-by: Edward Huang --- .changesets/feat_geal_v8_heap_statistics.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changesets/feat_geal_v8_heap_statistics.md b/.changesets/feat_geal_v8_heap_statistics.md index 1a596bdba8..c091b108a8 100644 --- a/.changesets/feat_geal_v8_heap_statistics.md +++ b/.changesets/feat_geal_v8_heap_statistics.md @@ -1,6 +1,6 @@ -### add metrics tracking the V8 heap usage ([PR #5781](https://github.com/apollographql/router/pull/5781)) +### Add V8 heap usage metrics ([PR #5781](https://github.com/apollographql/router/pull/5781)) -We add new gauge metrics tracking V8 memory usage: +The router supports new gauge metrics for tracking heap memory usage of the V8 Javascript engine: - `apollo.router.v8.heap.used`: heap memory used by V8, in bytes - `apollo.router.v8.heap.total`: total heap allocated by V8, in bytes From 9e710a5e093e0f7114d66b7938ff23ddcf379883 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Tue, 20 Aug 2024 09:25:06 +0200 Subject: [PATCH 11/13] add descriptiuon and unit --- apollo-router/src/query_planner/bridge_query_planner_pool.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apollo-router/src/query_planner/bridge_query_planner_pool.rs b/apollo-router/src/query_planner/bridge_query_planner_pool.rs index c8c364d28e..25ff3d26f8 100644 --- a/apollo-router/src/query_planner/bridge_query_planner_pool.rs +++ b/apollo-router/src/query_planner/bridge_query_planner_pool.rs @@ -11,6 +11,7 @@ use async_channel::Sender; use futures::future::BoxFuture; use opentelemetry::metrics::MeterProvider; use opentelemetry::metrics::ObservableGauge; +use opentelemetry::metrics::Unit; use opentelemetry_api::metrics::Meter; use router_bridge::planner::Planner; use tokio::sync::oneshot; @@ -130,6 +131,7 @@ impl BridgeQueryPlannerPool { let meter = meter_provider().meter("apollo/router"); let pool_size_gauge = meter .u64_observable_gauge("apollo.router.query_planning.queued") + .with_description("Number of queries waiting to be planned") .with_callback(move |m| m.observe(sender_for_gauge.len() as u64, &[])) .init(); @@ -165,6 +167,7 @@ impl BridgeQueryPlannerPool { let heap_used_gauge = meter .u64_observable_gauge("apollo.router.v8.heap.used") .with_description("V8 heap used, in bytes") + .with_unit(Unit::new("bytes")) .with_callback(move |i| { i.observe(current_heap_used_for_gauge.load(Ordering::SeqCst), &[]) }) @@ -178,6 +181,7 @@ impl BridgeQueryPlannerPool { let heap_total_gauge = meter .u64_observable_gauge("apollo.router.v8.heap.total") .with_description("V8 heap total, in bytes") + .with_unit(Unit::new("bytes")) .with_callback(move |i| { i.observe(current_heap_total_for_gauge.load(Ordering::SeqCst), &[]) }) From ba0dea41e31eab09675b76e3522733c5c90412cd Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Tue, 20 Aug 2024 10:11:24 +0200 Subject: [PATCH 12/13] update unit --- apollo-router/src/query_planner/bridge_query_planner_pool.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apollo-router/src/query_planner/bridge_query_planner_pool.rs b/apollo-router/src/query_planner/bridge_query_planner_pool.rs index 25ff3d26f8..4798e8b76e 100644 --- a/apollo-router/src/query_planner/bridge_query_planner_pool.rs +++ b/apollo-router/src/query_planner/bridge_query_planner_pool.rs @@ -167,7 +167,7 @@ impl BridgeQueryPlannerPool { let heap_used_gauge = meter .u64_observable_gauge("apollo.router.v8.heap.used") .with_description("V8 heap used, in bytes") - .with_unit(Unit::new("bytes")) + .with_unit(Unit::new("By")) .with_callback(move |i| { i.observe(current_heap_used_for_gauge.load(Ordering::SeqCst), &[]) }) @@ -181,7 +181,7 @@ impl BridgeQueryPlannerPool { let heap_total_gauge = meter .u64_observable_gauge("apollo.router.v8.heap.total") .with_description("V8 heap total, in bytes") - .with_unit(Unit::new("bytes")) + .with_unit(Unit::new("By")) .with_callback(move |i| { i.observe(current_heap_total_for_gauge.load(Ordering::SeqCst), &[]) }) From b139d3970297e8066876861af8fd55ab40c1a402 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Tue, 20 Aug 2024 10:17:44 +0200 Subject: [PATCH 13/13] add unit --- apollo-router/src/query_planner/bridge_query_planner_pool.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/apollo-router/src/query_planner/bridge_query_planner_pool.rs b/apollo-router/src/query_planner/bridge_query_planner_pool.rs index 4798e8b76e..bb75124df1 100644 --- a/apollo-router/src/query_planner/bridge_query_planner_pool.rs +++ b/apollo-router/src/query_planner/bridge_query_planner_pool.rs @@ -132,6 +132,7 @@ impl BridgeQueryPlannerPool { let pool_size_gauge = meter .u64_observable_gauge("apollo.router.query_planning.queued") .with_description("Number of queries waiting to be planned") + .with_unit(Unit::new("query")) .with_callback(move |m| m.observe(sender_for_gauge.len() as u64, &[])) .init();