Skip to content

Commit 2e322da

Browse files
committed
🚧
1 parent d6439ea commit 2e322da

File tree

4 files changed

+67
-476
lines changed

4 files changed

+67
-476
lines changed
Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
11
import { defineConfig } from '@graphql-hive/gateway';
2+
import { openTelemetrySetup } from '@graphql-hive/gateway/opentelemetry/setup';
3+
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
4+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
25

6+
const RESPONSE_CACHE_ENABLED = process.env['RESPONSE_CACHE_ENABLED'] == 'true';
7+
8+
openTelemetrySetup({
9+
contextManager: new AsyncLocalStorageContextManager(),
10+
resource: {
11+
serviceName: RESPONSE_CACHE_ENABLED ? 'with-cache' : 'without-cache',
12+
serviceVersion: '1.0.0',
13+
},
14+
traces: {
15+
exporter: new OTLPTraceExporter({ url: 'http://localhost:4318/v1/traces' }),
16+
// batching: false,
17+
},
18+
});
319
export const gatewayConfig = defineConfig({
20+
openTelemetry: {
21+
traces: true,
22+
},
423
cache: {
524
type: 'redis',
625
url: process.env['REDIS_URL'], // The URL of the Redis server
726
lazyConnect: false,
827
},
9-
responseCaching: {
10-
ttl: 0,
11-
ttlPerType: {
12-
'Query.me': 2000,
13-
},
14-
session: () => null,
15-
},
28+
responseCaching: RESPONSE_CACHE_ENABLED
29+
? {
30+
ttl: 0,
31+
ttlPerType: {
32+
'Query.me': 2000,
33+
},
34+
session: () => null,
35+
}
36+
: undefined,
1637
maskedErrors: false,
1738
});

bench/response-cache/response-cache.bench.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { setTimeout } from 'node:timers/promises';
21
import { createExampleSetup, createTenv, GatewayOptions } from '@internal/e2e';
32
import { benchConfig } from '@internal/testing';
43
import { bench, describe, expect } from 'vitest';
@@ -16,22 +15,33 @@ describe('Response Cache', async () => {
1615
containerPort: 6379,
1716
});
1817

19-
await runBench(
18+
await runBench.skip(
2019
'With in memory response cache',
2120
'gateway-with-cache.config.ts',
2221
);
23-
await runBench('Without response cache', 'gateway-without-cache.config.ts');
22+
await runBench.skip(
23+
'Without response cache',
24+
'gateway-without-cache.config.ts',
25+
);
2426

2527
await runBench.skip(
2628
'Without invalidation cache',
2729
'gateway-without-auto-invalidation.config.ts',
2830
);
2931

30-
await runBench.skip(
31-
'With redis response cache',
32+
await runBench('With redis response cache', 'gateway-with-redis.config.ts', {
33+
env: {
34+
RESPONSE_CACHE_ENABLED: 'true',
35+
REDIS_URL: `redis://localhost:${redis.port}`,
36+
},
37+
});
38+
39+
await runBench(
40+
'With redis but no response cache',
3241
'gateway-with-redis.config.ts',
3342
{
3443
env: {
44+
RESPONSE_CACHE_ENABLED: 'false',
3545
REDIS_URL: `redis://localhost:${redis.port}`,
3646
},
3747
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"tmp": "0.2.4",
8383
"tsx": "patch:tsx@npm%3A4.20.3#~/.yarn/patches/tsx-npm-4.20.3-7de67a623f.patch",
8484
"vite": "7.1.9",
85-
"@envelop/response-cache": "8.2.0-alpha-20251003143108-b56597767a1f741fbd6420f60af9abdf439fd4b8"
85+
"@envelop/response-cache": "8.2.0-alpha-20251013081815-d6f74fceb1a32fd336b2664f90f87872e1bbf2fe",
86+
"@graphql-mesh/cache-redis": "0.105.0-alpha-20251010093057-4eeae9412ec39cfbab6e001ecaf527cf94f4ea31"
8687
}
8788
}

0 commit comments

Comments
 (0)