From 542745da8a4c3a808ad8e692e335de4e5d9e9aba Mon Sep 17 00:00:00 2001 From: Austin Schaffer Date: Tue, 17 Dec 2019 11:45:52 -0500 Subject: [PATCH] [DEV-5312] Log quote_id along with doc_id --- src/server/token/MongoTokenDao.ts | 11 +++++++---- src/system/DeltaProcessor.ts | 19 +++++++++++++++++-- src/system/DeltaPublisher.ts | 6 +++++- src/system/db/MongoDeltaDao.ts | 9 ++++++--- test/server/token/MongoTokenDaoTest.ts | 16 ++++++++++------ test/system/DeltaPublisherTest.ts | 1 + 6 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/server/token/MongoTokenDao.ts b/src/server/token/MongoTokenDao.ts index 5d3dede..a66e01b 100644 --- a/src/server/token/MongoTokenDao.ts +++ b/src/server/token/MongoTokenDao.ts @@ -272,8 +272,9 @@ export class MongoTokenDao implements TokenDao `Unknown token namespace '${ns}' for document '${doc_id}` ), { - doc_id: doc_id, - ns: ns, + doc_id: doc_id, + quote_id: doc_id, + ns: ns, } ) ); @@ -317,8 +318,9 @@ export class MongoTokenDao implements TokenDao `on document '${doc_id}'` ), { - doc_id: doc_id, - ns: ns, + doc_id: doc_id, + quote_id: doc_id, + ns: ns, }, ); } @@ -363,6 +365,7 @@ export class MongoTokenDao implements TokenDao ), { doc_id: doc_id, + quote_id: doc_id, ns: ns, token_id: token_id, }, diff --git a/src/system/DeltaProcessor.ts b/src/system/DeltaProcessor.ts index 4eba003..9553a44 100644 --- a/src/system/DeltaProcessor.ts +++ b/src/system/DeltaProcessor.ts @@ -22,6 +22,7 @@ import { DeltaDao } from '../system/db/DeltaDao'; import { DocumentMeta } from '../document/Document'; import { AmqpPublisher } from './AmqpPublisher'; +import { context } from '../error/ContextError'; import { EventEmitter } from 'events'; import { DeltaType, @@ -122,11 +123,25 @@ export class DeltaProcessor ) .then( _ => { - this._emitter.emit( 'document-processed', { doc_id: meta.id } ); + this._emitter.emit( + 'document-processed', + { + doc_id: meta.id, + quote_id: meta.id, + }, + ); } ) .catch( ( e: Error ) => { - this._emitter.emit( 'error', e ); + const context_error = context( + e, + { + doc_id: meta.id, + quote_id: meta.id, + }, + ); + + this._emitter.emit( 'error', context_error ); return this._dao.setErrorFlag( meta.id ); } ); } diff --git a/src/system/DeltaPublisher.ts b/src/system/DeltaPublisher.ts index 57a5747..ddb5877 100644 --- a/src/system/DeltaPublisher.ts +++ b/src/system/DeltaPublisher.ts @@ -84,6 +84,7 @@ export class DeltaPublisher implements AmqpPublisher new AmqpError( 'Error sending message: No channel' ), { doc_id: meta.id, + quote_id: meta.id, delta_type: delta.type, delta_ts: delta.timestamp, }, @@ -104,6 +105,7 @@ export class DeltaPublisher implements AmqpPublisher new Error ( 'Delta publish failed' ), { doc_id: meta.id, + quote_id: meta.id, delta_type: delta.type, delta_ts: delta.timestamp, } @@ -115,7 +117,9 @@ export class DeltaPublisher implements AmqpPublisher this._emitter.emit( 'delta-publish', { - delta: delta, + doc_id: meta.id, + quote_id: meta.id, + delta: delta, exchange: this._conn.getExchangeName(), } ); diff --git a/src/system/db/MongoDeltaDao.ts b/src/system/db/MongoDeltaDao.ts index e058980..f3507d8 100644 --- a/src/system/db/MongoDeltaDao.ts +++ b/src/system/db/MongoDeltaDao.ts @@ -133,8 +133,9 @@ export class MongoDeltaDao implements DeltaDao reject( context( new DaoError( 'Error advancing delta index: ' + e ), { - doc_id: doc_id, - type: type, + doc_id: doc_id, + quote_id: doc_id, + type: type, } ) ); return; @@ -177,6 +178,7 @@ export class MongoDeltaDao implements DeltaDao ), { doc_id: doc_id, + quote_id: doc_id, last_update_ts: last_update_ts, } ) ); @@ -215,7 +217,8 @@ export class MongoDeltaDao implements DeltaDao 'Failed setting error flag: ' + e ), { - doc_id: doc_id, + doc_id: doc_id, + quote_id: doc_id, } ) ); return; diff --git a/test/server/token/MongoTokenDaoTest.ts b/test/server/token/MongoTokenDaoTest.ts index 23e403e..67e3a65 100644 --- a/test/server/token/MongoTokenDaoTest.ts +++ b/test/server/token/MongoTokenDaoTest.ts @@ -372,6 +372,7 @@ describe( 'server.token.TokenDao', () => `${ns}.tok123`, { doc_id: did, + quote_id: did, ns: ns, token_id: 'tok123', }, @@ -386,8 +387,9 @@ describe( 'server.token.TokenDao', () => null, ns, { - doc_id: did, - ns: ns, + doc_id: did, + quote_id: did, + ns: ns, }, ], @@ -440,8 +442,9 @@ describe( 'server.token.TokenDao', () => null, ns, { - doc_id: did, - ns: ns, + doc_id: did, + quote_id: did, + ns: ns, }, ], @@ -454,8 +457,9 @@ describe( 'server.token.TokenDao', () => null, ns, { - doc_id: did, - ns: ns, + doc_id: did, + quote_id: did, + ns: ns, }, ], ] ).forEach( ( [ label, tok_id, dbresult, expected, fmsg, fcontext ] ) => diff --git a/test/system/DeltaPublisherTest.ts b/test/system/DeltaPublisherTest.ts index f352b0c..b0bd702 100644 --- a/test/system/DeltaPublisherTest.ts +++ b/test/system/DeltaPublisherTest.ts @@ -123,6 +123,7 @@ describe( 'server.DeltaPublisher', () => const expected = { doc_id: meta.id, + quote_id: meta.id, delta_type: delta.type, delta_ts: delta.timestamp }