Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"test": "jest src",
"start": "node sample/publisher/index.js && node sample/subscriber/index.js && npx nuc-node-event-test/server",
"build": "npx tsc client/Event.ts --outDir client --declaration"
"build": "npx tsc client/Event.ts --outDir client --declaration && npx tsc src/Event.ts --outDir src --declaration"
Comment thread
c3c43083 marked this conversation as resolved.
},
"dependencies": {
"chalk": "^4.1.2",
Expand Down Expand Up @@ -44,9 +44,9 @@
},
"exports": {
".": {
"import": "./src/Event.ts",
"require": "./src/Event.ts",
"types": "./src/Event.ts"
"import": "./src/Event.js",
"require": "./src/Event.js",
"types": "./src/Event.d.ts"
Comment thread
c3c43083 marked this conversation as resolved.
},
"./client": {
"import": "./client/Event.js",
Expand Down
Empty file modified server/server.js
100644 → 100755
Empty file.
13 changes: 2 additions & 11 deletions src/Event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import client from "prom-client";
import * as client from "prom-client";

import { v4 as uuid } from "uuid";

const subscriptions = {};
Expand All @@ -23,44 +24,38 @@ const eventPublishDuration = new client.Histogram({
buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5],
});

// Track payload size for analysis
const eventPayloadSize = new client.Histogram({
name: "event_payload_size_bytes",
help: "Size of event payloads in bytes",
labelNames: ["event_type"],
buckets: [10, 100, 1000, 10000, 100000, 1000000],
});

// Track error rates
const eventPublishErrors = new client.Counter({
name: "event_publish_errors_total",
help: "Total number of event publish errors",
labelNames: ["event_type", "error_type"],
});

// Track callback processing duration
const callbackProcessingDuration = new client.Histogram({
name: "event_callback_duration_seconds",
help: "Time taken to process event callbacks",
labelNames: ["event_type"],
buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5],
});

// Track subscription rates
const subscriptionRate = new client.Counter({
name: "event_subscriptions_total",
help: "Total number of event subscriptions created",
labelNames: ["event_type"],
});

// Track unsubscription rates
const unsubscriptionRate = new client.Counter({
name: "event_unsubscriptions_total",
help: "Total number of event unsubscriptions",
labelNames: ["event_type"],
});

// Track throughput (events processed per second)
const eventThroughput = new client.Counter({
name: "event_callbacks_processed_total",
help: "Total number of event callbacks processed successfully",
Expand Down Expand Up @@ -119,7 +114,6 @@ const subscribe = (...args) => {
console.debug("node-event", "unsubscribe", type, id);
delete subscriptions[type][id];

// Track unsubscription
unsubscriptionRate.labels(type).inc();

if (Object.keys(subscriptions[type]).length === 0) {
Expand All @@ -135,7 +129,6 @@ const subscribe = (...args) => {

subscriptions[type][id] = registry;

// Update subscription metrics
subscriptionRate.labels(type).inc();
eventSubscriptionGauge
.labels(type)
Expand All @@ -159,11 +152,9 @@ const publish = (...args) => {
throw new Error("Invalid publish type");
}

// Track metrics for event publishing
const endTimer = eventPublishDuration.labels(type).startTimer();
eventPublishCounter.labels(type).inc();

// Track payload size
const payloadSize = JSON.stringify(payload).length;
eventPayloadSize.labels(type).observe(payloadSize);

Expand Down