Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 4 additions & 5 deletions apollo-router/src/plugins/cache/invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -184,7 +184,6 @@ async fn handle_request(
.map(|k| RedisKey(k.to_string()))
.collect::<Vec<_>>();
if !keys.is_empty() {
tracing::debug!("deleting keys: {keys:?}");
count += keys.len() as u64;
storage.delete(keys).await;

Expand Down Expand Up @@ -270,18 +269,18 @@ 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,
r#type,
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}:*")
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions apollo-router/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ preview_entity_cache:
all:
enabled: true
subgraphs:
reviews:
invalidation-entity-key-reviews:
ttl: 120s
enabled: true
enabled: true

telemetry:
exporters:
logging:
stdout:
format: text
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"}]}
}
},
Expand Down Expand Up @@ -59,7 +63,7 @@
{
"type": "Request",
"request": {
"query": "{ topProducts { reviews { body } } }"
"query": "query InvalidationEntityKey { topProducts { reviews { body } } }"
},
"expected_response": {
"data":{
Expand All @@ -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": {
Expand All @@ -96,7 +102,7 @@
"extensions": {
"invalidation": [{
"kind": "entity",
"subgraph": "reviews",
"subgraph": "invalidation-entity-key-reviews",
"type": "Product",
"key": {
"upc": "1"
Expand All @@ -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"}]}
}
},
Expand All @@ -129,7 +135,7 @@
{
"type": "Request",
"request": {
"query": "{ topProducts { reviews { body } } }"
"query": "query InvalidationEntityKey { topProducts { reviews { body } } }"
},
"expected_response": {
"data":{
Expand All @@ -151,7 +157,7 @@
{
"type": "Request",
"request": {
"query": "mutation { invalidateProductReview }"
"query": "mutation InvalidationEntityKey { invalidateProductReview }"
},
"expected_response": {
"data":{
Expand All @@ -162,33 +168,33 @@
{
"type": "Request",
"request": {
"query": "{ topProducts { reviews { body } } }"
"query": "query InvalidationEntityKey { topProducts { reviews { body } } }"
},
"expected_response":{
"data":{
"topProducts":[{"reviews":null},{"reviews":null}]
},
"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"}
}
]
}
},
{
"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"}]}
}
},
Expand All @@ -213,7 +219,7 @@
{
"type": "Request",
"request": {
"query": "{ topProducts { reviews { body } } }"
"query": "query InvalidationEntityKey { topProducts { reviews { body } } }"
},
"expected_response": {
"data":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ preview_entity_cache:
subgraphs:
reviews:
ttl: 120s
enabled: true
enabled: true

telemetry:
exporters:
logging:
stdout:
format: text
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -28,7 +28,7 @@
{
"type": "Request",
"request": {
"query": "{ me { name } }"
"query": "query InvalidationSubgraphName { me { name } }"
},
"expected_response": {
"data":{
Expand All @@ -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": {
Expand All @@ -56,7 +56,7 @@
"extensions": {
"invalidation": [{
"kind": "subgraph",
"subgraph": "accounts"
"subgraph": "invalidation-subgraph-name-accounts"
}]
}
}
Expand All @@ -69,7 +69,7 @@
{
"type": "Request",
"request": {
"query": "{ me { name } }"
"query": "query InvalidationSubgraphName { me { name } }"
},
"expected_response": {
"data":{
Expand All @@ -82,7 +82,7 @@
{
"type": "Request",
"request": {
"query": "mutation { updateMyAccount { name } }"
"query": "mutation InvalidationSubgraphName { updateMyAccount { name } }"
},
"expected_response": {
"data":{
Expand All @@ -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" } } }
Expand All @@ -116,7 +116,7 @@
{
"type": "Request",
"request": {
"query": "{ me { name } }"
"query": "query InvalidationSubgraphName{ me { name } }"
},
"expected_response": {
"data":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ preview_entity_cache:
subgraphs:
reviews:
ttl: 120s
enabled: true
enabled: true

telemetry:
exporters:
logging:
stdout:
format: text
Loading