|
2 | 2 | * Express Checkup Module |
3 | 3 | * ====================== |
4 | 4 | * Generates JSON health check reports directly from PostgreSQL without Prometheus. |
5 | | - * |
| 5 | + * |
6 | 6 | * ARCHITECTURAL DECISIONS |
7 | 7 | * ----------------------- |
8 | | - * |
| 8 | + * |
9 | 9 | * 1. SINGLE SOURCE OF TRUTH FOR SQL QUERIES |
10 | | - * Complex metrics (index health, settings, db_stats) are loaded from |
| 10 | + * Complex metrics (index health, settings, db_stats) are loaded from |
11 | 11 | * config/pgwatch-prometheus/metrics.yml via getMetricSql() from metrics-loader.ts. |
12 | | - * |
| 12 | + * |
13 | 13 | * Simple queries (version, database list, connection states, uptime) use |
14 | 14 | * inline SQL as they're trivial and CLI-specific. |
15 | | - * |
| 15 | + * |
16 | 16 | * 2. JSON SCHEMA COMPLIANCE |
17 | 17 | * All generated reports MUST comply with JSON schemas in reporter/schemas/. |
18 | 18 | * These schemas define the expected format for both: |
19 | 19 | * - Full-fledged monitoring reporter output |
20 | 20 | * - Express checkup output |
21 | | - * |
| 21 | + * |
22 | 22 | * Before adding or modifying a report, verify the corresponding schema exists |
23 | 23 | * and ensure the output matches. Run schema validation tests to confirm. |
24 | | - * |
| 24 | + * |
25 | 25 | * 3. ERROR HANDLING STRATEGY |
26 | 26 | * Functions follow two patterns based on criticality: |
27 | | - * |
| 27 | + * |
28 | 28 | * PROPAGATING (throws on error): |
29 | 29 | * - Core data functions: getPostgresVersion, getSettings, getAlteredSettings, |
30 | 30 | * getDatabaseSizes, getInvalidIndexes, getUnusedIndexes, getRedundantIndexes |
31 | 31 | * - If these fail, the entire report should fail (data is required) |
32 | 32 | * - Callers should handle errors at the report generation level |
33 | | - * |
| 33 | + * |
34 | 34 | * GRACEFUL DEGRADATION (catches errors, includes error in output): |
35 | 35 | * - Optional/supplementary queries: pg_stat_statements, pg_stat_kcache checks, |
36 | 36 | * memory calculations, postmaster startup time |
37 | 37 | * - These are nice-to-have; missing data shouldn't fail the whole report |
38 | 38 | * - Errors are logged and included in report output for visibility |
39 | | - * |
| 39 | + * |
40 | 40 | * ADDING NEW REPORTS |
41 | 41 | * ------------------ |
42 | 42 | * 1. Add/verify the metric exists in config/pgwatch-prometheus/metrics.yml |
@@ -336,7 +336,7 @@ export function parseVersionNum(versionNum: string): { major: string; minor: str |
336 | 336 | /** |
337 | 337 | * Format bytes to human readable string using binary units (1024-based). |
338 | 338 | * Uses IEC standard: KiB, MiB, GiB, etc. |
339 | | - * |
| 339 | + * |
340 | 340 | * Note: PostgreSQL's pg_size_pretty() uses kB/MB/GB with 1024 base (technically |
341 | 341 | * incorrect SI usage), but we follow IEC binary units per project style guide. |
342 | 342 | */ |
@@ -387,7 +387,7 @@ function formatSettingPrettyValue( |
387 | 387 | /** |
388 | 388 | * Get PostgreSQL version information. |
389 | 389 | * Uses simple inline SQL (trivial query, CLI-specific). |
390 | | - * |
| 390 | + * |
391 | 391 | * @throws {Error} If database query fails (propagating - critical data) |
392 | 392 | */ |
393 | 393 | export async function getPostgresVersion(client: Client): Promise<PostgresVersion> { |
@@ -1084,7 +1084,7 @@ export const generateH004 = (client: Client, nodeName = "node-01") => |
1084 | 1084 |
|
1085 | 1085 | /** |
1086 | 1086 | * Generate D004 report - pg_stat_statements and pg_stat_kcache settings. |
1087 | | - * |
| 1087 | + * |
1088 | 1088 | * Uses graceful degradation: extension queries are wrapped in try-catch |
1089 | 1089 | * because extensions may not be installed. Errors are included in the |
1090 | 1090 | * report output rather than failing the entire report. |
|
0 commit comments