Add Policy metrics

This commit is contained in:
Alex Gleason 2024-07-30 15:47:55 -05:00
parent 9b521e9f36
commit 8960bdcca9
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 8 additions and 1 deletions

View file

@ -35,6 +35,12 @@ export const pipelineEventCounter = new Counter({
labelNames: ['kind'],
});
export const policyEventCounter = new Counter({
name: 'policy_events_total',
help: 'Total number of policy OK responses',
labelNames: ['ok'],
});
export const relayEventCounter = new Counter({
name: 'relay_events_total',
help: 'Total number of EVENT messages processed by the relay',

View file

@ -8,7 +8,7 @@ import { Conf } from '@/config.ts';
import { DittoDB } from '@/db/DittoDB.ts';
import { deleteAttachedMedia } from '@/db/unattached-media.ts';
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
import { pipelineEventCounter } from '@/metrics.ts';
import { pipelineEventCounter, policyEventCounter } from '@/metrics.ts';
import { RelayError } from '@/RelayError.ts';
import { AdminSigner } from '@/signers/AdminSigner.ts';
import { hydrateEvents } from '@/storages/hydrate.ts';
@ -71,6 +71,7 @@ async function policyFilter(event: NostrEvent): Promise<void> {
try {
const result = await policyWorker.call(event);
policyEventCounter.inc({ ok: String(result[2]) });
debug(JSON.stringify(result));
RelayError.assert(result);
} catch (e) {