From f8eb4fc79cb90eeb6f9e71af0b5fff59ec8b792e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 6 Mar 2025 22:55:23 -0600 Subject: [PATCH] Add a metric for active author subscriptions --- packages/ditto/storages/DittoRelayStore.ts | 3 +++ packages/metrics/metrics.ts | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/packages/ditto/storages/DittoRelayStore.ts b/packages/ditto/storages/DittoRelayStore.ts index 9fb232ac..7a0935e1 100644 --- a/packages/ditto/storages/DittoRelayStore.ts +++ b/packages/ditto/storages/DittoRelayStore.ts @@ -1,6 +1,7 @@ import { DittoConf } from '@ditto/conf'; import { DittoDB, DittoTables } from '@ditto/db'; import { + activeAuthorSubscriptionsGauge, cachedFaviconsSizeGauge, cachedNip05sSizeGauge, pipelineEventsCounter, @@ -185,6 +186,7 @@ export class DittoRelayStore implements NRelay { // Try to fetch a kind 0 for the user if we don't have one yet. // TODO: Create a more elaborate system to refresh all replaceable events by addr. if (event.kind !== 0 && !event.author?.sig && !this.authorEncounters.get(event.pubkey)) { + activeAuthorSubscriptionsGauge.inc(); this.authorEncounters.set(event.pubkey, true); const [author] = await pool.query( @@ -196,6 +198,7 @@ export class DittoRelayStore implements NRelay { // await because it's important to have the kind 0 before the policy filter. await this.event(author, { signal }); } + activeAuthorSubscriptionsGauge.dec(); } // Ensure the event doesn't violate the policy. diff --git a/packages/metrics/metrics.ts b/packages/metrics/metrics.ts index 716582d4..9e131951 100644 --- a/packages/metrics/metrics.ts +++ b/packages/metrics/metrics.ts @@ -149,3 +149,8 @@ export const webPushNotificationsCounter: Counter<'type'> = new Counter({ help: 'Total number of Web Push notifications sent', labelNames: ['type'], }); + +export const activeAuthorSubscriptionsGauge: Gauge = new Gauge({ + name: `${prefix}_active_author_subscriptions`, + help: "Number of active REQ's to find kind 0 events from the pool", +});