From c5337c652a2ac6b81a07f0a1704b04c2775089fe Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Tue, 18 Jul 2023 21:13:17 +0100 Subject: [PATCH] Remove no longer needed `LOG_CONTEXT` setting on logger module, update qa-core to disable pino logger via env var, add configurable jest timeout via env var --- packages/backend-core/src/logging/index.ts | 3 --- .../backend-core/src/logging/pino/logger.ts | 17 +++++++---------- qa-core/scripts/createEnv.js | 2 ++ qa-core/src/jest/globalSetup.ts | 18 +++++++++--------- qa-core/src/jest/jestSetup.ts | 7 +++---- 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/packages/backend-core/src/logging/index.ts b/packages/backend-core/src/logging/index.ts index b87062c478..49d643375d 100644 --- a/packages/backend-core/src/logging/index.ts +++ b/packages/backend-core/src/logging/index.ts @@ -1,6 +1,3 @@ export * as correlation from "./correlation/correlation" export { logger } from "./pino/logger" export * from "./alerts" - -// turn off or on context logging i.e. tenantId, appId etc -export let LOG_CONTEXT = true diff --git a/packages/backend-core/src/logging/pino/logger.ts b/packages/backend-core/src/logging/pino/logger.ts index c96bc83e04..8a5de9372d 100644 --- a/packages/backend-core/src/logging/pino/logger.ts +++ b/packages/backend-core/src/logging/pino/logger.ts @@ -3,7 +3,6 @@ import pino, { LoggerOptions } from "pino" import * as context from "../../context" import * as correlation from "../correlation" import { IdentityType } from "@budibase/types" -import { LOG_CONTEXT } from "../index" // LOGGER @@ -83,15 +82,13 @@ if (!env.DISABLE_PINO_LOGGER) { let contextObject = {} - if (LOG_CONTEXT) { - contextObject = { - tenantId: getTenantId(), - appId: getAppId(), - automationId: getAutomationId(), - identityId: identity?._id, - identityType: identity?.type, - correlationId: correlation.getId(), - } + contextObject = { + tenantId: getTenantId(), + appId: getAppId(), + automationId: getAutomationId(), + identityId: identity?._id, + identityType: identity?.type, + correlationId: correlation.getId(), } const mergingObject: any = { diff --git a/qa-core/scripts/createEnv.js b/qa-core/scripts/createEnv.js index e5ab783735..ebb165f3a9 100644 --- a/qa-core/scripts/createEnv.js +++ b/qa-core/scripts/createEnv.js @@ -12,6 +12,8 @@ function init() { BB_ADMIN_USER_EMAIL: "admin", BB_ADMIN_USER_PASSWORD: "admin", LOG_LEVEL: "info", + JEST_TIMEOUT: "60000", + DISABLE_PINO_LOGGER: "1" } let envFile = "" Object.keys(envFileJson).forEach(key => { diff --git a/qa-core/src/jest/globalSetup.ts b/qa-core/src/jest/globalSetup.ts index e11d0e4423..68300cee26 100644 --- a/qa-core/src/jest/globalSetup.ts +++ b/qa-core/src/jest/globalSetup.ts @@ -1,5 +1,4 @@ -process.env.DISABLE_PINO_LOGGER = "1" -import { DEFAULT_TENANT_ID, logging } from "@budibase/backend-core" +import { DEFAULT_TENANT_ID } from "@budibase/backend-core" import { AccountInternalAPI } from "../account-api" import * as fixtures from "../internal-api/fixtures" import { BudibaseInternalAPI } from "../internal-api" @@ -7,10 +6,6 @@ import { Account, CreateAccountRequest, Feature } from "@budibase/types" import env from "../environment" import { APIRequestOpts } from "../types" -// turn off or on context logging i.e. tenantId, appId etc -// it's not applicable for the qa run -logging.LOG_CONTEXT = false - const accountsApi = new AccountInternalAPI({}) const internalApi = new BudibaseInternalAPI({}) @@ -24,7 +19,7 @@ async function createAccount(): Promise<[CreateAccountRequest, Account]> { await accountsApi.accounts.validateEmail(account.email, API_OPTS) await accountsApi.accounts.validateTenantId(account.tenantId, API_OPTS) const [res, newAccount] = await accountsApi.accounts.create( - account, {...API_OPTS, autoVerify: true}) + account, {...API_OPTS, autoVerify: true }) await updateLicense(newAccount.accountId) return [account, newAccount] } @@ -32,7 +27,7 @@ async function createAccount(): Promise<[CreateAccountRequest, Account]> { const UNLIMITED = { value: -1 } async function updateLicense(accountId: string) { - await accountsApi.licenses.updateLicense(accountId, { + const [response] = await accountsApi.licenses.updateLicense(accountId, { overrides: { // add all features features: Object.values(Feature), @@ -50,7 +45,12 @@ async function updateLicense(accountId: string) { }, }, }, - }) + }, { doExpect: false }) + if (response.status !== 200) { + throw new Error( + `Could not update license for accountId=${accountId}: ${response.status}` + ) + } } async function loginAsAdmin() { diff --git a/qa-core/src/jest/jestSetup.ts b/qa-core/src/jest/jestSetup.ts index 5c86d5fd24..928e547337 100644 --- a/qa-core/src/jest/jestSetup.ts +++ b/qa-core/src/jest/jestSetup.ts @@ -1,4 +1,3 @@ -import { logging } from "@budibase/backend-core" -logging.LOG_CONTEXT = false - -jest.setTimeout(60000) +const envTimeout = process.env.JEST_TIMEOUT +const timeout = envTimeout && parseInt(envTimeout) +jest.setTimeout(timeout || 60000)