Files
Jordi Enric 88ed2aad97 new home: refactor charts to use old sources (#42245)
- refactors new charts in homepage to use stable analytics endpoints
- changes are behind newHomepageUsageV2 flag

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Centralized per-service health metrics hook with per-service data,
loading/error states and refresh.

* **Improvements**
  * Time-series normalization into fixed buckets aligned to an end time.
* Updated UI: success-rate formatting, per-service loading/error
surfaced, refreshed click/refresh behavior; removed delta display.

* **Removals**
  * Legacy project-metrics query and mapping utilities removed.

* **Tests**
* Extensive unit tests added for date ranges, bucket normalization, and
health metric calculations; some obsolete tests removed.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-01-28 17:02:00 +00:00

38 lines
1.2 KiB
TypeScript

export type LogsBarChartDatum = {
timestamp: string
error_count: number
ok_count: number
warning_count: number
}
export const toLogsBarChartData = (
rows: Array<Record<string, unknown>> = []
): LogsBarChartDatum[] => {
return rows.map((r) => ({
timestamp: r.timestamp?.toString() ?? '',
ok_count: Number(r.ok_count) || 0,
warning_count: Number(r.warning_count) || 0,
error_count: Number(r.error_count) || 0,
}))
}
export const sumTotal = (data: LogsBarChartDatum[]): number =>
data.reduce((acc, r) => acc + r.ok_count + r.warning_count + r.error_count, 0)
export const sumWarnings = (data: LogsBarChartDatum[]): number =>
data.reduce((acc, r) => acc + r.warning_count, 0)
export const sumErrors = (data: LogsBarChartDatum[]): number =>
data.reduce((acc, r) => acc + r.error_count, 0)
export const computeSuccessAndNonSuccessRates = (
totalRequests: number,
totalWarnings: number,
totalErrors: number
): { successRate: number; nonSuccessRate: number } => {
if (totalRequests <= 0) return { successRate: 0, nonSuccessRate: 0 }
const nonSuccessRate = ((totalWarnings + totalErrors) / totalRequests) * 100
const successRate = 100 - nonSuccessRate
return { successRate, nonSuccessRate }
}