mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
refactor(KyselyLogger): use startTimer instead of observe
This commit is contained in:
parent
d580cac763
commit
ac9bdfde62
1 changed files with 4 additions and 14 deletions
|
|
@ -1,28 +1,18 @@
|
|||
import { Stickynotes } from '@soapbox/stickynotes';
|
||||
import { Logger } from 'kysely';
|
||||
import { dbQueryTime } from '@/metrics.ts';
|
||||
|
||||
export const prometheusParams = {
|
||||
threshold: 10000,
|
||||
};
|
||||
import { dbQueryTimeHistogram } from '@/metrics.ts';
|
||||
|
||||
/** Log the SQL for queries. */
|
||||
export const KyselyLogger: Logger = (event) => {
|
||||
if (event.level === 'query') {
|
||||
const console = new Stickynotes('ditto:sql');
|
||||
|
||||
const timer = dbQueryTimeHistogram.startTimer();
|
||||
|
||||
const { query, queryDurationMillis } = event;
|
||||
const { sql, parameters } = query;
|
||||
|
||||
if (queryDurationMillis > prometheusParams.threshold) {
|
||||
const labels = {
|
||||
sql,
|
||||
parameters: JSON.stringify(
|
||||
parameters.filter((param: any) => ['string', 'number'].includes(typeof param)) as (string | number)[],
|
||||
),
|
||||
};
|
||||
dbQueryTime.observe(labels, queryDurationMillis);
|
||||
}
|
||||
timer();
|
||||
|
||||
console.debug(
|
||||
sql,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue