mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
metrics: improve fetch response metrics
This commit is contained in:
parent
f8fcb9ac77
commit
6a8b22d018
2 changed files with 13 additions and 6 deletions
|
|
@ -27,10 +27,10 @@ export const streamingClientMessagesCounter = new Counter({
|
|||
help: 'Total number of messages received by the streaming API',
|
||||
});
|
||||
|
||||
export const fetchCounter = new Counter({
|
||||
name: 'ditto_fetch_total',
|
||||
export const fetchResponsesCounter = new Counter({
|
||||
name: 'ditto_fetch_responses_total',
|
||||
help: 'Total number of fetch requests',
|
||||
labelNames: ['method'],
|
||||
labelNames: ['method', 'status'],
|
||||
});
|
||||
|
||||
export const firehoseEventsCounter = new Counter({
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import * as Comlink from 'comlink';
|
|||
import { FetchWorker } from './fetch.worker.ts';
|
||||
import './handlers/abortsignal.ts';
|
||||
|
||||
import { fetchCounter } from '@/metrics.ts';
|
||||
import { fetchResponsesCounter } from '@/metrics.ts';
|
||||
|
||||
const worker = new Worker(new URL('./fetch.worker.ts', import.meta.url), { type: 'module' });
|
||||
const client = Comlink.wrap<typeof FetchWorker>(worker);
|
||||
|
|
@ -23,11 +23,18 @@ const ready = new Promise<void>((resolve) => {
|
|||
*/
|
||||
const fetchWorker: typeof fetch = async (...args) => {
|
||||
await ready;
|
||||
|
||||
const [url, init] = serializeFetchArgs(args);
|
||||
const { body, signal, ...rest } = init;
|
||||
fetchCounter.inc({ method: init.method });
|
||||
|
||||
const result = await client.fetch(url, { ...rest, body: await prepareBodyForWorker(body) }, signal);
|
||||
return new Response(...result);
|
||||
const response = new Response(...result);
|
||||
|
||||
const { method } = init;
|
||||
const { status } = response;
|
||||
fetchResponsesCounter.inc({ method, status });
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
/** Take arguments to `fetch`, and turn them into something we can send over Comlink. */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue