Skip to content

Commit ad7ab4c

Browse files
Adman23Desvelao
andauthored
Fix miscalculation on healthcheck tasks (#1366)
* Apply fix Signed-off-by: Adam Navarro Megías <adam.navarro@wazuh.com> * Change format on healthcheck tab to be consistent Signed-off-by: Adam Navarro Megías <adam.navarro@wazuh.com> * small fix Signed-off-by: Adam Navarro Megías <adam.navarro@wazuh.com> * Update task.ts Signed-off-by: Adam Navarro Megías <145340543+Adman23@users.noreply.github.com> * chore(changelog): add entry --------- Signed-off-by: Adam Navarro Megías <adam.navarro@wazuh.com> Signed-off-by: Adam Navarro Megías <145340543+Adman23@users.noreply.github.com> Co-authored-by: Antonio <34042064+Desvelao@users.noreply.github.com> Co-authored-by: Antonio David Gutiérrez <antonio.gutierrez@wazuh.com>
1 parent ca5ef8d commit ad7ab4c

6 files changed

Lines changed: 32 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ All notable changes to the Wazuh app project will be documented in this file.
77
### Added
88

99
- Support for Wazuh 5.0.0
10-
- Health check service [#811](https://github.com/wazuh/wazuh-dashboard/pull/811) [#866](https://github.com/wazuh/wazuh-dashboard/pull/866) [#961](https://github.com/wazuh/wazuh-dashboard/pull/961) [#1031](https://github.com/wazuh/wazuh-dashboard/pull/1031) [#1179](https://github.com/wazuh/wazuh-dashboard/pull/1179)
11-
- Added Health Check plugin [#870](https://github.com/wazuh/wazuh-dashboard/pull/870) [#946](https://github.com/wazuh/wazuh-dashboard/pull/946)
10+
- Health check service [#811](https://github.com/wazuh/wazuh-dashboard/pull/811) [#866](https://github.com/wazuh/wazuh-dashboard/pull/866) [#961](https://github.com/wazuh/wazuh-dashboard/pull/961) [#1031](https://github.com/wazuh/wazuh-dashboard/pull/1031) [#1179](https://github.com/wazuh/wazuh-dashboard/pull/1179) [#1366](https://github.com/wazuh/wazuh-dashboard/pull/1366)
11+
- Added Health Check app [#870](https://github.com/wazuh/wazuh-dashboard/pull/870) [#946](https://github.com/wazuh/wazuh-dashboard/pull/946) [#1366](https://github.com/wazuh/wazuh-dashboard/pull/1366)
1212
- Added manager host configuration for the default configuration file [#998](https://github.com/wazuh/wazuh-dashboard/pull/998)
1313
- Set v9 theme as default [#1092](https://github.com/wazuh/wazuh-dashboard/pull/1092)
1414

src/core/common/healthcheck/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface TaskInfo {
1212
createdAt: string | null;
1313
startedAt: string | null;
1414
finishedAt: string | null;
15-
duration: number | null; // seconds
15+
duration: number | null; // milliseconds
1616
data: any;
1717
error: string | null;
1818
enabled: boolean;

src/core/server/healthcheck/healthcheck/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ interface InitializationTaskRunData {
167167
createdAt: string | null;
168168
startedAt: string | null;
169169
finishedAt: string | null;
170-
duration: number | null; // seconds
170+
duration: number | null; // milliseconds
171171
data: any;
172172
error: string | null;
173173
enabled: boolean;
@@ -270,7 +270,7 @@ The UI allows exporting the checks to a JSON file to be shared easily.
270270
"createdAt": "2025-08-08T10:04:59.428Z",
271271
"startedAt": "2025-08-08T10:19:59.858Z",
272272
"finishedAt": "2025-08-08T10:19:59.948Z",
273-
"duration": 0.09,
273+
"duration": 90,
274274
"error": null,
275275
"enabled": true,
276276
"critical": true,
@@ -294,7 +294,7 @@ The UI allows exporting the checks to a JSON file to be shared easily.
294294
"createdAt": "2025-08-08T10:04:59.428Z",
295295
"startedAt": "2025-08-08T10:19:59.858Z",
296296
"finishedAt": "2025-08-08T10:19:59.948Z",
297-
"duration": 0.09,
297+
"duration": 90,
298298
"error": null,
299299
"enabled": true,
300300
"critical": true,

src/core/server/healthcheck/healthcheck/dashboard_server_is_not_ready_yet/client/script.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ function formatDateTime(value) {
433433
}
434434

435435
/**
436+
* !This function is duplicated on src/plugins/healthcheck/public/components/table/check_flyout.tsx
436437
* Format duration in milliseconds to a compact human string
437438
* @param {number | undefined} ms
438439
*/
@@ -673,7 +674,7 @@ class Components {
673674
* @returns
674675
*/
675676
static checkCriticalItem(task) {
676-
const created = formatDateTime(task.createdAt);
677+
const created = formatDateTime(task.startedAt);
677678
const finished = formatDateTime(task.finishedAt);
678679
const duration = formatDuration(task.duration);
679680
return /* html */ `
@@ -715,7 +716,7 @@ class Components {
715716
return /* html */ `
716717
<div class="noncritical-list" role="list">
717718
${$map(tasks, (task) => {
718-
const created = formatDateTime(task.createdAt);
719+
const created = formatDateTime(task.startedAt);
719720
const finished = formatDateTime(task.finishedAt);
720721
const duration = formatDuration(task.duration);
721722
return /* html */ `

src/core/server/healthcheck/task/task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class Task implements ITask {
6565
const dateStartedAt = new Date(this.startedAt as string);
6666
const dateFinishedAt = new Date(this.finishedAt);
6767

68-
this.duration = ((dateFinishedAt.getTime() - dateStartedAt.getTime()) as number) / 1000;
68+
this.duration = (dateFinishedAt.getTime() - dateStartedAt.getTime()) as number;
6969
}
7070

7171
if (error) {

src/plugins/healthcheck/public/components/table/check_flyout.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ import { TaskInfo } from '../../../../../core/common/healthcheck';
2222
import { mapTaskStatusToHealthColor } from '../services/health';
2323
import { BadgeResults } from '../utils/badge_results';
2424

25+
/**
26+
* !This function is duplicated on src/core/server/healthcheck/healthcheck/dashboard_server_is_not_ready_yet/client/script.js
27+
* Format duration in milliseconds to a compact human string
28+
* @param {number | undefined} ms
29+
*/
30+
function formatDuration(ms: number) {
31+
if (ms == null || isNaN(ms)) return '';
32+
const totalMs = Math.max(0, Math.floor(ms));
33+
const s = Math.floor(totalMs / 1000);
34+
const msR = totalMs % 1000;
35+
const h = Math.floor(s / 3600);
36+
const m = Math.floor((s % 3600) / 60);
37+
const sec = s % 60;
38+
const parts = [];
39+
if (h) parts.push(`${h}h`);
40+
if (m) parts.push(`${m}m`);
41+
if (sec || (!h && !m)) parts.push(`${sec}s`);
42+
if (!h && !m && msR) parts.push(`${msR}ms`);
43+
return parts.join(' ');
44+
}
45+
2546
interface CheckFlyoutProps {
2647
check: TaskInfo;
2748
formatDate: (date: string) => string;
@@ -171,7 +192,7 @@ export const CheckFlyout = ({ check, formatDate, setIsFlyoutVisible }: CheckFlyo
171192
/>
172193
</EuiDescriptionListTitle>
173194
<EuiDescriptionListDescription>
174-
<p>{duration ? `${duration}s` : '-'}</p>
195+
<p>{duration ? `${formatDuration(duration)}` : '-'}</p>
175196
</EuiDescriptionListDescription>
176197
</EuiDescriptionList>
177198
</EuiFlexItem>

0 commit comments

Comments
 (0)