From 444d3f2baa6c661ac64c73f54840ff3d7b6ff532 Mon Sep 17 00:00:00 2001 From: Darun Seethammagari Date: Tue, 28 Nov 2023 15:41:08 -0800 Subject: [PATCH] Update logging --- runner/src/dml-handler/dml-handler.test.ts | 24 +++++++++++----------- runner/src/dml-handler/dml-handler.ts | 8 ++++---- runner/src/indexer/indexer.ts | 4 ++-- runner/src/pg-client.ts | 8 ++++---- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/runner/src/dml-handler/dml-handler.test.ts b/runner/src/dml-handler/dml-handler.test.ts index 3ae2668de..188cb894b 100644 --- a/runner/src/dml-handler/dml-handler.test.ts +++ b/runner/src/dml-handler/dml-handler.test.ts @@ -37,9 +37,9 @@ describe('DML Handler tests', () => { }); const dmlHandler = await DmlHandler.create(ACCOUNT, hasuraClient, mockPgClient); - await dmlHandler.startConnection(); - await dmlHandler.startConnection(); - await dmlHandler.startConnection(); + await dmlHandler.startConnection('test_indexer'); + await dmlHandler.startConnection('test_indexer'); + await dmlHandler.startConnection('test_indexer'); expect(startConnection).toHaveBeenCalledTimes(1); }); @@ -57,13 +57,13 @@ describe('DML Handler tests', () => { }); const dmlHandler = await DmlHandler.create(ACCOUNT, hasuraClient, mockPgClient); - await dmlHandler.startConnection(); - await dmlHandler.endConnection(); - await dmlHandler.endConnection(); + await dmlHandler.startConnection('test_indexer'); + await dmlHandler.endConnection('test_indexer'); + await dmlHandler.endConnection('test_indexer'); expect(startConnection).toHaveBeenCalledTimes(1); expect(endConnection).toHaveBeenCalledTimes(1); - expect(endConnection).toHaveBeenCalledWith(false); + expect(endConnection).toHaveBeenCalledWith(false, 'test_indexer'); }); test('Test close connection with failed queries to database', async () => { @@ -80,15 +80,15 @@ describe('DML Handler tests', () => { }); const dmlHandler = await DmlHandler.create(ACCOUNT, hasuraClient, mockPgClient); - await dmlHandler.startConnection(); - await dmlHandler.startConnection(); + await dmlHandler.startConnection('test_indexer'); + await dmlHandler.startConnection('test_indexer'); dmlHandler.setTransactionFailed(); - await dmlHandler.endConnection(); - await dmlHandler.endConnection(); + await dmlHandler.endConnection('test_indexer'); + await dmlHandler.endConnection('test_indexer'); expect(startConnection).toHaveBeenCalledTimes(1); expect(endConnection).toHaveBeenCalledTimes(1); - expect(endConnection).toHaveBeenCalledWith(true); + expect(endConnection).toHaveBeenCalledWith(true, 'test_indexer'); }); test('Test valid insert one with array', async () => { diff --git a/runner/src/dml-handler/dml-handler.ts b/runner/src/dml-handler/dml-handler.ts index fc2cd7ab2..bd1200406 100644 --- a/runner/src/dml-handler/dml-handler.ts +++ b/runner/src/dml-handler/dml-handler.ts @@ -119,16 +119,16 @@ export default class DmlHandler { this.failedTransaction = true; } - async startConnection (): Promise { + async startConnection (functionName: string): Promise { if (!this.connected) { - await this.pgClient.startConnection(); + await this.pgClient.startConnection(functionName); this.connected = true; } } - async endConnection (): Promise { + async endConnection (functionName: string): Promise { if (this.connected) { - await this.pgClient.endConnection(this.failedTransaction); + await this.pgClient.endConnection(this.failedTransaction, functionName); } this.connected = false; this.failedTransaction = false; diff --git a/runner/src/indexer/indexer.ts b/runner/src/indexer/indexer.ts index 6195c5cd4..a207e3c61 100644 --- a/runner/src/indexer/indexer.ts +++ b/runner/src/indexer/indexer.ts @@ -101,7 +101,7 @@ export default class Indexer { const modifiedFunction = this.transformIndexerFunction(indexerFunction.code); try { if (modifiedFunction.includes('context.db')) { - await (await dmlHandlerLazyLoader).startConnection(); + await (await dmlHandlerLazyLoader).startConnection(functionName); } await vm.run(modifiedFunction); } catch (e) { @@ -114,7 +114,7 @@ export default class Indexer { await this.writeLog(functionName, blockHeight, 'Error running IndexerFunction', error.message); throw e; } finally { - await (await dmlHandlerLazyLoader).endConnection(); + await (await dmlHandlerLazyLoader).endConnection(functionName); } simultaneousPromises.push(this.writeFunctionState(functionName, blockHeight, isHistorical)); } catch (e) { diff --git a/runner/src/pg-client.ts b/runner/src/pg-client.ts index fe4774cdd..f6c6e0a30 100644 --- a/runner/src/pg-client.ts +++ b/runner/src/pg-client.ts @@ -28,7 +28,7 @@ export default class PgClient { this.format = pgFormat; } - async startConnection (): Promise { + async startConnection (functionName: string): Promise { try { await this.client.connect(); } catch (error) { @@ -36,13 +36,13 @@ export default class PgClient { throw error; } await this.client.query('BEGIN'); - console.log('Postgres client connected. Transaction started successfully.'); + console.log(`Postgres client connected. Transaction for indexer ${functionName} started successfully.`); } - async endConnection (failedQuery: boolean): Promise { + async endConnection (failedQuery: boolean, functionName: string): Promise { await this.client.query(failedQuery ? 'ROLLBACK' : 'COMMIT'); await this.client.end(); - console.log(`Transaction ${failedQuery ? 'rolled back' : 'comitted'} successfully. Postgres client disconnected.`); + console.log(`Transaction for indexer ${functionName} ${failedQuery ? 'rolled back' : 'comitted'} successfully. Postgres client disconnected.`); } async query(query: string, params: any[] = []): Promise> {