Skip to content

Refactor: derive D004, F001, G001 reports from A003 settings data#12

Closed
NikolayS wants to merge 4 commits into
mainfrom
claude/find-a003-based-reports-DBMWi
Closed

Refactor: derive D004, F001, G001 reports from A003 settings data#12
NikolayS wants to merge 4 commits into
mainfrom
claude/find-a003-based-reports-DBMWi

Conversation

@NikolayS
Copy link
Copy Markdown
Contributor

@NikolayS NikolayS commented Dec 24, 2025

Summary

  • Refactored D004, F001, and G001 reports to derive their settings data from A003 instead of making separate queries
  • Added markdown output support for all reports via --format CLI option
  • Each derived report now includes PostgreSQL version info from A003

Changes

New architecture

A003.json (all settings with PG version)
├── D004.json (pg_stat_statements settings) → D004.md
├── F001.json (autovacuum settings) → F001.md
└── G001.json (memory settings + analysis) → G001.md

New methods

  • filter_a003_settings() - Filters A003 data for specific settings
  • extract_postgres_version_from_a003() - Extracts PG version from A003
  • generate_d004_from_a003() - Generate D004 from A003 data
  • generate_f001_from_a003() - Generate F001 from A003 data
  • generate_g001_from_a003() - Generate G001 from A003 data
  • report_to_markdown() - Converts any report to markdown format

CLI enhancement

New --format option: json (default), markdown, or both

Test plan

  • All 35 unit tests pass
  • All 14 schema validation tests pass
  • Manual testing with live Prometheus instance

Note

Implements direct, SQL-based health checks and streamlines reporter generation using A003 settings.

  • New cli/lib/checkup.ts: SQL helpers and generators for A002, A003, A004, A007, A013 (includes parseVersionNum, formatBytes, get* helpers, generateAllReports).
  • CLI: adds postgres-ai checkup in cli/bin/postgres-ai.ts to run checks against a connection, with --check-id, --node-name, --output, --json; prints summaries or writes *.json files.
  • Reporter: D004, F001, G001 now derived from A003 via filter_a003_settings() and include PG version from A003; fallback to direct generation if A003 missing.
  • Reporter CLI: new --format (json/markdown/both), generates *.json and/or *.md; enhanced multi-node combine flow; updated file naming and upload behavior.
  • New/updated tests: cli/test/checkup.test.cjs for helpers/SQL/generators/CLI help; reporter unit tests updated to cover A003-derived builders.

Written by Cursor Bugbot for commit 8fb51de. Configure here.

- Add D004_SETTINGS, F001_SETTINGS, G001_SETTINGS constants for filtering
- Add generate_d004_from_a003, generate_f001_from_a003, generate_g001_from_a003 methods
- Add filter_a003_settings and extract_postgres_version_from_a003 helpers
- Add report_to_markdown method with report-specific markdown generators
- Add --format option to CLI (json/markdown/both)
- Update generate_all_reports to use A003 data for derived reports
- Update tests to reflect new architecture
Instead of relying only on postgres_version field, now also extracts
version info from server_version and server_version_num settings
which are part of the A003 data itself.
Add comprehensive tests for the checkup module including:
- parseVersionNum function with various PG versions
- createBaseReport structure validation
- CHECK_INFO and REPORT_GENERATORS constants
- Mock client tests for getPostgresVersion, getSettings
- Report generators (A002, A003, A013)
- CLI help output and error handling
…checkup

Add two new reports to the express checkup command:
- A004: Cluster information (database sizes, connection stats, cache hit ratio)
- A007: Altered settings (non-default PostgreSQL settings)

New SQL queries added:
- alteredSettings: filters pg_settings for non-default values
- databaseSizes: queries pg_database for size info
- clusterStats: aggregates pg_stat_database metrics
- connectionStates: groups pg_stat_activity by state
- uptimeInfo: gets server start time and uptime

Also adds comprehensive unit tests for all new functionality.
@NikolayS
Copy link
Copy Markdown
Contributor Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on January 16

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

for setting_name, setting_info in data.items():
if setting_name in setting_names:
filtered[setting_name] = setting_info
return filtered
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Settings filter merges all nodes instead of specific node

The filter_a003_settings method iterates over ALL nodes in the A003 report and merges their settings into a single dictionary, ignoring which specific node is being processed. When multiple nodes have the same setting with different values, the last node's value overwrites previous ones. This is inconsistent with extract_postgres_version_from_a003, which correctly accepts and filters by node_name. In multi-node scenarios, all derived reports (D004, F001, G001) will have identical merged settings data instead of node-specific settings, despite being called once per node.

Additional Locations (2)

Fix in Cursor Fix in Web

if args.format in ('markdown', 'both'):
with open(md_filename, 'w') as f:
f.write(generator.report_to_markdown(report))
print(f"Markdown report written to {md_filename}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unreachable code after exception re-raise

The sys.exit(1) statement on line 3215 is unreachable dead code. The preceding raise e statement immediately re-raises the exception and exits the except block, so sys.exit(1) will never execute. This means the script will crash with a full traceback instead of the intended clean exit with exit code 1. Either the raise e or the sys.exit(1) is extraneous depending on intended behavior.

Fix in Cursor Fix in Web

@NikolayS NikolayS closed this Jan 2, 2026
@NikolayS NikolayS deleted the claude/find-a003-based-reports-DBMWi branch January 2, 2026 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants