|
| 1 | +<script lang="ts"> |
| 2 | + import type { PageData } from "./$types"; |
| 3 | + import MissingRoleAlert from "$lib/components/MissingRoleAlert.svelte"; |
| 4 | + import { |
| 5 | + Activity, |
| 6 | + Archive, |
| 7 | + CheckCircle2, |
| 8 | + AlertTriangle, |
| 9 | + XCircle, |
| 10 | + Settings, |
| 11 | + } from "@lucide/svelte"; |
| 12 | +
|
| 13 | + let { data }: { data: PageData } = $props(); |
| 14 | +
|
| 15 | + const diagnostics = $derived(data.diagnostics); |
| 16 | + const config = $derived(diagnostics?.config); |
| 17 | + const metric = $derived(diagnostics?.metric); |
| 18 | + const metricArchive = $derived(diagnostics?.metric_archive); |
| 19 | + const checks = $derived(diagnostics?.checks ?? []); |
| 20 | + const everythingAsExpected = $derived( |
| 21 | + diagnostics?.everything_as_expected ?? false, |
| 22 | + ); |
| 23 | +
|
| 24 | + function formatDate(value: string | null | undefined): string { |
| 25 | + if (!value) return "—"; |
| 26 | + const d = new Date(value); |
| 27 | + if (isNaN(d.getTime())) return String(value); |
| 28 | + return d.toLocaleString(); |
| 29 | + } |
| 30 | +
|
| 31 | + function formatCount(value: number | null | undefined): string { |
| 32 | + if (value === null || value === undefined) return "—"; |
| 33 | + return value.toLocaleString(); |
| 34 | + } |
| 35 | +
|
| 36 | + function formatAge(days: number | null | undefined): string { |
| 37 | + if (days === null || days === undefined) return "—"; |
| 38 | + return `${days.toLocaleString()} day${days === 1 ? "" : "s"}`; |
| 39 | + } |
| 40 | +
|
| 41 | + function checkBadgeColor(status: string): string { |
| 42 | + if (status === "OK") |
| 43 | + return "bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400"; |
| 44 | + if (status === "WARNING") |
| 45 | + return "bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400"; |
| 46 | + return "bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400"; |
| 47 | + } |
| 48 | +</script> |
| 49 | + |
| 50 | +<svelte:head> |
| 51 | + <title>Metrics Diagnostics - API Manager</title> |
| 52 | +</svelte:head> |
| 53 | + |
| 54 | +<div class="container mx-auto px-4 py-8" data-testid="metrics-diagnostics-page"> |
| 55 | + <!-- Header --> |
| 56 | + <div class="mb-6"> |
| 57 | + <h1 class="text-3xl font-bold text-gray-900 dark:text-gray-100"> |
| 58 | + Metrics Diagnostics |
| 59 | + </h1> |
| 60 | + <p class="mt-1 text-gray-600 dark:text-gray-400"> |
| 61 | + State of the <code class="font-mono">metric</code> and |
| 62 | + <code class="font-mono">metricarchive</code> tables, the archiving |
| 63 | + configuration, and integrity checks for the metrics archive scheduler. |
| 64 | + </p> |
| 65 | + </div> |
| 66 | + |
| 67 | + {#if !data.hasRole} |
| 68 | + <MissingRoleAlert |
| 69 | + roles={["CanGetMetricsDiagnostics"]} |
| 70 | + message="You need this role to view metrics diagnostics" |
| 71 | + /> |
| 72 | + {:else if diagnostics} |
| 73 | + <!-- Overall Status --> |
| 74 | + <div |
| 75 | + class="mb-6 rounded-lg border p-4 {everythingAsExpected |
| 76 | + ? 'border-green-200 bg-green-50 dark:border-green-800 dark:bg-green-900/20' |
| 77 | + : 'border-red-200 bg-red-50 dark:border-red-800 dark:bg-red-900/20'}" |
| 78 | + data-testid="overall-status" |
| 79 | + data-state={everythingAsExpected ? "ok" : "attention"} |
| 80 | + > |
| 81 | + <div class="flex items-center gap-3"> |
| 82 | + {#if everythingAsExpected} |
| 83 | + <CheckCircle2 class="h-6 w-6 text-green-600 dark:text-green-400" /> |
| 84 | + <p class="text-base font-semibold text-green-800 dark:text-green-200"> |
| 85 | + Everything as expected |
| 86 | + </p> |
| 87 | + {:else} |
| 88 | + <AlertTriangle class="h-6 w-6 text-red-600 dark:text-red-400" /> |
| 89 | + <p class="text-base font-semibold text-red-800 dark:text-red-200"> |
| 90 | + Some checks need attention |
| 91 | + </p> |
| 92 | + {/if} |
| 93 | + </div> |
| 94 | + </div> |
| 95 | + |
| 96 | + <!-- Table Stats --> |
| 97 | + <div class="mb-6 grid grid-cols-1 gap-4 lg:grid-cols-2"> |
| 98 | + {#each [{ title: "Metric Table", icon: Activity, stats: metric, color: "text-blue-500" }, { title: "Metric Archive Table", icon: Archive, stats: metricArchive, color: "text-purple-500" }] as card (card.title)} |
| 99 | + <div |
| 100 | + class="rounded-lg border border-gray-200 bg-white p-6 shadow-sm dark:border-gray-700 dark:bg-gray-800" |
| 101 | + data-testid="table-stats" |
| 102 | + data-table={card.stats?.table_name} |
| 103 | + > |
| 104 | + <div class="mb-4 flex items-center justify-between"> |
| 105 | + <div class="flex items-center gap-2"> |
| 106 | + <card.icon class="h-5 w-5 {card.color}" /> |
| 107 | + <h2 class="text-lg font-semibold text-gray-900 dark:text-gray-100"> |
| 108 | + {card.title} |
| 109 | + </h2> |
| 110 | + </div> |
| 111 | + <code |
| 112 | + class="rounded bg-gray-100 px-2 py-1 text-xs font-mono text-gray-700 dark:bg-gray-900 dark:text-gray-300" |
| 113 | + > |
| 114 | + {card.stats?.table_name ?? "—"} |
| 115 | + </code> |
| 116 | + </div> |
| 117 | + |
| 118 | + <div class="mb-4"> |
| 119 | + <p class="text-sm font-medium text-gray-600 dark:text-gray-400"> |
| 120 | + Row Count |
| 121 | + </p> |
| 122 | + <p |
| 123 | + class="mt-1 text-3xl font-bold text-gray-900 dark:text-gray-100" |
| 124 | + data-testid="row-count" |
| 125 | + > |
| 126 | + {formatCount(card.stats?.count)} |
| 127 | + </p> |
| 128 | + </div> |
| 129 | + |
| 130 | + <div class="grid grid-cols-2 gap-4 rounded-lg bg-gray-50 p-4 dark:bg-gray-900/50"> |
| 131 | + <div> |
| 132 | + <p class="text-sm font-medium text-gray-600 dark:text-gray-400"> |
| 133 | + Oldest Record |
| 134 | + </p> |
| 135 | + <p class="mt-1 text-sm text-gray-900 dark:text-gray-100"> |
| 136 | + {formatDate(card.stats?.oldest_record_date)} |
| 137 | + </p> |
| 138 | + <p class="text-xs text-gray-500 dark:text-gray-400"> |
| 139 | + {formatAge(card.stats?.oldest_record_age_days)} old |
| 140 | + </p> |
| 141 | + </div> |
| 142 | + <div> |
| 143 | + <p class="text-sm font-medium text-gray-600 dark:text-gray-400"> |
| 144 | + Newest Record |
| 145 | + </p> |
| 146 | + <p class="mt-1 text-sm text-gray-900 dark:text-gray-100"> |
| 147 | + {formatDate(card.stats?.newest_record_date)} |
| 148 | + </p> |
| 149 | + <p class="text-xs text-gray-500 dark:text-gray-400"> |
| 150 | + {formatAge(card.stats?.newest_record_age_days)} old |
| 151 | + </p> |
| 152 | + </div> |
| 153 | + </div> |
| 154 | + </div> |
| 155 | + {/each} |
| 156 | + </div> |
| 157 | + |
| 158 | + <!-- Archiving Configuration --> |
| 159 | + <div |
| 160 | + class="mb-6 rounded-lg border border-gray-200 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800" |
| 161 | + > |
| 162 | + <div class="flex items-center gap-2 border-b border-gray-200 p-6 dark:border-gray-700"> |
| 163 | + <Settings class="h-5 w-5 text-gray-500" /> |
| 164 | + <h2 class="text-lg font-semibold text-gray-900 dark:text-gray-100"> |
| 165 | + Archiving Configuration |
| 166 | + </h2> |
| 167 | + </div> |
| 168 | + <div class="grid grid-cols-1 gap-px overflow-hidden rounded-b-lg bg-gray-200 dark:bg-gray-700 sm:grid-cols-2 lg:grid-cols-3"> |
| 169 | + {#each [{ key: "write_metrics", label: "Write Metrics", value: config?.write_metrics }, { key: "enable_metrics_scheduler", label: "Scheduler Enabled", value: config?.enable_metrics_scheduler }, { key: "retain_metrics_move_limit", label: "Move Batch Limit", value: config?.retain_metrics_move_limit }, { key: "retain_metrics_days", label: "Retain Metrics (days)", value: config?.retain_metrics_days, effective: config?.retain_metrics_days_effective }, { key: "retain_archive_metrics_days", label: "Retain Archive (days)", value: config?.retain_archive_metrics_days, effective: config?.retain_archive_metrics_days_effective }] as item (item.key)} |
| 170 | + <div class="bg-white p-4 dark:bg-gray-800" data-testid="config-item" data-config-key={item.key}> |
| 171 | + <p class="text-sm font-medium text-gray-600 dark:text-gray-400"> |
| 172 | + {item.label} |
| 173 | + </p> |
| 174 | + <p class="mt-1 text-lg font-semibold text-gray-900 dark:text-gray-100"> |
| 175 | + {#if typeof item.value === "boolean"} |
| 176 | + {item.value ? "Yes" : "No"} |
| 177 | + {:else} |
| 178 | + {item.value ?? "—"} |
| 179 | + {/if} |
| 180 | + </p> |
| 181 | + {#if item.effective !== undefined && item.effective !== item.value} |
| 182 | + <p class="text-xs text-gray-500 dark:text-gray-400"> |
| 183 | + effective: {item.effective} |
| 184 | + </p> |
| 185 | + {/if} |
| 186 | + </div> |
| 187 | + {/each} |
| 188 | + </div> |
| 189 | + </div> |
| 190 | + |
| 191 | + <!-- Integrity Checks --> |
| 192 | + <div |
| 193 | + class="mb-6 rounded-lg border border-gray-200 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800" |
| 194 | + > |
| 195 | + <div class="border-b border-gray-200 p-6 dark:border-gray-700"> |
| 196 | + <h2 class="text-lg font-semibold text-gray-900 dark:text-gray-100"> |
| 197 | + Integrity Checks ({checks.length}) |
| 198 | + </h2> |
| 199 | + </div> |
| 200 | + <ul class="divide-y divide-gray-200 dark:divide-gray-700"> |
| 201 | + {#each checks as check (check.name)} |
| 202 | + <li class="flex items-start gap-3 p-4" data-testid="integrity-check" data-check={check.name} data-status={check.status}> |
| 203 | + <div class="mt-0.5"> |
| 204 | + {#if check.status === "OK"} |
| 205 | + <CheckCircle2 class="h-5 w-5 text-green-600 dark:text-green-400" /> |
| 206 | + {:else if check.status === "WARNING"} |
| 207 | + <AlertTriangle class="h-5 w-5 text-yellow-600 dark:text-yellow-400" /> |
| 208 | + {:else} |
| 209 | + <XCircle class="h-5 w-5 text-red-600 dark:text-red-400" /> |
| 210 | + {/if} |
| 211 | + </div> |
| 212 | + <div class="flex-1"> |
| 213 | + <div class="flex items-center gap-2"> |
| 214 | + <code class="text-sm font-mono font-semibold text-gray-900 dark:text-gray-100"> |
| 215 | + {check.name} |
| 216 | + </code> |
| 217 | + <span class="rounded-full px-2.5 py-0.5 text-xs font-medium {checkBadgeColor(check.status)}"> |
| 218 | + {check.status} |
| 219 | + </span> |
| 220 | + </div> |
| 221 | + <p class="mt-1 text-sm text-gray-600 dark:text-gray-400"> |
| 222 | + {check.message} |
| 223 | + </p> |
| 224 | + </div> |
| 225 | + </li> |
| 226 | + {/each} |
| 227 | + </ul> |
| 228 | + </div> |
| 229 | + |
| 230 | + <!-- Raw Data --> |
| 231 | + <div |
| 232 | + class="rounded-lg border border-gray-200 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800" |
| 233 | + > |
| 234 | + <div class="border-b border-gray-200 p-6 dark:border-gray-700"> |
| 235 | + <h2 class="text-lg font-semibold text-gray-900 dark:text-gray-100"> |
| 236 | + Raw Diagnostics Data |
| 237 | + </h2> |
| 238 | + </div> |
| 239 | + <div class="p-6"> |
| 240 | + <div class="overflow-auto max-h-[600px]"> |
| 241 | + <pre class="whitespace-pre-wrap break-words rounded-lg bg-gray-50 p-4 text-xs dark:bg-gray-900"><code |
| 242 | + class="text-gray-900 dark:text-gray-100">{JSON.stringify(diagnostics, null, 2)}</code></pre> |
| 243 | + </div> |
| 244 | + </div> |
| 245 | + </div> |
| 246 | + {/if} |
| 247 | +</div> |
0 commit comments