Compare commits

..

No commits in common. "69a7016e97900e79caf80800f1ad5064def20b3b" and "bfbdace1541113b47ce0e21d698e0544d35d1e36" have entirely different histories.

3 changed files with 20 additions and 20 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@navy.gif/wrappers",
"version": "1.7.2",
"version": "1.7.0",
"description": "Various wrapper classes I use in my projects",
"repository": "https://git.corgi.wtf/Navy.gif/wrappers.git",
"author": "Navy.gif",

View File

@ -96,7 +96,7 @@ class MariaDB
#pool: PoolCluster | null;
#nodes: Node[];
#canQueryDonor: boolean;
static #queryHistogram?: {startTimer: (labels: object) => () => void};
#queryHistogram?: {startTimer: (labels: object) => () => void};
#server: IServer;
constructor (server: IServer, options: MariaOptions)
@ -241,16 +241,16 @@ class MariaDB
{
this.#logger.warn('Metrics recording was enabled but missing prom-client dependency');
}
else if (this.#config.recordMetrics && Prometheus && !MariaDB.#queryHistogram)
else if (this.#config.recordMetrics && Prometheus)
{
this.#logger.info('Setting up metric recording');
MariaDB.#queryHistogram = new Prometheus.Histogram({
this.#queryHistogram = new Prometheus.Histogram({
name: 'sql_queries',
help: 'Tracks query duration in seconds and frequency',
help: 'Tracks query duration and frequency',
buckets: Prometheus?.exponentialBuckets(0.005, 2, 10),
labelNames: [ 'type' ] as const
});
this.#server.registerMetric(MariaDB.#queryHistogram!);
this.#server.registerMetric(this.#queryHistogram!);
}
this.#_ready = true;
@ -407,7 +407,7 @@ class MariaDB
{
const result = await new Promise<T[] | FieldInfo[] | [OkPacket]| undefined>((resolve, reject) =>
{
const endTimer = MariaDB.#queryHistogram?.startTimer({ type: [ 'SELECT', 'UPDATE', 'INSERT', 'DELETE' ].find(entry => query.toUpperCase().includes(entry)) ?? 'OTHER' });
const endTimer = this.#queryHistogram?.startTimer({ type: [ 'SELECT', 'UPDATE', 'INSERT', 'DELETE' ].find(entry => query.toUpperCase().includes(entry)) ?? 'OTHER' });
const q = connection.query({ timeout, sql: query }, values, (err, results, fields) =>
{
if (err)

View File

@ -55,7 +55,7 @@ class MongoDB
#db: Db | null;
#_client: MongoClient;
static #queryHistogram?: { startTimer: (labels: object) => () => void };
#queryHistogram?: { startTimer: (labels: object) => () => void };
#server: IServer;
constructor (server: IServer, config: MongoOptions)
@ -145,16 +145,16 @@ class MongoDB
{
this.#logger.warn('Metrics recording was enabled but missing prom-client dependency');
}
else if (this.#config.recordMetrics && Prometheus && !MongoDB.#queryHistogram)
else if (this.#config.recordMetrics && Prometheus)
{
this.#logger.info('Setting up metric recording');
MongoDB.#queryHistogram = new Prometheus.Histogram({
this.#queryHistogram = new Prometheus.Histogram({
name: 'mongo_queries',
help: 'Tracks query duration in seconds and frequency',
help: 'Tracks query duration and frequency',
buckets: Prometheus?.exponentialBuckets(0.005, 2, 10),
labelNames: [ 'type' ] as const
});
this.#server.registerMetric(MongoDB.#queryHistogram!);
this.#server.registerMetric(this.#queryHistogram!);
}
this.#logger.status('MongoDB ready');
@ -198,7 +198,7 @@ class MongoDB
this.#logger.debug(`Incoming find query for ${db} with parameters ${inspect(query)}`);
const endTimer = MongoDB.#queryHistogram?.startTimer({ type: 'find' });
const endTimer = this.#queryHistogram?.startTimer({ type: 'find' });
const cursor = this.#db.collection<T>(db).find(query as Filter<T>, options);
const data = await cursor.toArray();
if (endTimer)
@ -225,7 +225,7 @@ class MongoDB
query._id = new ObjectId(query._id);
this.#logger.debug(`Incoming findOne query for ${db} with parameters ${inspect(query)}`);
const endTimer = MongoDB.#queryHistogram?.startTimer({ type: 'findOne' });
const endTimer = this.#queryHistogram?.startTimer({ type: 'findOne' });
const result = await this.#db.collection<T>(db).findOne(query as Filter<T>, options);
if (endTimer)
endTimer();
@ -253,7 +253,7 @@ class MongoDB
filter._id = new ObjectId(filter._id);
this.#logger.debug(`Incoming update query for '${db}' with parameters\n${inspect(filter)}\nand data\n${inspect(data)}`);
const endTimer = MongoDB.#queryHistogram?.startTimer({ type: 'updateMany' });
const endTimer = this.#queryHistogram?.startTimer({ type: 'updateMany' });
const result = await this.#db.collection<T>(db).updateMany(filter as Filter<T>, { $set: data }, { upsert });
if (endTimer)
endTimer();
@ -279,7 +279,7 @@ class MongoDB
filter._id = new ObjectId(filter._id);
this.#logger.debug(`Incoming updateOne query for ${db} with parameters ${inspect(filter)}`);
const endTimer = MongoDB.#queryHistogram?.startTimer({ type: 'updateOne' });
const endTimer = this.#queryHistogram?.startTimer({ type: 'updateOne' });
const result = await this.#db.collection(db).updateOne(filter as Filter<Document>, { $set: data }, { upsert });
if (endTimer)
endTimer();
@ -305,7 +305,7 @@ class MongoDB
data._id = new ObjectId(data._id);
this.#logger.debug(`Incoming insertOne query for ${db} with parameters ${inspect(data)}`);
const endTimer = MongoDB.#queryHistogram?.startTimer({ type: 'insertOne' });
const endTimer = this.#queryHistogram?.startTimer({ type: 'insertOne' });
const result = await this.#db.collection(db).insertOne(data);
if (endTimer)
endTimer();
@ -322,7 +322,7 @@ class MongoDB
filter._id = new ObjectId(filter._id);
this.#logger.debug(`Incoming deleteOne query for ${db} with parameters ${inspect(filter)}`);
const endTimer = MongoDB.#queryHistogram?.startTimer({ type: 'deleteOne' });
const endTimer = this.#queryHistogram?.startTimer({ type: 'deleteOne' });
const result = await this.#db.collection(db).deleteOne(filter);
if (endTimer)
endTimer();
@ -340,7 +340,7 @@ class MongoDB
if (typeof filter._id === 'string')
filter._id = new ObjectId(filter._id);
const endTimer = MongoDB.#queryHistogram?.startTimer({ type: 'findOneAndDelete' });
const endTimer = this.#queryHistogram?.startTimer({ type: 'findOneAndDelete' });
const result = await this.#db.collection<T>(db).findOneAndDelete(filter as Filter<T>, { includeResultMetadata: meta });
if (endTimer)
endTimer();
@ -367,7 +367,7 @@ class MongoDB
filter._id = new ObjectId(filter._id);
this.#logger.debug(`Incoming push query for ${db}, with upsert ${upsert} and with parameters ${inspect(filter)} and data ${inspect(data)}`);
const endTimer = MongoDB.#queryHistogram?.startTimer({ type: 'push' });
const endTimer = this.#queryHistogram?.startTimer({ type: 'push' });
const result = await this.#db.collection(db).updateOne(filter, { $push: data }, { upsert });
if (endTimer)
endTimer();