Skip to content

Commit 4292bc2

Browse files
committed
Log subscriptions
1 parent 773407f commit 4292bc2

File tree

6 files changed

+40
-12
lines changed

6 files changed

+40
-12
lines changed

router/router.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ subscription:
2525
reviews:
2626
protocol: graphql_ws
2727

28-
telemetry:
29-
instrumentation:
30-
spans:
31-
mode: spec_compliant
3228

3329
# Enable health check endpoint on all interfaces
3430
health_check:

scripts/port-forward-utils.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
# =============================================================================
1111

1212
# Source shared utilities
13-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
14-
source "$SCRIPT_DIR/utils.sh"
15-
source "$SCRIPT_DIR/config.sh"
13+
if [ -z "$SCRIPT_DIR" ]; then
14+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15+
fi
16+
source "$SCRIPT_DIR/scripts/utils.sh"
17+
source "$SCRIPT_DIR/scripts/config.sh"
1618

1719
# Configuration (now from config)
1820
NAMESPACE=$(get_k8s_namespace)

scripts/test-utils.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
# =============================================================================
1111

1212
# Source shared utilities
13-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
14-
source "$SCRIPT_DIR/utils.sh"
15-
source "$SCRIPT_DIR/config.sh"
13+
if [ -z "$SCRIPT_DIR" ]; then
14+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15+
fi
16+
source "$SCRIPT_DIR/scripts/utils.sh"
17+
source "$SCRIPT_DIR/scripts/config.sh"
1618

1719
# Default values (now from config)
1820
ROUTER_URL=$(get_router_graphql_url | sed 's|/graphql$||')

subgraphs/reviews/resolvers.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ export const resolvers = {
1515
Subscription: {
1616
reviewAdded: {
1717
subscribe: async function* () {
18+
// Log the pod ID when subscription starts
19+
const podId = process.env.HOSTNAME || 'unknown';
20+
console.log(`🚀 [${podId}] Reviews subscription connection established`);
21+
1822
let count = 0;
1923
while (true) {
2024
const review = REVIEWS[count++];
25+
console.log(`📤 [${podId}] Sending review: ${review.id} - ${review.title}`);
2126
yield { reviewAdded: review };
2227
await new Promise((resolve) => setTimeout(resolve, 3000));
2328
if (count === REVIEWS.length) count = 0;

subgraphs/subgraphs.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ const getLocalSubgraphConfig = (subgraphName) =>
3434
LOCAL_SUBGRAPH_CONFIG.find(it => it.name === subgraphName);
3535

3636
export const startSubgraphs = async (httpPort) => {
37+
// Log pod ID for Kubernetes identification
38+
const podId = process.env.HOSTNAME || 'unknown';
39+
console.log(`🚀 [${podId}] Starting subgraphs server...`);
40+
3741
// Create a monolith express app for all subgraphs
3842
const app = express();
3943
const httpServer = http.createServer(app);
@@ -66,6 +70,21 @@ export const startSubgraphs = async (httpPort) => {
6670
server: httpServer,
6771
path,
6872
});
73+
74+
// Add WebSocket connection logging
75+
wsServer.on('connection', (socket, request) => {
76+
console.log(`🔌 [${podId}] WebSocket connection established for [${subgraphConfig.name}] subgraph`);
77+
console.log(`🔌 [${podId}] Client IP: ${request.socket.remoteAddress}`);
78+
79+
socket.on('close', () => {
80+
console.log(`🔌 [${podId}] WebSocket connection closed for [${subgraphConfig.name}] subgraph`);
81+
});
82+
83+
socket.on('error', (error) => {
84+
console.log(`❌ [${podId}] WebSocket error for [${subgraphConfig.name}] subgraph:`, error.message);
85+
});
86+
});
87+
6988
const serverCleanup = useServer({ schema }, wsServer);
7089
wsPlugin = {
7190
async serverWillStart() {
@@ -76,10 +95,10 @@ export const startSubgraphs = async (httpPort) => {
7695
};
7796
},
7897
};
79-
console.log(`Setting up WebSocket server for [${subgraphConfig.name}] subgraph at ws://localhost:${serverPort}/${path}`);
98+
console.log(`🚀 [${podId}] Setting up WebSocket server for [${subgraphConfig.name}] subgraph at ws://localhost:${serverPort}${path}`);
8099
}
81100

82-
console.log(`Setting up HTTP server for [${subgraphConfig.name}] subgraph at http://localhost:${serverPort}${path}`);
101+
console.log(`🚀 [${podId}] Setting up HTTP server for [${subgraphConfig.name}] subgraph at http://localhost:${serverPort}${path}`);
83102

84103
const server = new ApolloServer({
85104
schema,
@@ -110,4 +129,5 @@ export const startSubgraphs = async (httpPort) => {
110129

111130
// Start entire monolith at given port
112131
await new Promise((resolve) => httpServer.listen({ port: serverPort }, resolve));
132+
console.log(`🚀 [${podId}] All subgraphs started and listening on port ${serverPort}`);
113133
};

test-k8s.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ done
3636

3737
show_script_header "Apollo Supergraph Kubernetes Testing" "Testing Apollo Supergraph deployment in minikube"
3838

39+
# Get namespace
40+
NAMESPACE=$(get_k8s_namespace)
41+
3942
# Check if namespace exists
4043
if ! namespace_exists "$NAMESPACE"; then
4144
print_error "Namespace $NAMESPACE does not exist. Please deploy first:"

0 commit comments

Comments
 (0)