Skip to content

Commit

Permalink
feat: Log requestId in compiling schema events
Browse files Browse the repository at this point in the history
  • Loading branch information
paveltiunov committed Mar 17, 2020
1 parent 4a03a67 commit 4c457c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 4 additions & 3 deletions packages/cubejs-api-gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ const coerceForSqlQuery = (query, context) => ({
timeDimensions: query.timeDimensions || [],
contextSymbols: {
userContext: context.authInfo && context.authInfo.u || {}
}
},
requestId: context.requestId
});

class ApiGateway {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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, {
Expand Down
14 changes: 9 additions & 5 deletions packages/cubejs-server-core/core/CompilerApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -89,8 +93,8 @@ class CompilerApi {
);
}

async metaConfig() {
return (await this.getCompilers()).metaTransformer.cubes;
async metaConfig(options) {
return (await this.getCompilers(options)).metaTransformer.cubes;
}
}

Expand Down

0 comments on commit 4c457c9

Please sign in to comment.