Skip to content

Commit

Permalink
feat: record light push errors in dogfooding (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
adklempner authored Jul 26, 2024
1 parent 2e55c4c commit 67fe074
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
33 changes: 23 additions & 10 deletions examples/dogfooding/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -198,4 +211,4 @@ export async function app(telemetryClient: TelemetryClient) {

document.addEventListener(sequenceCompletedEvent.type, () => startSequence());
startSequence();
})();
})();
19 changes: 19 additions & 0 deletions examples/dogfooding/src/telemetry_client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export enum TelemetryType {
LIGHT_PUSH_FILTER = "LightPushFilter",
LIGHT_PUSH_ERROR = "LightPushError",
GENERIC = "Generic"
}

// Top level structure of a telemetry request
Expand All @@ -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(
Expand Down

0 comments on commit 67fe074

Please sign in to comment.