feat: record light push errors in dogfooding (#79)

This commit is contained in:
Arseniy Klempner 2024-07-26 13:15:54 -07:00 committed by GitHub
parent 2e55c4c548
commit 67fe074471
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 10 deletions

View File

@ -11,13 +11,15 @@ import {
import { Type, Field } from "protobufjs";
import {
TelemetryClient,
TelemetryPushError,
TelemetryPushFilter,
TelemetryType,
} from "./telemetry_client";
import { generateRandomNumber, hashNumber } from "./util";
const DEFAULT_CONTENT_TOPIC = "/js-waku-examples/1/message-ratio/utf8";
const TELEMETRY_URL = process.env.TELEMETRY_URL || "http://localhost:8080/waku-metrics";
const TELEMETRY_URL =
process.env.TELEMETRY_URL || "http://localhost:8080/waku-metrics";
const ProtoSequencedMessage = new Type("SequencedMessage")
.add(new Field("hash", 1, "string"))
@ -42,9 +44,13 @@ export async function app(telemetryClient: TelemetryClient) {
// TODO: https://github.com/waku-org/js-waku/issues/2079
// Dialing bootstrap peers right on start in order to have Filter subscription initiated properly
await node.dial("/dns4/node-01.do-ams3.waku.test.status.im/tcp/8000/wss");
await node.dial("/dns4/node-01.ac-cn-hongkong-c.waku.test.status.im/tcp/8000/wss");
await node.dial("/dns4/node-01.gc-us-central1-a.waku.test.status.im/tcp/8000/wss");
await node.dial(
"/dns4/node-01.ac-cn-hongkong-c.waku.test.status.im/tcp/8000/wss"
);
await node.dial(
"/dns4/node-01.gc-us-central1-a.waku.test.status.im/tcp/8000/wss"
);
await waitForRemotePeer(node);
const peerId = node.libp2p.peerId.toString();
@ -107,7 +113,17 @@ export async function app(telemetryClient: TelemetryClient) {
sequenceIndex++;
}
if (result.failures.length > 0) {
console.error("Failed to send message", result.failures);
telemetryClient.push<TelemetryPushError>(
result.failures.map((failure) => ({
messageType: TelemetryType.LIGHT_PUSH_ERROR,
timestamp: Math.floor(new Date().getTime() / 1000),
peerId: peerId,
peerIdRemote: failure.peerId?.toString(),
errorMessage: failure.error.toString(),
contentTopic: DEFAULT_CONTENT_TOPIC,
pubsubTopic: DefaultPubsubTopic,
}))
);
}
if (sequenceIndex < sequenceTotal) {
setTimeout(sendMessage, period); // Schedule the next send
@ -166,10 +182,7 @@ export async function app(telemetryClient: TelemetryClient) {
}
(async () => {
const telemetryClient = new TelemetryClient(
TELEMETRY_URL,
5000
);
const telemetryClient = new TelemetryClient(TELEMETRY_URL, 5000);
const { node, startLightPushSequence, startFilterSubscription } = await app(
telemetryClient
);
@ -198,4 +211,4 @@ export async function app(telemetryClient: TelemetryClient) {
document.addEventListener(sequenceCompletedEvent.type, () => startSequence());
startSequence();
})();
})();

View File

@ -1,5 +1,7 @@
export enum TelemetryType {
LIGHT_PUSH_FILTER = "LightPushFilter",
LIGHT_PUSH_ERROR = "LightPushError",
GENERIC = "Generic"
}
// Top level structure of a telemetry request
@ -25,6 +27,23 @@ export interface TelemetryPushFilter extends TelemetryMessage {
pubsubTopic: string;
}
export interface TelemetryPushError extends TelemetryMessage {
peerId: string;
errorMessage: string;
peerIdRemote?: string;
contentTopic?: string;
pubsubTopic?: string;
}
export interface TelemetryGeneric extends TelemetryMessage {
peerId: string;
metricType: string;
contentTopic?: string;
pubsubTopic?: string;
genericData?: string;
errorMessage?: string;
}
export class TelemetryClient {
constructor(