Skip to content

Commit 911ace9

Browse files
authored
Add network-wide grafana error links for Kubernetes CI (#2117)
* Add network-wide grafana error links for Kubernetes CI * Prettier fix
1 parent 737083d commit 911ace9

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

javascript/packages/orchestrator/src/network.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
CreateLogTable,
33
TimeoutAbortController,
44
decorators,
5+
getLokiUrlForNetworkErrors,
56
} from "@zombienet/utils";
67
import fs from "fs";
78
import {
@@ -340,6 +341,33 @@ export class Network {
340341
this.showNodeInfo(node, provider, logTable);
341342
}
342343
}
344+
345+
// Add network-wide error logs link for kubernetes provider
346+
if (this.client.providerName === "kubernetes" && this.networkStartTime) {
347+
const inCI = process.env.RUN_IN_CONTAINER === "1";
348+
if (inCI) {
349+
const networkLokiUrl = getLokiUrlForNetworkErrors(
350+
this.namespace,
351+
this.networkStartTime,
352+
);
353+
logTable.pushTo([
354+
[
355+
{
356+
colSpan: 2,
357+
hAlign: "center",
358+
content: decorators.cyan("🌐 All nodes logs (Grafana)"),
359+
},
360+
],
361+
[
362+
{
363+
colSpan: 2,
364+
content: decorators.bright(networkLokiUrl),
365+
},
366+
],
367+
]);
368+
}
369+
}
370+
343371
logTable.print();
344372
}
345373

javascript/packages/orchestrator/src/test-runner/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
decorators,
33
getLokiUrl,
4+
getLokiUrlForNetworkErrors,
45
readNetworkConfig,
56
setLogType,
67
sleep,
@@ -159,6 +160,22 @@ export async function run(
159160
console.log(
160161
`\n\n\t${decorators.red("❌ One or more of your test failed...")}`,
161162
);
163+
164+
// Show network-wide error logs link for kubernetes in CI when tests fail
165+
if (network.client.providerName === "kubernetes" && inCI) {
166+
const networkEndtime = new Date().getTime();
167+
const networkLokiUrl = getLokiUrlForNetworkErrors(
168+
network.namespace,
169+
network.networkStartTime!,
170+
networkEndtime,
171+
);
172+
console.log(
173+
`\n\t${decorators.red("🔍 View error logs for all nodes in the network:")}`,
174+
);
175+
console.log(
176+
`\t${decorators.bright(decorators.red(networkLokiUrl))}`,
177+
);
178+
}
162179
} else {
163180
success = true;
164181
}
@@ -220,6 +237,18 @@ export async function run(
220237
}
221238
}
222239

240+
// Add network-wide errors logs link
241+
const networkLokiUrl = getLokiUrlForNetworkErrors(
242+
network.namespace,
243+
network.networkStartTime!,
244+
networkEndtime,
245+
);
246+
console.log(
247+
`\n\t${decorators.cyan("🌐 All nodes (relaychain + parachains) error logs:")} ${decorators.bright(
248+
networkLokiUrl,
249+
)}`,
250+
);
251+
223252
// logs are also collected as artifacts
224253
console.log(
225254
`\n\n\t ${decorators.yellow(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
export const LOKI_URL_FOR_NODE =
22
"https://grafana.teleport.parity.io/explore?orgId=1&left=%7B%22datasource%22:%22PCF9DACBDF30E12B3%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22datasource%22:%7B%22type%22:%22loki%22,%22uid%22:%22PCF9DACBDF30E12B3%22%7D,%22editorMode%22:%22code%22,%22expr%22:%22%7Bnamespace%3D%5C%22{{namespace}}%5C%22,pod%3D%5C%22{{podName}}%5C%22%7D%22,%22queryType%22:%22range%22%7D%5D,%22range%22:%7B%22from%22:%22{{from}}%22,%22to%22:%22{{to}}%22%7D%7D";
3+
4+
export const LOKI_URL_FOR_NETWORK_ERRORS =
5+
"https://grafana.teleport.parity.io/explore?orgId=1&left=%7B%22datasource%22:%22PCF9DACBDF30E12B3%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22datasource%22:%7B%22type%22:%22loki%22,%22uid%22:%22PCF9DACBDF30E12B3%22%7D,%22editorMode%22:%22code%22,%22expr%22:%22%7Bnamespace%3D%5C%22{{namespace}}%5C%22%7D%20%7C~%20%5C%22(%3F%3Ai)error%7Cfail%7Cpanic%7Cfatal%5C%22%22,%22queryType%22:%22range%22%7D%5D,%22range%22:%7B%22from%22:%22{{from}}%22,%22to%22:%22{{to}}%22%7D%7D";

javascript/packages/utils/src/misc.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createHash, randomBytes } from "crypto";
22
import { format } from "util";
3-
import { LOKI_URL_FOR_NODE } from "./constants";
3+
import { LOKI_URL_FOR_NODE, LOKI_URL_FOR_NETWORK_ERRORS } from "./constants";
44

55
export async function sleep(ms: number) {
66
return new Promise((resolve) => setTimeout(resolve, ms));
@@ -120,6 +120,21 @@ export function getLokiUrl(
120120
return loki_url;
121121
}
122122

123+
export function getLokiUrlForNetworkErrors(
124+
namespace: string,
125+
from: number | string,
126+
to?: number | string,
127+
): string {
128+
const loki_url = LOKI_URL_FOR_NETWORK_ERRORS.replace(
129+
/{{namespace}}/,
130+
namespace,
131+
)
132+
.replace(/{{from}}/, from.toString())
133+
.replace(/{{to}}/, to?.toString() || "now");
134+
135+
return loki_url;
136+
}
137+
123138
export const TimeoutAbortController = (time: number) => {
124139
const controller = new AbortController();
125140
setTimeout(() => controller.abort(), time * 1000);

0 commit comments

Comments
 (0)