|
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 | + * 3. ERROR HANDLING STRATEGY |
| 26 | + * Functions follow two patterns based on criticality: |
| 27 | + * |
| 28 | + * PROPAGATING (throws on error): |
| 29 | + * - Core data functions: getPostgresVersion, getSettings, getAlteredSettings, |
| 30 | + * getDatabaseSizes, getInvalidIndexes, getUnusedIndexes, getRedundantIndexes |
| 31 | + * - If these fail, the entire report should fail (data is required) |
| 32 | + * - Callers should handle errors at the report generation level |
| 33 | + * |
| 34 | + * GRACEFUL DEGRADATION (catches errors, includes error in output): |
| 35 | + * - Optional/supplementary queries: pg_stat_statements, pg_stat_kcache checks, |
| 36 | + * memory calculations, postmaster startup time |
| 37 | + * - These are nice-to-have; missing data shouldn't fail the whole report |
| 38 | + * - Errors are logged and included in report output for visibility |
| 39 | + * |
25 | 40 | * ADDING NEW REPORTS |
26 | 41 | * ------------------ |
27 | 42 | * 1. Add/verify the metric exists in config/pgwatch-prometheus/metrics.yml |
@@ -247,8 +262,10 @@ function formatSettingPrettyValue( |
247 | 262 | } |
248 | 263 |
|
249 | 264 | /** |
250 | | - * Get PostgreSQL version information |
251 | | - * Uses simple inline SQL (trivial query, CLI-specific) |
| 265 | + * Get PostgreSQL version information. |
| 266 | + * Uses simple inline SQL (trivial query, CLI-specific). |
| 267 | + * |
| 268 | + * @throws {Error} If database query fails (propagating - critical data) |
252 | 269 | */ |
253 | 270 | export async function getPostgresVersion(client: Client): Promise<PostgresVersion> { |
254 | 271 | const result = await client.query(` |
@@ -967,7 +984,11 @@ export async function generateH004(client: Client, nodeName: string = "node-01") |
967 | 984 | } |
968 | 985 |
|
969 | 986 | /** |
970 | | - * Generate D004 report - pg_stat_statements and pg_stat_kcache settings |
| 987 | + * Generate D004 report - pg_stat_statements and pg_stat_kcache settings. |
| 988 | + * |
| 989 | + * Uses graceful degradation: extension queries are wrapped in try-catch |
| 990 | + * because extensions may not be installed. Errors are included in the |
| 991 | + * report output rather than failing the entire report. |
971 | 992 | */ |
972 | 993 | async function generateD004(client: Client, nodeName: string): Promise<Report> { |
973 | 994 | const report = createBaseReport("D004", "pg_stat_statements and pg_stat_kcache settings", nodeName); |
|
0 commit comments