Skip to content

feat: TUI skeleton and a synthetic workload generator#2

Open
mickamy wants to merge 5 commits into
mainfrom
feat/tui-skeleton
Open

feat: TUI skeleton and a synthetic workload generator#2
mickamy wants to merge 5 commits into
mainfrom
feat/tui-skeleton

Conversation

@mickamy
Copy link
Copy Markdown
Owner

@mickamy mickamy commented May 28, 2026

Summary

Adds the bubbletea TUI skeleton on top of the PostgreSQL driver, plus a synthetic workload generator for developing against live data.

Running dbtop <postgres-dsn> now opens a live, polling TUI with three tabs (Activity / Metrics / Statements).

TUI (internal/tui)

  • Elm-style Model / Update / View. DB I/O never runs inside Update: a single tick chain drives polling (Init seeds one poll, each result schedules the next tick), so polls never overlap or pile up.
  • tab switches screens, space pauses (stops the tick chain), q / ctrl+c quits. Bindings live in one keyMap that also feeds the footer, so the hints can't drift from the actual keys.
  • Capabilities are probed at startup. The Statements tab shows a CREATE EXTENSION pg_stat_statements hint instead of erroring when the extension is missing.
  • The frame is assembled as exact lines and each row is clipped to the terminal width, so the tab bar and footer always stay on screen regardless of row count or query length.

CLI wiring (internal/cli)

  • dbtop <dsn> opens the PostgreSQL driver, probes capabilities, and launches the program. A mysql:// DSN reports that the driver is not implemented yet.

Workload generator (cmd/workload, compose, Makefile)

  • A development-only load generator that produces the scenarios dbtop is built to surface: steady OLTP load, an N+1 pattern, occasional long-running queries, and an idle-in-transaction lock holder with a contending writer (blocking).
  • Declared in compose.yaml under the load profile (so plain compose up and CI stay quiet) and reachable via network_mode: service:postgres. postgres now preloads pg_stat_statements and an initdb script creates the extension.
  • make compose-up COMPOSE_PROFILE=load brings the database up with the workload.

Testing

  • Unit tests cover the poll/update/view flow, key routing, the statements degrade path, and the height/width fit (the tab bar must remain the first line; rows must not exceed the width).
  • The workload was verified against a live PostgreSQL: long queries, blocking, and a populated pg_stat_statements digest all appear.

Notes

  • Row selection, the detail pane, cancel/kill, sort, and filter are follow-ups; this lands the loop, navigation-free rendering, and graceful degradation.
  • Line clipping is rune-based for now; it will move to display-width aware truncation when wide glyphs (gutter markers) land.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

❌ Patch coverage is 82.17391% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.17%. Comparing base (3164d69) to head (7025c8d).

Files with missing lines Patch % Lines
internal/cli/cli.go 15.78% 16 Missing ⚠️
internal/tui/view.go 87.73% 7 Missing and 6 partials ⚠️
internal/tui/model.go 85.52% 8 Missing and 3 partials ⚠️
internal/tui/tab.go 92.30% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main       #2       +/-   ##
===========================================
+ Coverage   19.16%   54.17%   +35.01%     
===========================================
  Files          11       15        +4     
  Lines         287      515      +228     
===========================================
+ Hits           55      279      +224     
+ Misses        232      227        -5     
- Partials        0        9        +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements the core live monitor TUI for dbtop, introducing the main loop, tab navigation, and views for Activity, Metrics, and Statements. It also adds a synthetic workload generator to simulate database traffic during development. The review comments identify several critical issues: a compilation error in the workload generator due to a non-existent sync.WaitGroup.Go method, potential duplicate concurrent polling loops when pausing and unpausing the TUI, and unsafe byte-slicing of UTF-8 strings in the query truncation helper.

Comment thread cmd/workload/main.go
Comment thread internal/tui/model.go
Comment thread internal/tui/model.go
Comment thread internal/tui/model.go
Comment thread internal/tui/model.go
Comment thread internal/tui/view.go
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements the initial TUI (Terminal User Interface) for dbtop using the Bubble Tea framework, including screens for Activity, Metrics, and Statements. It also introduces a synthetic workload generator to simulate database traffic for development. The review comments identify three valid issues: a compilation error in the workload generator where sync.WaitGroup is incorrectly called with a .Go() method, a potential panic or garbled character bug in truncate due to direct byte-slicing of UTF-8 strings, and a poor user experience when running the CLI with standard help or version flags.

Comment thread cmd/workload/main.go
Comment thread internal/tui/view.go
Comment thread internal/cli/cli.go
@mickamy
Copy link
Copy Markdown
Owner Author

mickamy commented May 28, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a live monitor TUI using the Bubble Tea framework, along with a synthetic workload generator to simulate database traffic. The reviewer identified a critical compilation error in the workload generator where sync.WaitGroup is incorrectly used with a non-existent .Go() method. Additionally, the reviewer noted a UX lag issue in the TUI where switching tabs does not trigger an immediate database poll, recommending an immediate poll and cancellation of in-flight requests to improve responsiveness.

Comment thread cmd/workload/main.go
Comment thread internal/tui/model.go
Comment on lines +107 to +110
case key.Matches(msg, m.keys.SwitchTab):
m.tab = m.tab.next()

return m, nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

  • Severity: Medium
  • Issue: Switching tabs does not trigger an immediate database poll. Instead, the TUI waits for the in-flight poll of the previous tab to finish, then waits for the tick interval, and only then starts polling the new tab. This can cause a noticeable delay or "lag" when navigating between tabs, especially if the previous poll was slow or the interval is large.
  • Recommendation: Consider triggering an immediate poll upon switching tabs. To prevent concurrent overlapping polls, you can track an active cancellation context for the in-flight poll in the Model and cancel it when switching tabs or unpausing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant