diff --git a/apollo-router/src/plugins/cache/invalidation.rs b/apollo-router/src/plugins/cache/invalidation.rs index a2c2bc80d6..77736f6598 100644 --- a/apollo-router/src/plugins/cache/invalidation.rs +++ b/apollo-router/src/plugins/cache/invalidation.rs @@ -161,7 +161,7 @@ async fn handle_request( ); // FIXME: configurable batch size - let mut stream = storage.scan(key_prefix.clone(), Some(10)); + let mut stream = storage.scan(key_prefix.clone(), Some(100)); let mut count = 0u64; let mut error = None; @@ -184,7 +184,6 @@ async fn handle_request( .map(|k| RedisKey(k.to_string())) .collect::>(); if !keys.is_empty() { - tracing::debug!("deleting keys: {keys:?}"); count += keys.len() as u64; storage.delete(keys).await; @@ -270,10 +269,10 @@ impl InvalidationRequest { fn key_prefix(&self) -> String { match self { InvalidationRequest::Subgraph { subgraph } => { - format!("version:{ENTITY_CACHE_VERSION}:subgraph:{subgraph}*",) + format!("version:{ENTITY_CACHE_VERSION}:subgraph:{subgraph}:*",) } InvalidationRequest::Type { subgraph, r#type } => { - format!("version:{ENTITY_CACHE_VERSION}:subgraph:{subgraph}:type:{type}*",) + format!("version:{ENTITY_CACHE_VERSION}:subgraph:{subgraph}:type:{type}:*",) } InvalidationRequest::Entity { subgraph, @@ -281,7 +280,7 @@ impl InvalidationRequest { key, } => { let entity_key = hash_entity_key(key); - format!("version:{ENTITY_CACHE_VERSION}:subgraph:{subgraph}:type:{type}:entity:{entity_key}*") + format!("version:{ENTITY_CACHE_VERSION}:subgraph:{subgraph}:type:{type}:entity:{entity_key}:*") } } } diff --git a/apollo-router/tests/common.rs b/apollo-router/tests/common.rs index 4265605971..35a1115495 100644 --- a/apollo-router/tests/common.rs +++ b/apollo-router/tests/common.rs @@ -551,7 +551,6 @@ impl IntegrationTest { async move { let span = info_span!("client_request"); let span_id = span.context().span().span_context().trace_id(); - dbg!(&span_id); async move { let client = reqwest::Client::new(); @@ -574,7 +573,6 @@ impl IntegrationTest { let mut request = builder.json(&query).build().unwrap(); telemetry.inject_context(&mut request); - dbg!(&request.headers()); request.headers_mut().remove(ACCEPT); match client.execute(request).await { Ok(response) => (span_id, response), diff --git a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/configuration.yaml b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/configuration.yaml index b297fee443..e283bbdace 100644 --- a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/configuration.yaml +++ b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/configuration.yaml @@ -12,6 +12,12 @@ preview_entity_cache: all: enabled: true subgraphs: - reviews: + invalidation-entity-key-reviews: ttl: 120s - enabled: true \ No newline at end of file + enabled: true + +telemetry: + exporters: + logging: + stdout: + format: text \ No newline at end of file diff --git a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/skipped.json b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/plan.json similarity index 75% rename from apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/skipped.json rename to apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/plan.json index b505259570..c08682fff8 100644 --- a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/skipped.json +++ b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/plan.json @@ -7,11 +7,14 @@ "schema_path": "./supergraph.graphql", "configuration_path": "./configuration.yaml", "subgraphs": { - "products": { + "invalidation-entity-key-products": { "requests": [ { "request": { - "body": {"query":"{topProducts{__typename upc}}"} + "body": { + "query":"query InvalidationEntityKey__invalidation_entity_key_products__0{topProducts{__typename upc}}", + "operationName": "InvalidationEntityKey__invalidation_entity_key_products__0" + } }, "response": { "headers": { @@ -23,12 +26,13 @@ } ] }, - "reviews": { + "invalidation-entity-key-reviews": { "requests": [ { "request": { "body": { - "query":"query($representations:[_Any!]!){_entities(representations:$representations){...on Product{reviews{body}}}}", + "query":"query InvalidationEntityKey__invalidation_entity_key_reviews__1($representations:[_Any!]!){_entities(representations:$representations){...on Product{reviews{body}}}}", + "operationName": "InvalidationEntityKey__invalidation_entity_key_reviews__1", "variables":{"representations":[{"upc":"0","__typename":"Product"},{"upc":"1","__typename":"Product"}]} } }, @@ -59,7 +63,7 @@ { "type": "Request", "request": { - "query": "{ topProducts { reviews { body } } }" + "query": "query InvalidationEntityKey { topProducts { reviews { body } } }" }, "expected_response": { "data":{ @@ -81,11 +85,13 @@ { "type": "ReloadSubgraphs", "subgraphs": { - "reviews": { + "invalidation-entity-key-reviews": { "requests": [ { "request": { - "body": {"query":"mutation{invalidateProductReview}"} + "body": { + "query":"mutation InvalidationEntityKey__invalidation_entity_key_reviews__0{invalidateProductReview}" + } }, "response": { "headers": { @@ -96,7 +102,7 @@ "extensions": { "invalidation": [{ "kind": "entity", - "subgraph": "reviews", + "subgraph": "invalidation-entity-key-reviews", "type": "Product", "key": { "upc": "1" @@ -109,7 +115,7 @@ { "request": { "body": { - "query":"query($representations:[_Any!]!){_entities(representations:$representations){...on Product{reviews{body}}}}", + "query":"query InvalidationEntityKey__invalidation_entity_key_reviews__1($representations:[_Any!]!){_entities(representations:$representations){...on Product{reviews{body}}}}", "variables":{"representations":[{"upc":"1","__typename":"Product"}]} } }, @@ -129,7 +135,7 @@ { "type": "Request", "request": { - "query": "{ topProducts { reviews { body } } }" + "query": "query InvalidationEntityKey { topProducts { reviews { body } } }" }, "expected_response": { "data":{ @@ -151,7 +157,7 @@ { "type": "Request", "request": { - "query": "mutation { invalidateProductReview }" + "query": "mutation InvalidationEntityKey { invalidateProductReview }" }, "expected_response": { "data":{ @@ -162,7 +168,7 @@ { "type": "Request", "request": { - "query": "{ topProducts { reviews { body } } }" + "query": "query InvalidationEntityKey { topProducts { reviews { body } } }" }, "expected_response":{ "data":{ @@ -170,12 +176,12 @@ }, "errors":[ { - "message":"HTTP fetch failed from 'reviews': 500: Internal Server Error", - "extensions":{"code":"SUBREQUEST_HTTP_ERROR","service":"reviews","reason":"500: Internal Server Error","http":{"status":500}} + "message":"HTTP fetch failed from 'invalidation-entity-key-reviews': 500: Internal Server Error", + "extensions":{"code":"SUBREQUEST_HTTP_ERROR","service":"invalidation-entity-key-reviews","reason":"500: Internal Server Error","http":{"status":500}} }, { - "message":"service 'reviews' response was malformed: {}", - "extensions":{"service":"reviews","reason":"{}","code":"SUBREQUEST_MALFORMED_RESPONSE"} + "message":"service 'invalidation-entity-key-reviews' response was malformed: {}", + "extensions":{"service":"invalidation-entity-key-reviews","reason":"{}","code":"SUBREQUEST_MALFORMED_RESPONSE"} } ] } @@ -183,12 +189,12 @@ { "type": "ReloadSubgraphs", "subgraphs": { - "reviews": { + "invalidation-entity-key-reviews": { "requests": [ { "request": { "body": { - "query":"query($representations:[_Any!]!){_entities(representations:$representations){...on Product{reviews{body}}}}", + "query":"query InvalidationEntityKey__invalidation_entity_key_reviews__1($representations:[_Any!]!){_entities(representations:$representations){...on Product{reviews{body}}}}", "variables":{"representations":[{"upc":"1","__typename":"Product"}]} } }, @@ -213,7 +219,7 @@ { "type": "Request", "request": { - "query": "{ topProducts { reviews { body } } }" + "query": "query InvalidationEntityKey { topProducts { reviews { body } } }" }, "expected_response": { "data":{ diff --git a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/supergraph.graphql b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/supergraph.graphql index 8f4b1aa05b..630e59c38b 100644 --- a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/supergraph.graphql +++ b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-entity-key/supergraph.graphql @@ -37,10 +37,10 @@ enum core__Purpose { scalar join__FieldSet enum join__Graph { - ACCOUNTS @join__graph(name: "accounts", url: "https://accounts.demo.starstuff.dev") - INVENTORY @join__graph(name: "inventory", url: "https://inventory.demo.starstuff.dev") - PRODUCTS @join__graph(name: "products", url: "https://products.demo.starstuff.dev") - REVIEWS @join__graph(name: "reviews", url: "https://reviews.demo.starstuff.dev") + ACCOUNTS @join__graph(name: "invalidation-entity-key-accounts", url: "https://accounts.demo.starstuff.dev") + INVENTORY @join__graph(name: "invalidation-entity-key-inventory", url: "https://inventory.demo.starstuff.dev") + PRODUCTS @join__graph(name: "invalidation-entity-key-products", url: "https://products.demo.starstuff.dev") + REVIEWS @join__graph(name: "invalidation-entity-key-reviews", url: "https://reviews.demo.starstuff.dev") } type Mutation { updateMyAccount: User @join__field(graph: ACCOUNTS) diff --git a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph/README.md b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-name/README.md similarity index 100% rename from apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph/README.md rename to apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-name/README.md diff --git a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph/configuration.yaml b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-name/configuration.yaml similarity index 78% rename from apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph/configuration.yaml rename to apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-name/configuration.yaml index a54c33f25d..85e106df9f 100644 --- a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph/configuration.yaml +++ b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-name/configuration.yaml @@ -17,4 +17,10 @@ preview_entity_cache: subgraphs: reviews: ttl: 120s - enabled: true \ No newline at end of file + enabled: true + +telemetry: + exporters: + logging: + stdout: + format: text \ No newline at end of file diff --git a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph/skipped.json b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-name/plan.json similarity index 77% rename from apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph/skipped.json rename to apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-name/plan.json index cadc7ac809..9bbbd1d90c 100644 --- a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph/skipped.json +++ b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-name/plan.json @@ -7,11 +7,11 @@ "schema_path": "./supergraph.graphql", "configuration_path": "./configuration.yaml", "subgraphs": { - "accounts": { + "invalidation-subgraph-name-accounts": { "requests": [ { "request": { - "body": {"query":"{me{name}}"} + "body": {"query":"query InvalidationSubgraphName__invalidation_subgraph_name_accounts__0{me{name}}"} }, "response": { "headers": { @@ -28,7 +28,7 @@ { "type": "Request", "request": { - "query": "{ me { name } }" + "query": "query InvalidationSubgraphName { me { name } }" }, "expected_response": { "data":{ @@ -41,11 +41,11 @@ { "type": "ReloadSubgraphs", "subgraphs": { - "accounts": { + "invalidation-subgraph-name-accounts": { "requests": [ { "request": { - "body": {"query":"mutation{updateMyAccount{name}}"} + "body": {"query":"mutation InvalidationSubgraphName__invalidation_subgraph_name_accounts__0{updateMyAccount{name}}"} }, "response": { "headers": { @@ -56,7 +56,7 @@ "extensions": { "invalidation": [{ "kind": "subgraph", - "subgraph": "accounts" + "subgraph": "invalidation-subgraph-name-accounts" }] } } @@ -69,7 +69,7 @@ { "type": "Request", "request": { - "query": "{ me { name } }" + "query": "query InvalidationSubgraphName { me { name } }" }, "expected_response": { "data":{ @@ -82,7 +82,7 @@ { "type": "Request", "request": { - "query": "mutation { updateMyAccount { name } }" + "query": "mutation InvalidationSubgraphName { updateMyAccount { name } }" }, "expected_response": { "data":{ @@ -95,15 +95,15 @@ { "type": "ReloadSubgraphs", "subgraphs": { - "accounts": { + "invalidation-subgraph-name-accounts": { "requests": [ { "request": { - "body": {"query":"{me{name}}"} + "body": {"query":"query InvalidationSubgraphName__invalidation_subgraph_name_accounts__0{me{name}}"} }, "response": { "headers": { - "Cache-Control": "public, max-age=10", + "Cache-Control": "no-store, max-age=0", "Content-Type": "application/json" }, "body": {"data": { "me": { "name": "invalidation-subgraph2" } } } @@ -116,7 +116,7 @@ { "type": "Request", "request": { - "query": "{ me { name } }" + "query": "query InvalidationSubgraphName{ me { name } }" }, "expected_response": { "data":{ diff --git a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph/supergraph.graphql b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-name/supergraph.graphql similarity index 96% rename from apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph/supergraph.graphql rename to apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-name/supergraph.graphql index 1196414b6f..c8184433b1 100644 --- a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph/supergraph.graphql +++ b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-name/supergraph.graphql @@ -37,7 +37,7 @@ enum core__Purpose { scalar join__FieldSet enum join__Graph { - ACCOUNTS @join__graph(name: "accounts", url: "https://accounts.demo.starstuff.dev") + ACCOUNTS @join__graph(name: "invalidation-subgraph-name-accounts", url: "https://accounts.demo.starstuff.dev") INVENTORY @join__graph(name: "inventory", url: "https://inventory.demo.starstuff.dev") PRODUCTS @join__graph(name: "products", url: "https://products.demo.starstuff.dev") REVIEWS @join__graph(name: "reviews", url: "https://reviews.demo.starstuff.dev") diff --git a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/configuration.yaml b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/configuration.yaml index 55728b841b..96577bbb28 100644 --- a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/configuration.yaml +++ b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/configuration.yaml @@ -21,4 +21,10 @@ preview_entity_cache: subgraphs: reviews: ttl: 120s - enabled: true \ No newline at end of file + enabled: true + +telemetry: + exporters: + logging: + stdout: + format: text \ No newline at end of file diff --git a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/skipped.json b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/plan.json similarity index 74% rename from apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/skipped.json rename to apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/plan.json index 89e90f1be9..72e39a7b80 100644 --- a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/skipped.json +++ b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/plan.json @@ -7,11 +7,11 @@ "schema_path": "./supergraph.graphql", "configuration_path": "./configuration.yaml", "subgraphs": { - "accounts": { + "invalidation-subgraph-type-accounts": { "requests": [ { "request": { - "body": {"query":"query InvalidationSubgraphType__accounts__0{me{name id}}","operationName":"InvalidationSubgraphType__accounts__0"} + "body": {"query":"query InvalidationSubgraphType__invalidation_subgraph_type_accounts__0{me{name id}}","operationName":"InvalidationSubgraphType__invalidation_subgraph_type_accounts__0"} }, "response": { "headers": { @@ -42,7 +42,7 @@ { "type": "ReloadSubgraphs", "subgraphs": { - "accounts": { + "invalidation-subgraph-type-accounts": { "requests": [] } } @@ -66,21 +66,24 @@ "url": "http://127.0.0.1:12345/invalidation-sample-subgraph-type", "request": { "method": "POST", - "body": { + "headers": { + "Authorization": "1234" + }, + "body": [{ "kind": "type", - "subgraph": "accounts", + "subgraph": "invalidation-subgraph-type-accounts", "type": "Query" - } + }] } }, { "type": "ReloadSubgraphs", "subgraphs": { - "accounts": { + "invalidation-subgraph-type-accounts": { "requests": [ { "request": { - "body": {"query":"query InvalidationSubgraphType__accounts__0{me{name id}}", "operationName":"InvalidationSubgraphType__accounts__0"} + "body": {"query":"query InvalidationSubgraphType__invalidation_subgraph_type_accounts__0{me{name id}}", "operationName":"InvalidationSubgraphType__invalidation_subgraph_type_accounts__0"} }, "response": { "headers": { @@ -108,6 +111,21 @@ } } }, + { + "type": "EndpointRequest", + "url": "http://127.0.0.1:12345/invalidation-sample-subgraph-type", + "request": { + "method": "POST", + "headers": { + "Authorization": "1234" + }, + "body": [{ + "kind": "type", + "subgraph": "invalidation-subgraph-type-accounts", + "type": "Query" + }] + } + }, { "type": "Stop" } diff --git a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/supergraph.graphql b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/supergraph.graphql index 1196414b6f..a9554a070d 100644 --- a/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/supergraph.graphql +++ b/apollo-router/tests/samples/enterprise/entity-cache/invalidation-subgraph-type/supergraph.graphql @@ -37,7 +37,7 @@ enum core__Purpose { scalar join__FieldSet enum join__Graph { - ACCOUNTS @join__graph(name: "accounts", url: "https://accounts.demo.starstuff.dev") + ACCOUNTS @join__graph(name: "invalidation-subgraph-type-accounts", url: "https://accounts.demo.starstuff.dev") INVENTORY @join__graph(name: "inventory", url: "https://inventory.demo.starstuff.dev") PRODUCTS @join__graph(name: "products", url: "https://products.demo.starstuff.dev") REVIEWS @join__graph(name: "reviews", url: "https://reviews.demo.starstuff.dev") diff --git a/apollo-router/tests/samples/enterprise/query-planning-redis/configuration.yaml b/apollo-router/tests/samples/enterprise/query-planning-redis/configuration.yaml index 97518c7956..b00c6e7d58 100644 --- a/apollo-router/tests/samples/enterprise/query-planning-redis/configuration.yaml +++ b/apollo-router/tests/samples/enterprise/query-planning-redis/configuration.yaml @@ -8,3 +8,9 @@ supergraph: cache: redis: urls: ["redis://localhost:6379",] + +telemetry: + exporters: + logging: + stdout: + format: text \ No newline at end of file diff --git a/apollo-router/tests/samples_tests.rs b/apollo-router/tests/samples_tests.rs index da324cfbd7..fe7d87ed71 100644 --- a/apollo-router/tests/samples_tests.rs +++ b/apollo-router/tests/samples_tests.rs @@ -472,13 +472,13 @@ impl TestExecution { writeln!(out, "assertion `left == right` failed").unwrap(); writeln!( out, - " left: {}", + " expected: {}", serde_json::to_string(&expected_response).unwrap() ) .unwrap(); writeln!( out, - "right: {}", + "received: {}", serde_json::to_string(&graphql_response).unwrap() ) .unwrap();