From e7377f6c8fe514cbca806a683c0d58aa4d90d52f Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Thu, 5 Sep 2024 14:30:30 +0100 Subject: [PATCH] refactor: Enable lazy loading for images in BlogPostUtil and remove unnecessary whitespace in Copilot/Init.ts --- Accounts/Dockerfile.tpl | 5 +++++ AdminDashboard/Dockerfile.tpl | 5 +++++ App/Dockerfile.tpl | 5 +++++ Common/Server/Utils/Telemetry.ts | 26 ++++++++++++-------------- Copilot/Dockerfile.tpl | 5 +++++ Copilot/Init.ts | 20 ++++++++++++++++++-- Copilot/Utils/CodeRepository.ts | 2 ++ Copilot/Utils/ServiceRepository.ts | 4 ++-- Dashboard/Dockerfile.tpl | 5 +++++ E2E/Dockerfile.tpl | 5 +++++ Haraka/Dockerfile.tpl | 5 +++++ Ingestor/Dockerfile.tpl | 5 +++++ IsolatedVM/Dockerfile.tpl | 5 +++++ Probe/Dockerfile.tpl | 5 +++++ StatusPage/Dockerfile.tpl | 5 +++++ TestServer/Dockerfile.tpl | 4 ++++ Tests/Dockerfile.tpl | 5 +++++ 17 files changed, 98 insertions(+), 18 deletions(-) diff --git a/Accounts/Dockerfile.tpl b/Accounts/Dockerfile.tpl index 11e1e10025..d0c40b2801 100644 --- a/Accounts/Dockerfile.tpl +++ b/Accounts/Dockerfile.tpl @@ -6,6 +6,11 @@ FROM node:21.7.3-alpine3.18 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global +RUN npm config set fetch-retries 5 +RUN npm config set fetch-retry-mintimeout 100000 +RUN npm config set fetch-retry-maxtimeout 600000 + + ARG GIT_SHA ARG APP_VERSION diff --git a/AdminDashboard/Dockerfile.tpl b/AdminDashboard/Dockerfile.tpl index feb2fbd906..8c091581cd 100644 --- a/AdminDashboard/Dockerfile.tpl +++ b/AdminDashboard/Dockerfile.tpl @@ -6,6 +6,11 @@ FROM node:21.7.3-alpine3.18 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global +RUN npm config set fetch-retries 5 +RUN npm config set fetch-retry-mintimeout 100000 +RUN npm config set fetch-retry-maxtimeout 600000 + + ARG GIT_SHA ARG APP_VERSION diff --git a/App/Dockerfile.tpl b/App/Dockerfile.tpl index 448cdb8897..9bb2208c86 100644 --- a/App/Dockerfile.tpl +++ b/App/Dockerfile.tpl @@ -6,6 +6,11 @@ FROM node:21.2-alpine3.18 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global +RUN npm config set fetch-retries 5 +RUN npm config set fetch-retry-mintimeout 100000 +RUN npm config set fetch-retry-maxtimeout 600000 + + ARG GIT_SHA ARG APP_VERSION diff --git a/Common/Server/Utils/Telemetry.ts b/Common/Server/Utils/Telemetry.ts index e848eba154..dabe13ba0b 100644 --- a/Common/Server/Utils/Telemetry.ts +++ b/Common/Server/Utils/Telemetry.ts @@ -18,10 +18,8 @@ import { CompressionAlgorithm } from "@opentelemetry/otlp-exporter-base"; import { Resource } from "@opentelemetry/resources"; import { BatchLogRecordProcessor, - ConsoleLogRecordExporter, LoggerProvider, LogRecordProcessor, - SimpleLogRecordProcessor, } from "@opentelemetry/sdk-logs"; import { MeterProvider, @@ -167,9 +165,7 @@ export default class Telemetry { }), }); - let logRecordProcessor: LogRecordProcessor = new SimpleLogRecordProcessor( - new ConsoleLogRecordExporter(), - ); + let logRecordProcessor: LogRecordProcessor | null = null; if (this.getOltpLogsEndpoint() && hasHeaders) { const logExporter: OTLPLogExporter = new OTLPLogExporter({ @@ -181,19 +177,21 @@ export default class Telemetry { logRecordProcessor = new BatchLogRecordProcessor(logExporter); } - this.loggerProvider.addLogRecordProcessor(logRecordProcessor); + if (logRecordProcessor) { + this.loggerProvider.addLogRecordProcessor(logRecordProcessor); + } logs.setGlobalLoggerProvider(this.loggerProvider); const nodeSdkConfiguration: Partial = - { - idGenerator: new AWSXRayIdGenerator(), - instrumentations: [], - resource: this.getResource({ - serviceName: data.serviceName, - }), - autoDetectResources: true, - }; + { + idGenerator: new AWSXRayIdGenerator(), + instrumentations: [], + resource: this.getResource({ + serviceName: data.serviceName, + }), + autoDetectResources: true, + }; if (traceExporter) { nodeSdkConfiguration.traceExporter = traceExporter; diff --git a/Copilot/Dockerfile.tpl b/Copilot/Dockerfile.tpl index 5ccd291ef5..9fbe16e2d8 100644 --- a/Copilot/Dockerfile.tpl +++ b/Copilot/Dockerfile.tpl @@ -6,6 +6,11 @@ FROM node:22.3.0 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global +RUN npm config set fetch-retries 5 +RUN npm config set fetch-retry-mintimeout 100000 +RUN npm config set fetch-retry-maxtimeout 600000 + + ARG GIT_SHA ARG APP_VERSION diff --git a/Copilot/Init.ts b/Copilot/Init.ts index c52f5c6051..bf53992334 100644 --- a/Copilot/Init.ts +++ b/Copilot/Init.ts @@ -27,6 +27,9 @@ let currentFixCount: number = 1; const init: PromiseVoidFunction = async (): Promise => { // check if copilot is disabled. + + debugger; + if (GetIsCopilotDisabled()) { logger.info("Copilot is disabled. Exiting."); ProcessUtil.haltProcessWithSuccess(); @@ -49,6 +52,19 @@ const init: PromiseVoidFunction = async (): Promise => { const servicesToImprove: ServiceCopilotCodeRepository[] = await ServiceRepositoryUtil.getServicesToImprove(); + + logger.debug(`Found ${servicesToImprove.length} services to improve.`); + + // if no services to improve, then exit. + if (servicesToImprove.length === 0) { + logger.info("No services to improve. Exiting."); + ProcessUtil.haltProcessWithSuccess(); + } + + for (const serviceToImprove of servicesToImprove) { + logger.debug(`- ${serviceToImprove.serviceCatalog!.name}`); + } + await cloneRepository({ codeRepositoryResult, }); @@ -207,8 +223,8 @@ const setUpRepository: PromiseVoidFunction = async (): Promise => { logger.info( "Repository setup PR created - #" + - pullRequest.pullRequestNumber + - ". Please megre this PR to continue using Copilot. Exiting..", + pullRequest.pullRequestNumber + + ". Please megre this PR to continue using Copilot. Exiting..", ); ProcessUtil.haltProcessWithSuccess(); diff --git a/Copilot/Utils/CodeRepository.ts b/Copilot/Utils/CodeRepository.ts index 88cc0c3729..375e79dd8a 100644 --- a/Copilot/Utils/CodeRepository.ts +++ b/Copilot/Utils/CodeRepository.ts @@ -290,6 +290,8 @@ export default class CodeRepositoryUtil { }); this.folderNameOfClonedRepository = folderName; + + logger.debug(`Repository cloned to ${repoLocalPath}/${folderName}`); } public static async executeScript(data: { script: string }): Promise { diff --git a/Copilot/Utils/ServiceRepository.ts b/Copilot/Utils/ServiceRepository.ts index bce6cab04b..e007718302 100644 --- a/Copilot/Utils/ServiceRepository.ts +++ b/Copilot/Utils/ServiceRepository.ts @@ -19,7 +19,7 @@ import ObjectID from "Common/Types/ObjectID"; export default class ServiceRepositoryUtil { public static codeRepositoryResult: CodeRepositoryResult | null = null; - public static servicesToImprove: Array = []; + public static servicesToImprove: Array | null = null; public static setCodeRepositoryResult(data: { codeRepositoryResult: CodeRepositoryResult; @@ -103,7 +103,7 @@ export default class ServiceRepositoryUtil { const { serviceCatalogId } = data; const serviceRepository: ServiceCopilotCodeRepository | undefined = - ServiceRepositoryUtil.servicesToImprove.find( + (await ServiceRepositoryUtil.getServicesToImprove()).find( (serviceRepository: ServiceCopilotCodeRepository) => { return ( serviceRepository.serviceCatalog!.id?.toString() === diff --git a/Dashboard/Dockerfile.tpl b/Dashboard/Dockerfile.tpl index 57c3b6edcd..0b13838152 100644 --- a/Dashboard/Dockerfile.tpl +++ b/Dashboard/Dockerfile.tpl @@ -6,6 +6,11 @@ FROM node:21.7.3-alpine3.18 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global +RUN npm config set fetch-retries 5 +RUN npm config set fetch-retry-mintimeout 100000 +RUN npm config set fetch-retry-maxtimeout 600000 + + ARG GIT_SHA ARG APP_VERSION diff --git a/E2E/Dockerfile.tpl b/E2E/Dockerfile.tpl index a4ba4a320c..bbf599ccf6 100644 --- a/E2E/Dockerfile.tpl +++ b/E2E/Dockerfile.tpl @@ -9,6 +9,11 @@ FROM node:21.6 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global +RUN npm config set fetch-retries 5 +RUN npm config set fetch-retry-mintimeout 100000 +RUN npm config set fetch-retry-maxtimeout 600000 + + ARG GIT_SHA ARG APP_VERSION diff --git a/Haraka/Dockerfile.tpl b/Haraka/Dockerfile.tpl index b01a771719..cfc1c60199 100644 --- a/Haraka/Dockerfile.tpl +++ b/Haraka/Dockerfile.tpl @@ -2,6 +2,11 @@ FROM node:21.7.3-alpine3.18 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global +RUN npm config set fetch-retries 5 +RUN npm config set fetch-retry-mintimeout 100000 +RUN npm config set fetch-retry-maxtimeout 600000 + + ARG GIT_SHA ARG APP_VERSION diff --git a/Ingestor/Dockerfile.tpl b/Ingestor/Dockerfile.tpl index 5a900d3eb0..e395188b87 100644 --- a/Ingestor/Dockerfile.tpl +++ b/Ingestor/Dockerfile.tpl @@ -6,6 +6,11 @@ FROM node:21.7.3-alpine3.18 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global +RUN npm config set fetch-retries 5 +RUN npm config set fetch-retry-mintimeout 100000 +RUN npm config set fetch-retry-maxtimeout 600000 + + ARG GIT_SHA ARG APP_VERSION diff --git a/IsolatedVM/Dockerfile.tpl b/IsolatedVM/Dockerfile.tpl index cf1bcb9248..a032904130 100644 --- a/IsolatedVM/Dockerfile.tpl +++ b/IsolatedVM/Dockerfile.tpl @@ -6,6 +6,11 @@ FROM node:21.6-alpine3.18 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global +RUN npm config set fetch-retries 5 +RUN npm config set fetch-retry-mintimeout 100000 +RUN npm config set fetch-retry-maxtimeout 600000 + + ARG GIT_SHA ARG APP_VERSION diff --git a/Probe/Dockerfile.tpl b/Probe/Dockerfile.tpl index 67865af240..a5c4408d32 100644 --- a/Probe/Dockerfile.tpl +++ b/Probe/Dockerfile.tpl @@ -6,6 +6,11 @@ FROM node:22.5 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global +RUN npm config set fetch-retries 5 +RUN npm config set fetch-retry-mintimeout 100000 +RUN npm config set fetch-retry-maxtimeout 600000 + + ARG GIT_SHA ARG APP_VERSION diff --git a/StatusPage/Dockerfile.tpl b/StatusPage/Dockerfile.tpl index d201565466..ca248e4907 100644 --- a/StatusPage/Dockerfile.tpl +++ b/StatusPage/Dockerfile.tpl @@ -6,6 +6,11 @@ FROM node:21.7.3-alpine3.18 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global +RUN npm config set fetch-retries 5 +RUN npm config set fetch-retry-mintimeout 100000 +RUN npm config set fetch-retry-maxtimeout 600000 + + ARG GIT_SHA ARG APP_VERSION diff --git a/TestServer/Dockerfile.tpl b/TestServer/Dockerfile.tpl index 5cf5931e2f..2c98a32b7e 100644 --- a/TestServer/Dockerfile.tpl +++ b/TestServer/Dockerfile.tpl @@ -6,6 +6,10 @@ FROM node:21.7.3-alpine3.18 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global +RUN npm config set fetch-retries 5 +RUN npm config set fetch-retry-mintimeout 100000 +RUN npm config set fetch-retry-maxtimeout 600000 + ARG GIT_SHA ARG APP_VERSION diff --git a/Tests/Dockerfile.tpl b/Tests/Dockerfile.tpl index dd79c21161..1518205242 100644 --- a/Tests/Dockerfile.tpl +++ b/Tests/Dockerfile.tpl @@ -1,6 +1,11 @@ FROM node:21.7.3-alpine3.18 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global +RUN npm config set fetch-retries 5 +RUN npm config set fetch-retry-mintimeout 100000 +RUN npm config set fetch-retry-maxtimeout 600000 + + # Install bash. RUN apk add bash && apk add curl