From 8232c4a4dc9be3d750239e56098a46373b72b9a1 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Wed, 21 Feb 2024 16:00:54 +0000 Subject: [PATCH] Refactor code and remove unnecessary blank lines --- App/Index.ts | 3 - .../Services/AnalyticsDatabaseService.ts | 3 +- CommonServer/Utils/Logger.ts | 1 - CommonServer/Utils/OpenTelemetry.ts | 15 +---- CommonServer/Utils/StartServer.ts | 1 - .../src/Components/GanttChart/Bar/Index.tsx | 41 +++++++----- .../src/Components/LogsViewer/LogItem.tsx | 11 ++-- Ingestor/API/OTelIngest.ts | 62 +++++++++++++------ 8 files changed, 82 insertions(+), 55 deletions(-) diff --git a/App/Index.ts b/App/Index.ts index 73c40fa32b..80aa5551e9 100755 --- a/App/Index.ts +++ b/App/Index.ts @@ -1,4 +1,3 @@ - import OpenTelemetrySDK from 'CommonServer/Utils/OpenTelemetry'; import 'ejs'; import Redis from 'CommonServer/Infrastructure/Redis'; @@ -16,7 +15,6 @@ import './FeatureSet/ApiReference/Index'; import Workers from './FeatureSet/Workers/Index'; import Workflow from './FeatureSet/Workflow/Index'; - // home should be in the end. import './FeatureSet/Home/Index'; @@ -48,7 +46,6 @@ const init: () => Promise = async (): Promise => { await Workflow.init(); OpenTelemetrySDK?.start(); - } catch (err) { logger.error('App Init Failed:'); logger.error(err); diff --git a/CommonServer/Services/AnalyticsDatabaseService.ts b/CommonServer/Services/AnalyticsDatabaseService.ts index 0d6761d76d..77c14e5c0f 100644 --- a/CommonServer/Services/AnalyticsDatabaseService.ts +++ b/CommonServer/Services/AnalyticsDatabaseService.ts @@ -810,7 +810,8 @@ export default class AnalyticsDatabaseService< throw new BadDataException(`${requiredField} is required`); } } else if ( - ((data as any)[requiredField] === null || (data as any)[requiredField] === undefined) && + ((data as any)[requiredField] === null || + (data as any)[requiredField] === undefined) && !data.isDefaultValueColumn(requiredField) ) { throw new BadDataException(`${requiredField} is required`); diff --git a/CommonServer/Utils/Logger.ts b/CommonServer/Utils/Logger.ts index f55a4f4a8b..880ef3e14d 100644 --- a/CommonServer/Utils/Logger.ts +++ b/CommonServer/Utils/Logger.ts @@ -1,6 +1,5 @@ import { createLogger, Logger, transports } from 'winston'; - const logger: Logger = createLogger({ transports: [new transports.Console()], }); diff --git a/CommonServer/Utils/OpenTelemetry.ts b/CommonServer/Utils/OpenTelemetry.ts index f03e1b6383..597004b114 100644 --- a/CommonServer/Utils/OpenTelemetry.ts +++ b/CommonServer/Utils/OpenTelemetry.ts @@ -3,22 +3,17 @@ import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'; import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto'; import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'; import Dictionary from 'Common/Types/Dictionary'; -import { - BatchLogRecordProcessor, -} from '@opentelemetry/sdk-logs'; +import { BatchLogRecordProcessor } from '@opentelemetry/sdk-logs'; import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http'; import { AWSXRayIdGenerator } from '@opentelemetry/id-generator-aws-xray'; import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'; - let sdk: opentelemetry.NodeSDK | null = null; if ( process.env['OTEL_EXPORTER_OTLP_ENDPOINT'] && process.env['OTEL_EXPORTER_OTLP_HEADERS'] ) { - - const headersStrings: Array = process.env['OTEL_EXPORTER_OTLP_HEADERS'].split(';'); @@ -38,12 +33,11 @@ if ( headers: headers, }); - sdk = new opentelemetry.NodeSDK({ idGenerator: new AWSXRayIdGenerator(), traceExporter: new OTLPTraceExporter({ url: otlpEndpoint + '/v1/traces', - headers: headers + headers: headers, }), metricReader: new PeriodicExportingMetricReader({ exporter: new OTLPMetricExporter({ @@ -52,9 +46,7 @@ if ( }), }) as any, logRecordProcessor: new BatchLogRecordProcessor(logExporter) as any, - instrumentations: [ - getNodeAutoInstrumentations(), - ], + instrumentations: [getNodeAutoInstrumentations()], }); process.on('SIGTERM', () => { @@ -65,4 +57,3 @@ if ( } export default sdk; - diff --git a/CommonServer/Utils/StartServer.ts b/CommonServer/Utils/StartServer.ts index a0341069f4..326902f1f3 100644 --- a/CommonServer/Utils/StartServer.ts +++ b/CommonServer/Utils/StartServer.ts @@ -31,7 +31,6 @@ import ServerException from 'Common/Types/Exception/ServerException'; import zlib from 'zlib'; import CookieParser from 'cookie-parser'; - // Make sure we have stack trace for debugging. Error.stackTraceLimit = Infinity; diff --git a/CommonUI/src/Components/GanttChart/Bar/Index.tsx b/CommonUI/src/Components/GanttChart/Bar/Index.tsx index 4ba14acb0a..e0ba18c6a4 100644 --- a/CommonUI/src/Components/GanttChart/Bar/Index.tsx +++ b/CommonUI/src/Components/GanttChart/Bar/Index.tsx @@ -49,7 +49,8 @@ const Bar: FunctionComponent = ( } const eachCharacterWidth: number = 8; - const showLabelOutsideBar: boolean = barWidth < props.bar.title.length * eachCharacterWidth; + const showLabelOutsideBar: boolean = + barWidth < props.bar.title.length * eachCharacterWidth; const handleMouseEnter: MouseEventHandler = (): void => { setIsHovered(true); @@ -61,9 +62,12 @@ const Bar: FunctionComponent = ( return ( // rectangle div with curved corners and text inside in tailwindcss -
+
= ( onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave} > - {!showLabelOutsideBar && } + {!showLabelOutsideBar && ( + + )} {isHovered && props.bar.tooltip && (
{props.bar.tooltip}
)}
- {showLabelOutsideBar &&
} + {showLabelOutsideBar && ( +
+ +
+ )}
); }; diff --git a/CommonUI/src/Components/LogsViewer/LogItem.tsx b/CommonUI/src/Components/LogsViewer/LogItem.tsx index 663ab3c114..12082ceb27 100644 --- a/CommonUI/src/Components/LogsViewer/LogItem.tsx +++ b/CommonUI/src/Components/LogsViewer/LogItem.tsx @@ -6,8 +6,6 @@ export interface ComponentProps { log: Log; } - - const LogItem: FunctionComponent = ( props: ComponentProps ): ReactElement => { @@ -19,7 +17,11 @@ const LogItem: FunctionComponent = ( let bodyColor: string = 'text-slate-200'; - if (props.log.severityText === LogSeverity.Warning || props.log.severityText === LogSeverity.Trace || props.log.severityText === LogSeverity.Debug) { + if ( + props.log.severityText === LogSeverity.Warning || + props.log.severityText === LogSeverity.Trace || + props.log.severityText === LogSeverity.Debug + ) { bodyColor = 'text-amber-400'; } else if (props.log.severityText === LogSeverity.Error) { bodyColor = 'text-rose-400'; @@ -76,7 +78,6 @@ const LogItem: FunctionComponent = ( [FATAL]  
)} -
{props.log.body?.toString()} @@ -158,7 +159,7 @@ const LogItem: FunctionComponent = (
)} - {props.log.severityText === LogSeverity.Fatal && ( + {props.log.severityText === LogSeverity.Fatal && (
SEVERITY: diff --git a/Ingestor/API/OTelIngest.ts b/Ingestor/API/OTelIngest.ts index c185edfe45..3afd6a033c 100644 --- a/Ingestor/API/OTelIngest.ts +++ b/Ingestor/API/OTelIngest.ts @@ -481,21 +481,31 @@ router.post( log['timeUnixNano'] as number ); - let logSeverityNumber: number = log['severityNumber'] as number || 0; // 0 is Unspecified by default. + let logSeverityNumber: number = + (log['severityNumber'] as number) || 0; // 0 is Unspecified by default. - if(typeof logSeverityNumber === 'string') { - - if(logSeverityNumber === 'SEVERITY_NUMBER_TRACE') { + if (typeof logSeverityNumber === 'string') { + if (logSeverityNumber === 'SEVERITY_NUMBER_TRACE') { logSeverityNumber = 1; - } else if(logSeverityNumber === 'SEVERITY_NUMBER_DEBUG') { + } else if ( + logSeverityNumber === 'SEVERITY_NUMBER_DEBUG' + ) { logSeverityNumber = 5; - } else if(logSeverityNumber === 'SEVERITY_NUMBER_INFO') { + } else if ( + logSeverityNumber === 'SEVERITY_NUMBER_INFO' + ) { logSeverityNumber = 9; - } else if(logSeverityNumber === 'SEVERITY_NUMBER_WARN') { + } else if ( + logSeverityNumber === 'SEVERITY_NUMBER_WARN' + ) { logSeverityNumber = 13; - } else if(logSeverityNumber === 'SEVERITY_NUMBER_ERROR') { + } else if ( + logSeverityNumber === 'SEVERITY_NUMBER_ERROR' + ) { logSeverityNumber = 17; - } else if(logSeverityNumber === 'SEVERITY_NUMBER_FATAL') { + } else if ( + logSeverityNumber === 'SEVERITY_NUMBER_FATAL' + ) { logSeverityNumber = 21; } else { logSeverityNumber = parseInt(logSeverityNumber); @@ -506,26 +516,42 @@ router.post( let logSeverity: LogSeverity = LogSeverity.Unspecified; - // these numbers are from the opentelemetry/api-logs package - if(logSeverityNumber < 0 || logSeverityNumber > 24) { + if (logSeverityNumber < 0 || logSeverityNumber > 24) { logSeverity = LogSeverity.Unspecified; logSeverityNumber = 0; - }else if (logSeverityNumber >= 1 && logSeverityNumber <= 4) { + } else if ( + logSeverityNumber >= 1 && + logSeverityNumber <= 4 + ) { logSeverity = LogSeverity.Trace; - }else if (logSeverityNumber >= 5 && logSeverityNumber <= 8) { + } else if ( + logSeverityNumber >= 5 && + logSeverityNumber <= 8 + ) { logSeverity = LogSeverity.Debug; - } else if (logSeverityNumber >= 9 && logSeverityNumber <= 12) { + } else if ( + logSeverityNumber >= 9 && + logSeverityNumber <= 12 + ) { logSeverity = LogSeverity.Information; - } else if (logSeverityNumber >= 13 && logSeverityNumber <= 16) { + } else if ( + logSeverityNumber >= 13 && + logSeverityNumber <= 16 + ) { logSeverity = LogSeverity.Warning; - } else if (logSeverityNumber >= 17 && logSeverityNumber <= 20) { + } else if ( + logSeverityNumber >= 17 && + logSeverityNumber <= 20 + ) { logSeverity = LogSeverity.Error; - } else if (logSeverityNumber >= 21 && logSeverityNumber <= 24) { + } else if ( + logSeverityNumber >= 21 && + logSeverityNumber <= 24 + ) { logSeverity = LogSeverity.Fatal; } - dbLog.severityText = logSeverity; const logBody: JSONObject = log['body'] as JSONObject;