better help strings

This commit is contained in:
Erik 2023-11-11 17:51:40 +02:00
parent 8997d5e60d
commit 8a4d8c1d1b
2 changed files with 19 additions and 19 deletions

View File

@ -96,7 +96,7 @@ class MariaDB
#pool: PoolCluster | null;
#nodes: Node[];
#canQueryDonor: boolean;
#queryHistogram?: {startTimer: (labels: object) => () => void};
static #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)
else if (this.#config.recordMetrics && Prometheus && !MariaDB.#queryHistogram)
{
this.#logger.info('Setting up metric recording');
this.#queryHistogram = new Prometheus.Histogram({
MariaDB.#queryHistogram = new Prometheus.Histogram({
name: 'sql_queries',
help: 'Tracks query duration and frequency',
help: 'Tracks query duration in seconds and frequency',
buckets: Prometheus?.exponentialBuckets(0.005, 2, 10),
labelNames: [ 'type' ] as const
});
this.#server.registerMetric(this.#queryHistogram!);
this.#server.registerMetric(MariaDB.#queryHistogram!);
}
this.#_ready = true;
@ -407,7 +407,7 @@ class MariaDB
{
const result = await new Promise<T[] | FieldInfo[] | [OkPacket]| undefined>((resolve, reject) =>
{
const endTimer = this.#queryHistogram?.startTimer({ type: [ 'SELECT', 'UPDATE', 'INSERT', 'DELETE' ].find(entry => query.toUpperCase().includes(entry)) ?? 'OTHER' });
const endTimer = MariaDB.#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;
#queryHistogram?: { startTimer: (labels: object) => () => void };
static #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)
else if (this.#config.recordMetrics && Prometheus && !MongoDB.#queryHistogram)
{
this.#logger.info('Setting up metric recording');
this.#queryHistogram = new Prometheus.Histogram({
MongoDB.#queryHistogram = new Prometheus.Histogram({
name: 'mongo_queries',
help: 'Tracks query duration and frequency',
help: 'Tracks query duration in seconds and frequency',
buckets: Prometheus?.exponentialBuckets(0.005, 2, 10),
labelNames: [ 'type' ] as const
});
this.#server.registerMetric(this.#queryHistogram!);
this.#server.registerMetric(MongoDB.#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 = this.#queryHistogram?.startTimer({ type: 'find' });
const endTimer = MongoDB.#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 = this.#queryHistogram?.startTimer({ type: 'findOne' });
const endTimer = MongoDB.#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 = this.#queryHistogram?.startTimer({ type: 'updateMany' });
const endTimer = MongoDB.#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 = this.#queryHistogram?.startTimer({ type: 'updateOne' });
const endTimer = MongoDB.#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 = this.#queryHistogram?.startTimer({ type: 'insertOne' });
const endTimer = MongoDB.#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 = this.#queryHistogram?.startTimer({ type: 'deleteOne' });
const endTimer = MongoDB.#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 = this.#queryHistogram?.startTimer({ type: 'findOneAndDelete' });
const endTimer = MongoDB.#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 = this.#queryHistogram?.startTimer({ type: 'push' });
const endTimer = MongoDB.#queryHistogram?.startTimer({ type: 'push' });
const result = await this.#db.collection(db).updateOne(filter, { $push: data }, { upsert });
if (endTimer)
endTimer();