From ad12f2e0551427a809859fee3ec5b5616076bebc Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Tue, 19 Sep 2023 11:08:47 -0400 Subject: [PATCH 1/2] add logging for atlas-service ai request and response --- packages/atlas-service/src/main.ts | 87 +++++++++++++++++++----------- 1 file changed, 56 insertions(+), 31 deletions(-) diff --git a/packages/atlas-service/src/main.ts b/packages/atlas-service/src/main.ts index 056596cb8f9..879b341df11 100644 --- a/packages/atlas-service/src/main.ts +++ b/packages/atlas-service/src/main.ts @@ -336,12 +336,12 @@ export class AtlasService { log.info(mongoLogId(1_001_000_218), 'AtlasService', 'Starting sign in'); try { + const userInfo = await this.getUserInfo({ signal }); log.info( mongoLogId(1_001_000_219), 'AtlasService', 'Signed in successfully' ); - const userInfo = await this.getUserInfo({ signal }); track('Atlas Sign In Success', getTrackingUserInfo(userInfo)); return userInfo; } catch (err) { @@ -543,11 +543,17 @@ export class AtlasService { throwIfNetworkTrafficDisabled(); const userId = (await this.getActiveCompassUser()).id; + const url = `${this.config.atlasApiBaseUrl}/unauth/ai/api/v1/hello/${userId}`; - const res = await this.fetch( - `${this.config.atlasApiBaseUrl}/unauth/ai/api/v1/hello/${userId}` + log.info( + mongoLogId(1_001_000_227), + 'AtlasService', + 'Fetching if the AI feature is enabled via hello endpoint', + { userId, url } ); + const res = await this.fetch(url); + await throwIfNotOk(res); const body = await res.json(); @@ -558,12 +564,6 @@ export class AtlasService { } static async setupAIAccess(): Promise { - log.info( - mongoLogId(1_001_000_227), - 'AtlasService', - 'Fetching if the AI feature is enabled' - ); - try { throwIfNetworkTrafficDisabled(); @@ -578,6 +578,7 @@ export class AtlasService { 'Fetched if the AI feature is enabled', { enabled: isAIFeatureEnabled, + featureResponse, } ); @@ -643,18 +644,30 @@ export class AtlasService { } const token = await this.maybeGetToken({ signal }); + const url = `${this.config.atlasApiBaseUrl}/ai/api/v1/mql-aggregation`; - const res = await this.fetch( - `${this.config.atlasApiBaseUrl}/ai/api/v1/mql-aggregation`, - { - signal: signal as NodeFetchAbortSignal | undefined, - method: 'POST', - headers: { - Authorization: `Bearer ${token ?? ''}`, - 'Content-Type': 'application/json', - }, - body: msgBody, - } + log.info( + mongoLogId(1_001_000_247), + 'AtlasService', + 'Running aggregation generation request', + { url, body: msgBody } + ); + + const res = await this.fetch(url, { + signal: signal as NodeFetchAbortSignal | undefined, + method: 'POST', + headers: { + Authorization: `Bearer ${token ?? ''}`, + 'Content-Type': 'application/json', + }, + body: msgBody, + }); + + log.info( + mongoLogId(1_001_000_248), + 'AtlasService', + 'Received aggregation generation response', + { status: res.status, statusText: res.statusText } ); await throwIfNotOk(res); @@ -712,18 +725,30 @@ export class AtlasService { } const token = await this.maybeGetToken({ signal }); + const url = `${this.config.atlasApiBaseUrl}/ai/api/v1/mql-query`; - const res = await this.fetch( - `${this.config.atlasApiBaseUrl}/ai/api/v1/mql-query`, - { - signal: signal as NodeFetchAbortSignal | undefined, - method: 'POST', - headers: { - Authorization: `Bearer ${token ?? ''}`, - 'Content-Type': 'application/json', - }, - body: msgBody, - } + log.info( + mongoLogId(1_001_000_245), + 'AtlasService', + 'Running query generation request', + { url, body: msgBody } + ); + + const res = await this.fetch(url, { + signal: signal as NodeFetchAbortSignal | undefined, + method: 'POST', + headers: { + Authorization: `Bearer ${token ?? ''}`, + 'Content-Type': 'application/json', + }, + body: msgBody, + }); + + log.info( + mongoLogId(1_001_000_246), + 'AtlasService', + 'Received query generation response', + { status: res.status, statusText: res.statusText } ); await throwIfNotOk(res); From 7945bafb23fe3176d3395e24e7858fe9015cb9f3 Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Tue, 19 Sep 2023 12:04:45 -0400 Subject: [PATCH 2/2] update log ids --- packages/atlas-service/src/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/atlas-service/src/main.ts b/packages/atlas-service/src/main.ts index 879b341df11..33fae05545e 100644 --- a/packages/atlas-service/src/main.ts +++ b/packages/atlas-service/src/main.ts @@ -728,7 +728,7 @@ export class AtlasService { const url = `${this.config.atlasApiBaseUrl}/ai/api/v1/mql-query`; log.info( - mongoLogId(1_001_000_245), + mongoLogId(1_001_000_249), 'AtlasService', 'Running query generation request', { url, body: msgBody } @@ -745,7 +745,7 @@ export class AtlasService { }); log.info( - mongoLogId(1_001_000_246), + mongoLogId(1_001_000_250), 'AtlasService', 'Received query generation response', { status: res.status, statusText: res.statusText }