From 4c457c9a21985d3ac1d5f358ca531ce93826e594 Mon Sep 17 00:00:00 2001 From: Pavel Tiunov Date: Tue, 17 Mar 2020 12:58:27 -0700 Subject: [PATCH] feat: Log `requestId` in compiling schema events --- packages/cubejs-api-gateway/index.js | 7 ++++--- packages/cubejs-server-core/core/CompilerApi.js | 14 +++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/cubejs-api-gateway/index.js b/packages/cubejs-api-gateway/index.js index ff81946f52096..4283284fad41e 100644 --- a/packages/cubejs-api-gateway/index.js +++ b/packages/cubejs-api-gateway/index.js @@ -242,7 +242,8 @@ const coerceForSqlQuery = (query, context) => ({ timeDimensions: query.timeDimensions || [], contextSymbols: { userContext: context.authInfo && context.authInfo.u || {} - } + }, + requestId: context.requestId }); class ApiGateway { @@ -336,7 +337,7 @@ class ApiGateway { async meta({ context, res }) { const requestStarted = new Date(); try { - const metaConfig = await this.getCompilerApi(context).metaConfig(); + const metaConfig = await this.getCompilerApi(context).metaConfig({ requestId: context.requestId }); const cubes = metaConfig.map(c => c.config); res({ cubes }); } catch (e) { @@ -381,7 +382,7 @@ class ApiGateway { const normalizedQuery = await this.queryTransformer(normalizeQuery(query), context); const [compilerSqlResult, metaConfigResult] = await Promise.all([ this.getCompilerApi(context).getSql(coerceForSqlQuery(normalizedQuery, context)), - this.getCompilerApi(context).metaConfig() + this.getCompilerApi(context).metaConfig({ requestId: context.requestId }) ]); const sqlQuery = compilerSqlResult; this.log(context, { diff --git a/packages/cubejs-server-core/core/CompilerApi.js b/packages/cubejs-server-core/core/CompilerApi.js index b8e4e3af81983..d1e24b33b896c 100644 --- a/packages/cubejs-server-core/core/CompilerApi.js +++ b/packages/cubejs-server-core/core/CompilerApi.js @@ -15,7 +15,8 @@ class CompilerApi { this.compileContext = options.compileContext; } - async getCompilers() { + async getCompilers(options) { + const { requestId } = options || {}; let compilerVersion = ( this.schemaVersion && this.schemaVersion() || 'default_schema_version' @@ -25,7 +26,10 @@ class CompilerApi { compilerVersion += `_${crypto.createHash('md5').update(JSON.stringify(files)).digest("hex")}`; } if (!this.compilers || this.compilerVersion !== compilerVersion) { - this.logger(this.compilers ? 'Recompiling schema' : 'Compiling schema', { version: compilerVersion }); + this.logger(this.compilers ? 'Recompiling schema' : 'Compiling schema', { + version: compilerVersion, + requestId + }); // TODO check if saving this promise can produce memory leak? this.compilers = PrepareCompiler.compile(this.repository, { allowNodeRequire: this.allowNodeRequire, @@ -47,7 +51,7 @@ class CompilerApi { options = options || {}; const { includeDebugInfo } = options; const dbType = this.getDbType('default'); - const compilers = await this.getCompilers(); + const compilers = await this.getCompilers({ requestId: query.requestId }); let sqlGenerator = this.createQuery(compilers, dbType, query); const dataSource = compilers.compiler.withQuery(sqlGenerator, () => sqlGenerator.dataSource); @@ -89,8 +93,8 @@ class CompilerApi { ); } - async metaConfig() { - return (await this.getCompilers()).metaTransformer.cubes; + async metaConfig(options) { + return (await this.getCompilers(options)).metaTransformer.cubes; } }