Skip to content

Commit ec5d022

Browse files
authored
chore: add query metadata in event emit (#41)
* add: query metadata * bump: version
1 parent 98eaa71 commit ec5d022

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

meerkat-dbm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devrev/meerkat-dbm",
3-
"version": "0.0.133",
3+
"version": "0.0.134",
44
"dependencies": {
55
"tslib": "^2.3.0",
66
"@duckdb/duckdb-wasm": "^1.28.0",

meerkat-dbm/src/dbm/dbm.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ type BeforeQueryHook = (
2626
) => Promise<void>;
2727

2828
type QueryOptions = {
29-
beforeQuery: BeforeQueryHook;
29+
beforeQuery?: BeforeQueryHook;
30+
metadata?: object;
3031
};
3132

3233
export class DBM {
@@ -44,7 +45,7 @@ export class DBM {
4445
* Timestamp when the query was added to the queue
4546
*/
4647
timestamp: number;
47-
options?: { beforeQuery: BeforeQueryHook };
48+
options?: QueryOptions;
4849
}[] = [];
4950
private beforeQuery?: ({
5051
query,
@@ -149,6 +150,7 @@ export class DBM {
149150
this._emitEvent({
150151
event_name: 'mount_file_buffer_duration',
151152
duration: endMountTime - startMountTime,
153+
metadata: options?.metadata,
152154
});
153155

154156
const tablesFileData = await this.fileManager.getFilesNameForTables(
@@ -181,6 +183,7 @@ export class DBM {
181183
this._emitEvent({
182184
event_name: 'query_execution_duration',
183185
duration: queryQueueDuration,
186+
metadata: options?.metadata,
184187
});
185188

186189
/**
@@ -200,6 +203,7 @@ export class DBM {
200203
this._emitEvent({
201204
event_name: 'unmount_file_buffer_duration',
202205
duration: endUnmountTime - startUnmountTime,
206+
metadata: options?.metadata,
203207
});
204208

205209
return result;
@@ -223,12 +227,13 @@ export class DBM {
223227
* If there is no query in the queue, stop the queue
224228
* Recursively call itself to execute the next query
225229
*/
226-
private async _startQueryExecution() {
230+
private async _startQueryExecution(metadata?: object) {
227231
this.logger.debug('Query queue length:', this.queriesQueue.length);
228232

229233
this._emitEvent({
230234
event_name: 'query_queue_length',
231235
value: this.queriesQueue.length,
236+
metadata,
232237
});
233238

234239
/**
@@ -255,6 +260,7 @@ export class DBM {
255260
this._emitEvent({
256261
event_name: 'query_queue_duration',
257262
duration: startTime - queueElement.timestamp,
263+
metadata,
258264
});
259265

260266
/**
@@ -288,7 +294,7 @@ export class DBM {
288294
/**
289295
* Start the next query
290296
*/
291-
this._startQueryExecution();
297+
this._startQueryExecution(queueElement.options?.metadata);
292298
}
293299

294300
/**
@@ -315,7 +321,7 @@ export class DBM {
315321
public async queryWithTableNames(
316322
query: string,
317323
tableNames: string[],
318-
options?: { beforeQuery: BeforeQueryHook }
324+
options?: QueryOptions
319325
) {
320326
const promise = new Promise((resolve, reject) => {
321327
this.queriesQueue.push({

meerkat-dbm/src/logger/event-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ export interface QueueEvents {
1212
value: number;
1313
}
1414

15-
export type DBMEvent = DurationEvents | QueueEvents;
15+
export type DBMEvent = (DurationEvents | QueueEvents) & { metadata?: object };

0 commit comments

Comments
 (0)