From 038684e512da302216ae795b1e578cfaadd635be Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Mon, 1 Apr 2024 12:23:29 +0100 Subject: [PATCH] Fix probeId conversion to string in ProbeMonitorResponseService --- .../Utils/Probe/ProbeMonitorResponse.ts | 4 +- .../Monitor/MonitorCharts/MonitorChart.tsx | 89 ++++++++++++------- docker-compose.dev.yml | 24 +++++ 3 files changed, 82 insertions(+), 35 deletions(-) diff --git a/CommonServer/Utils/Probe/ProbeMonitorResponse.ts b/CommonServer/Utils/Probe/ProbeMonitorResponse.ts index 64ccf57b89..9f23264eab 100644 --- a/CommonServer/Utils/Probe/ProbeMonitorResponse.ts +++ b/CommonServer/Utils/Probe/ProbeMonitorResponse.ts @@ -470,7 +470,7 @@ export default class ProbeMonitorResponseService { data.dataToProcess as ProbeMonitorResponse ).responseTimeInMs; monitorMetricsByMinute.miscData = { - probeId: (data.dataToProcess as ProbeMonitorResponse).probeId, + probeId: (data.dataToProcess as ProbeMonitorResponse).probeId.toString(), }; itemsToSave.push(monitorMetricsByMinute); @@ -486,7 +486,7 @@ export default class ProbeMonitorResponseService { data.dataToProcess as ProbeMonitorResponse ).responseCode; monitorMetricsByMinute.miscData = { - probeId: (data.dataToProcess as ProbeMonitorResponse).probeId, + probeId: (data.dataToProcess as ProbeMonitorResponse).probeId.toString(), }; itemsToSave.push(monitorMetricsByMinute); diff --git a/Dashboard/src/Components/Monitor/MonitorCharts/MonitorChart.tsx b/Dashboard/src/Components/Monitor/MonitorCharts/MonitorChart.tsx index d0e9c0aa42..df55c3e010 100644 --- a/Dashboard/src/Components/Monitor/MonitorCharts/MonitorChart.tsx +++ b/Dashboard/src/Components/Monitor/MonitorCharts/MonitorChart.tsx @@ -9,6 +9,7 @@ import { AxisLeft, AxisType, ChartCurve, + LineChartData, LineChartDataItem, LineChartPoint, XScale, @@ -47,7 +48,7 @@ export class MonitorCharts { public static getDistinctMiscDataFromMonitorMetricsByMinute(data: { monitorMetricsByMinute: Array; checkOn: CheckOn; - }): Array { + }): Array { const miscData: Array = data.monitorMetricsByMinute .filter((item: MonitorMetricsByMinute) => { @@ -69,13 +70,34 @@ export class MonitorCharts { }) === index ); } - ); + ).filter((item: JSONObject | undefined) => { + return !!item; + }) as Array; + } + + public static getChartData(data: { + monitorMetricsByMinute: Array; + checkOn: CheckOn; + miscData: JSONObject | undefined; + }): LineChartData { + + const { monitorMetricsByMinute, checkOn } = data; + + return { + id: `line-${Text.generateRandomNumber()}`, + data: MonitorCharts.getDataForCharts({ + monitorMetricsByMinute, + checkOn: checkOn, + miscData: data.miscData, + }), + } + } public static getChartProps(data: { monitorMetricsByMinute: Array; checkOn: CheckOn; - miscData: JSONObject | undefined; + miscData: Array | undefined; }): Chart { const { monitorMetricsByMinute, checkOn } = data; @@ -85,27 +107,36 @@ export class MonitorCharts { checkOn: checkOn, }); + const chartData: Array = []; + + if(!data.miscData) { + chartData.push(MonitorCharts.getChartData({ + monitorMetricsByMinute, + checkOn, + miscData: undefined, + })); + } + + + for (const miscData of data.miscData || []) { + chartData.push(MonitorCharts.getChartData({ + monitorMetricsByMinute, + checkOn, + miscData: miscData, + })); + } + return { id: `chart-${Text.generateRandomNumber()}`, type: ChartType.LINE, title: MonitorCharts.getChartTitle({ - checkOn: checkOn, - miscData: data.miscData, + checkOn: checkOn }), description: MonitorCharts.getChartDescription({ checkOn: checkOn, }), props: { - data: [ - { - id: `line-${Text.generateRandomNumber()}`, - data: MonitorCharts.getDataForCharts({ - monitorMetricsByMinute, - checkOn: checkOn, - miscData: data.miscData, - }), - }, - ], + data: chartData, xScale: MonitorCharts.getXScaleFor({ monitorMetricsByMinute, }), @@ -146,22 +177,22 @@ export class MonitorCharts { const charts: Array = []; for (const checkOn of checkOns) { - const distinctMiscData: Array = + const distinctMiscData: Array = MonitorCharts.getDistinctMiscDataFromMonitorMetricsByMinute({ monitorMetricsByMinute, checkOn, + }).filter((item: JSONObject | undefined) => { + return !!item; }); if (distinctMiscData.length > 0) { - for (const miscData of distinctMiscData) { - charts.push( - MonitorCharts.getChartProps({ - monitorMetricsByMinute, - checkOn, - miscData, - }) - ); - } + charts.push( + MonitorCharts.getChartProps({ + monitorMetricsByMinute, + checkOn, + miscData: distinctMiscData, + }) + ); } else { charts.push( MonitorCharts.getChartProps({ @@ -208,15 +239,7 @@ export class MonitorCharts { public static getChartTitle(data: { checkOn: CheckOn; - miscData: JSONObject | undefined; }): string { - if (data.checkOn === CheckOn.DiskUsagePercent) { - return ( - 'Disk Usage (in %)' + - (data.miscData ? ` for ${data.miscData['diskPath']}` : '') - ); - } - return data.checkOn; } diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index e9d88364c8..94b8bfafd2 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -222,6 +222,30 @@ services: network: host context: . dockerfile: ./Probe/Dockerfile + + probe-2: + volumes: + - ./Probe:/usr/src/app + # Use node modules of the container and not host system. + # https://stackoverflow.com/questions/29181032/add-a-volume-to-docker-but-exclude-a-sub-folder + - /usr/src/app/node_modules/ + - ./Common:/usr/src/Common + - ./Model:/usr/src/Model + - ./CommonServer:/usr/src/CommonServer + - ./CommonUI:/usr/src/CommonUI + - /usr/src/Common/node_modules/ + - /usr/src/CommonUI/node_modules/ + - /usr/src/CommonServer/node_modules/ + - /usr/src/Model/node_modules/ + extends: + file: ./docker-compose.base.yml + service: probe-2 + ports: + - '9656:9229' # Debugging port. + build: + network: host + context: . + dockerfile: ./Probe/Dockerfile ingestor: volumes: