Add a metric for active author subscriptions

This commit is contained in:
Alex Gleason 2025-03-06 22:55:23 -06:00
parent 9c3307f923
commit f8eb4fc79c
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 8 additions and 0 deletions

View file

@ -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.

View file

@ -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",
});