diff --git a/apollo-federation/src/lib.rs b/apollo-federation/src/lib.rs index 99d340e881..6ce5b82a08 100644 --- a/apollo-federation/src/lib.rs +++ b/apollo-federation/src/lib.rs @@ -59,6 +59,19 @@ use crate::subgraph::ValidSubgraph; pub use crate::supergraph::ValidFederationSubgraph; pub use crate::supergraph::ValidFederationSubgraphs; +/// Part of the key for distributed query plan cache. +/// +/// Update this every time the cache key or the query plan format has to change, +/// specifically if an old serialized query plan cannot always be deserialized and used correctly +/// in the current Router version. +/// +/// When changed it MUST BE CALLED OUT PROMINENTLY IN THE CHANGELOG. +/// +/// Historically this was based in part on the federation version extracted from the build metadata +/// in the router-bridge crate version number (e.g. `0.6.4+v2.9.3`) but any arbitrary string works. +/// The next version can be "2", and this paragraph removed. +pub const CACHE_KEY_VERSION: &str = "1:federation:v2.9.3"; + pub(crate) type SupergraphSpecs = (&'static LinkSpecDefinition, &'static JoinSpecDefinition); pub(crate) fn validate_supergraph_for_query_planning( diff --git a/apollo-router/build/main.rs b/apollo-router/build/main.rs index 763d894df0..b323c668bb 100644 --- a/apollo-router/build/main.rs +++ b/apollo-router/build/main.rs @@ -1,37 +1,5 @@ -use std::fs; -use std::path::PathBuf; - mod studio; fn main() -> Result<(), Box> { - let cargo_manifest: serde_json::Value = basic_toml::from_str( - &fs::read_to_string(PathBuf::from(&env!("CARGO_MANIFEST_DIR")).join("Cargo.toml")) - .expect("could not read Cargo.toml"), - ) - .expect("could not parse Cargo.toml"); - - let router_bridge = cargo_manifest - .get("dependencies") - .expect("Cargo.toml does not contain dependencies") - .as_object() - .expect("Cargo.toml dependencies key is not an object") - .get("router-bridge") - .expect("Cargo.toml dependencies does not have an entry for router-bridge"); - let router_bridge_version = router_bridge - .as_str() - .or_else(|| { - router_bridge - .as_object() - .and_then(|o| o.get("version")) - .and_then(|version| version.as_str()) - }) - .expect("router-bridge does not have a version"); - - let mut it = router_bridge_version.split('+'); - let _ = it.next(); - let fed_version = it.next().expect("invalid router-bridge version format"); - - println!("cargo:rustc-env=FEDERATION_VERSION={fed_version}"); - studio::main() } diff --git a/apollo-router/src/query_planner/bridge_query_planner.rs b/apollo-router/src/query_planner/bridge_query_planner.rs index cc058b5555..bbe4314ca2 100644 --- a/apollo-router/src/query_planner/bridge_query_planner.rs +++ b/apollo-router/src/query_planner/bridge_query_planner.rs @@ -859,9 +859,6 @@ pub(crate) fn metric_rust_qp_init(init_error_kind: Option<&'static str>) { #[cfg(test)] mod tests { - use std::fs; - use std::path::PathBuf; - use serde_json::json; use test_log::test; use tower::Service; @@ -1405,28 +1402,6 @@ mod tests { .await } - #[test] - fn router_bridge_dependency_is_pinned() { - let cargo_manifest: serde_json::Value = basic_toml::from_str( - &fs::read_to_string(PathBuf::from(&env!("CARGO_MANIFEST_DIR")).join("Cargo.toml")) - .expect("could not read Cargo.toml"), - ) - .expect("could not parse Cargo.toml"); - let router_bridge_version = cargo_manifest - .get("dependencies") - .expect("Cargo.toml does not contain dependencies") - .as_object() - .expect("Cargo.toml dependencies key is not an object") - .get("router-bridge") - .expect("Cargo.toml dependencies does not have an entry for router-bridge") - .as_str() - .unwrap_or_default(); - assert!( - router_bridge_version.contains('='), - "router-bridge in Cargo.toml is not pinned with a '=' prefix" - ); - } - #[tokio::test] async fn test_both_mode() { let mut harness = crate::TestHarness::builder() diff --git a/apollo-router/src/query_planner/caching_query_planner.rs b/apollo-router/src/query_planner/caching_query_planner.rs index 209adcc856..09837909c0 100644 --- a/apollo-router/src/query_planner/caching_query_planner.rs +++ b/apollo-router/src/query_planner/caching_query_planner.rs @@ -5,6 +5,9 @@ use std::sync::Arc; use std::task; use apollo_compiler::validation::Valid; +/// Update this key every time the cache key or the query plan format has to change. +/// When changed it MUST BE CALLED OUT PROMINENTLY IN THE CHANGELOG. +use apollo_federation::CACHE_KEY_VERSION; use futures::future::BoxFuture; use indexmap::IndexMap; use query_planner::QueryPlannerPlugin; @@ -632,11 +635,6 @@ pub(crate) struct CachingQueryKey { pub(crate) config_mode: Arc, } -// Update this key every time the cache key or the query plan format has to change. -// When changed it MUST BE CALLED OUT PROMINENTLY IN THE CHANGELOG. -const CACHE_KEY_VERSION: usize = 1; -const FEDERATION_VERSION: &str = std::env!("FEDERATION_VERSION"); - impl std::fmt::Display for CachingQueryKey { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut hasher = Sha256::new(); @@ -654,8 +652,8 @@ impl std::fmt::Display for CachingQueryKey { write!( f, - "plan:cache:{}:federation:{}:{}:opname:{}:metadata:{}", - CACHE_KEY_VERSION, FEDERATION_VERSION, self.hash, operation, metadata, + "plan:cache:{}:{}:opname:{}:metadata:{}", + CACHE_KEY_VERSION, self.hash, operation, metadata, ) } }