diff --git a/package.json b/package.json index 122d71a..fe27b38 100644 --- a/package.json +++ b/package.json @@ -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" }, "dependencies": { "chalk": "^4.1.2", @@ -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" }, "./client": { "import": "./client/Event.js", diff --git a/server/server.js b/server/server.js old mode 100644 new mode 100755 diff --git a/src/Event.ts b/src/Event.ts index f43ae26..1d8ed16 100644 --- a/src/Event.ts +++ b/src/Event.ts @@ -1,4 +1,5 @@ -import client from "prom-client"; +import * as client from "prom-client"; + import { v4 as uuid } from "uuid"; const subscriptions = {}; @@ -23,7 +24,6 @@ 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", @@ -31,14 +31,12 @@ const eventPayloadSize = new client.Histogram({ 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", @@ -46,21 +44,18 @@ const callbackProcessingDuration = new client.Histogram({ 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", @@ -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) { @@ -135,7 +129,6 @@ const subscribe = (...args) => { subscriptions[type][id] = registry; - // Update subscription metrics subscriptionRate.labels(type).inc(); eventSubscriptionGauge .labels(type) @@ -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);