diff --git a/package.json b/package.json index 4989a2e51a2..c8a3285e239 100644 --- a/package.json +++ b/package.json @@ -63,15 +63,15 @@ "-- CI SCRIPTS ": "-----------------------------------------------------------------------------------------------", "build": "./scripts/build/build-ci.sh", "ci-compile": "node scripts/ci/check-versions.js && node scripts/build/cli npmCiModules && npm run lint && npm run unit-nginx && npm run unit-haproxy && npm run unit-haproxy-healthcheck && npm run unit-cht-deploy && npm run build && npm run integration-api && npm run unit", - "ci-integration-all": "mocha --config tests/integration/.mocharc-all.js", - "ci-integration-replication": "mocha --config tests/integration/.mocharc-replication.js", - "ci-integration-all-k3d": "mocha --config tests/integration/.mocharc-k3d.js", - "ci-integration-sentinel": "mocha --config tests/integration/.mocharc-sentinel.js", - "ci-integration-sentinel-k3d": "mocha --config tests/integration/.mocharc-sentinel-k3d.js", - "ci-webdriver-default": "wdio run ./tests/e2e/default/wdio.conf.js", - "ci-webdriver-default-mobile": "wdio run ./tests/e2e/default-mobile/wdio.conf.js", - "ci-webdriver-visual-desktop": "wdio run ./tests/e2e/visual/wdio.conf.js --suite=desktopTests", - "ci-webdriver-visual-mobile": "wdio run ./tests/e2e/visual/wdio.conf.js --suite=mobileTests", + "ci-integration-all": "LOG_LEVEL=debug mocha --config tests/integration/.mocharc-all.js", + "ci-integration-replication": "LOG_LEVEL=debug mocha --config tests/integration/.mocharc-replication.js", + "ci-integration-all-k3d": "LOG_LEVEL=debug mocha --config tests/integration/.mocharc-k3d.js", + "ci-integration-sentinel": "LOG_LEVEL=debug mocha --config tests/integration/.mocharc-sentinel.js", + "ci-integration-sentinel-k3d": "LOG_LEVEL=debug mocha --config tests/integration/.mocharc-sentinel-k3d.js", + "ci-webdriver-default": "LOG_LEVEL=debug wdio run ./tests/e2e/default/wdio.conf.js", + "ci-webdriver-default-mobile": "LOG_LEVEL=debug wdio run ./tests/e2e/default-mobile/wdio.conf.js", + "ci-webdriver-visual-desktop": "LOG_LEVEL=debug wdio run ./tests/e2e/visual/wdio.conf.js --suite=desktopTests", + "ci-webdriver-visual-mobile": "LOG_LEVEL=debug wdio run ./tests/e2e/visual/wdio.conf.js --suite=mobileTests", "publish-for-testing": "./scripts/build/build-service-images.sh && mkdir -p images && node scripts/build/cli publishServiceImages && node ./scripts/build/ddoc-compile.js staging && node ./scripts/build/push-ddoc-to-staging.js", "test-config-covid-19": "cd config/covid-19 && npm run test", "test-config-default": "cd config/default && npm run test", diff --git a/scripts/build/helm/templates/api/deployment.yaml b/scripts/build/helm/templates/api/deployment.yaml index 3d50e406a68..da68bbbe389 100644 --- a/scripts/build/helm/templates/api/deployment.yaml +++ b/scripts/build/helm/templates/api/deployment.yaml @@ -19,6 +19,8 @@ spec: terminationGracePeriodSeconds: 0 containers: - env: + - name: LOG_LEVEL + value: '{{ .Values.api.log_level | default "info" }}' - name: BUILDS_URL value: {{ .Values.upstream_servers.builds_url | default "https://staging.dev.medicmobile.org/_couch/builds_4" }} - name: COUCH_URL diff --git a/scripts/build/helm/templates/sentinel/deployment.yaml b/scripts/build/helm/templates/sentinel/deployment.yaml index 13a05b91455..03f7479ae79 100644 --- a/scripts/build/helm/templates/sentinel/deployment.yaml +++ b/scripts/build/helm/templates/sentinel/deployment.yaml @@ -18,6 +18,8 @@ spec: spec: containers: - env: + - name: LOG_LEVEL + value: '{{ .Values.sentinel.log_level | default "info" }}' - name: API_HOST value: api.{{ .Values.namespace }}.svc.cluster.local - name: COUCH_URL diff --git a/scripts/build/helm/tests/integration-k3d-values.yaml.template b/scripts/build/helm/tests/integration-k3d-values.yaml.template index c14c8fa1fb9..722f7a56197 100644 --- a/scripts/build/helm/tests/integration-k3d-values.yaml.template +++ b/scripts/build/helm/tests/integration-k3d-values.yaml.template @@ -27,3 +27,10 @@ local_storage: preExistingDiskPath-2: "{{{data_path}}}/srv2" preExistingDiskPath-3: "{{{data_path}}}/srv3" +# API log level for integration tests +api: + log_level: "debug" + +# Sentinel log level for integration tests +sentinel: + log_level: "debug" \ No newline at end of file diff --git a/shared-libs/logger/src/node-logger.js b/shared-libs/logger/src/node-logger.js index 4488aa17e2b..3744c382d11 100644 --- a/shared-libs/logger/src/node-logger.js +++ b/shared-libs/logger/src/node-logger.js @@ -1,5 +1,7 @@ const { createLogger, format, transports } = require('winston'); -const env = process.env.NODE_ENV || 'development'; +// LOG_LEVEL controls logging globally. Defaults to 'info' if not explicitly set. +const logLevel = process.env.LOG_LEVEL || 'info'; + const cleanUpErrorsFromSymbolProperties = (info) => { if (!info) { @@ -61,7 +63,7 @@ module.exports.create = (dateFormat) => createLogger({ transports: [ new transports.Console({ // change level if in dev environment versus production - level: env === 'development' ? 'debug' : 'info', + level: logLevel, format: format.combine( // https://github.com/winstonjs/winston/issues/1345 format(info => { diff --git a/tests/utils/index.js b/tests/utils/index.js index eeffa741223..20d7384b254 100644 --- a/tests/utils/index.js +++ b/tests/utils/index.js @@ -1174,12 +1174,41 @@ const generateComposeFiles = async () => { couchdb_servers: 'couchdb-1.local,couchdb-2.local,couchdb-3.local', }; + const INJECT_SERVICES = ['api', 'sentinel']; + for (const file of COMPOSE_FILES) { const templatePath = getTemplateComposeFilePath(file); const testComposePath = getTestComposeFilePath(file); const template = await fs.promises.readFile(templatePath, 'utf-8'); - await fs.promises.writeFile(testComposePath, mustache.render(template, view)); + let compiled = mustache.render(template, view); + + INJECT_SERVICES.forEach((svc) => { + const svcHeader = `\n ${svc}:`; + const start = compiled.indexOf(svcHeader); + if (start === -1) { + return; + } + + const rest = compiled.slice(start + 1); + + const nextServiceMatch = rest.search(/\n {2}[a-zA-Z0-9_-]+:/); + const block = nextServiceMatch === -1 ? rest : rest.slice(0, nextServiceMatch + 1); + + const envMarker = '\n environment:\n'; + const envIdxInBlock = block.indexOf(envMarker); + + if (envIdxInBlock !== -1) { + const insertPos = start + 1 + envIdxInBlock + envMarker.length; + const logLine = ' - "LOG_LEVEL=${LOG_LEVEL:-debug}"\n'; + compiled = compiled.slice(0, insertPos) + logLine + compiled.slice(insertPos); + } else { + const serviceLineEnd = compiled.indexOf('\n', start + 1) + 1; + const insertion = ' environment:\n - "LOG_LEVEL=${LOG_LEVEL:-debug}"\n'; + compiled = compiled.slice(0, serviceLineEnd) + insertion + compiled.slice(serviceLineEnd); + } + }); + await fs.promises.writeFile(testComposePath, compiled); } };