Skip to content

chore(demo): add synthetic data seeder - #440

Merged
SantiagoDePolonia merged 3 commits into
mainfrom
chore/demo-data-seeder
Jun 29, 2026
Merged

SantiagoDePolonia merged 3 commits into
mainfrom
chore/demo-data-seeder

Conversation

@SantiagoDePolonia

@SantiagoDePolonia SantiagoDePolonia commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add a make seed-demo-data target backed by a rolling SQLite demo data seeder
  • generate realistic usage, audit logs, budgets, cache telemetry, user paths, and endpoint-specific request/response bodies
  • tolerate nullable audit error_type values in SQLite and PostgreSQL readers

Testing

  • bash -n tools/seed-demo-data.sh
  • go test -count=1 ./internal/auditlog/...
  • pre-commit: make test-race, go mod tidy, dashboard JavaScript unit tests, hot-path performance guard, make lint

Summary by CodeRabbit

  • New Features

    • Added a seed-demo-data command to populate a SQLite database with sample usage traffic, audit logs, and budget data.
    • Supports configurable date ranges, request volume, cache/prompt-cache behavior, and outputs a dataset summary when complete.
  • Bug Fixes

    • Improved audit log handling when error_type is missing/NULL so the returned ErrorType stays empty.
    • Added/updated coverage to verify the same NULL behavior in both PostgreSQL and SQLite log readers.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b1df1087-29f5-4e81-b2c6-3cb52b2fec6c

📥 Commits

Reviewing files that changed from the base of the PR and between 3d63dad and 165a557.

📒 Files selected for processing (3)
  • internal/auditlog/reader_postgresql.go
  • internal/auditlog/reader_postgresql_test.go
  • tools/seed-demo-data.sh

📝 Walkthrough

Walkthrough

Adds a seed-demo-data Makefile target and Bash script that seeds SQLite demo data, while updating PostgreSQL and SQLite audit log readers and tests so error_type remains empty when the column is NULL.

Changes

NULL error_type fix in audit log readers

Layer / File(s) Summary
PostgreSQL NULL error_type handling
internal/auditlog/reader_postgresql.go, internal/auditlog/reader_postgresql_test.go
PostgreSQLReader uses a queryer interface, scans error_type into nullable locals in both read paths, and tests cover NULL error_type through the reader and scan helper.
SQLite NULL error_type handling
internal/auditlog/reader_sqlite.go, internal/auditlog/store_sqlite_test.go
GetLogs and scanSQLiteLogEntry scan error_type into sql.NullString, and SQLite tests assert NULL error_type stays empty on returned log entries.

Demo data seeding script

Layer / File(s) Summary
Makefile target
Makefile
seed-demo-data is added to .PHONY, and its recipe invokes tools/seed-demo-data.sh with Bash.
Script config and setup
tools/seed-demo-data.sh
The script defines defaults and help text, validates inputs, checks for sqlite3, creates tables and indexes, starts a transaction, and clears prior seeded rows for the chosen prefix.
Usage and audit log generation
tools/seed-demo-data.sh
The script builds temporary generation tables, inserts synthetic usage rows, and writes matching audit log rows with cache logic and template-specific JSON payloads.
Budget writes and reporting
tools/seed-demo-data.sh
The script upserts budgets and budget settings, commits the transaction, runs reporting queries, and prints the final seed message.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I hop through seeds from dusk to dawn,
NULLs stay blank where logs were drawn.
Bash turns soil, and Makefile sings,
Budgets bloom with little springs.
A carrot trail of demo cheer,
Helps test the paths from far to near.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the new synthetic demo data seeder, which is one of the primary changes in the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/demo-data-seeder

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5

The seeder can overwrite existing budget configuration in a reused SQLite demo database and should be fixed before relying on it around shared budget keys.

The changed audit reader behavior is covered, and the remaining concern is localized to the new demo seeding path where existing budget rows can be clobbered.

tools/seed-demo-data.sh

T-Rex T-Rex Logs

What T-Rex did

  • Ran a generated SQLite harness that preinserted a non-demo /engineering monthly budget, seed-demo-data.sh, and queried the same budget row before and after to confirm the overwrite.
  • Tried to seed demo data with make seed-demo-data; the initial run did not have the required target, and a later head run completed with exit code 0 and a summarized view of usage, audit, budget, and related rows.
  • Ran focused tests for NULL handling; the before state showed errors in SQLite and PostgreSQL scans, and the head run completed with exit code 0 for the focused tests.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (2): Last reviewed commit: "test(audit): cover nullable postgres err..." | Re-trigger Greptile

Comment thread tools/seed-demo-data.sh Outdated
@codecov-commenter

codecov-commenter commented Jun 29, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 50.00000% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/auditlog/reader_postgresql.go 25.00% 2 Missing and 4 partials ⚠️
internal/auditlog/reader_sqlite.go 75.00% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tools/seed-demo-data.sh`:
- Around line 382-392: The demo cost calculation in the seed script treats local
response cache hits as if they still paid full provider output costs, which
conflicts with the intended cache-savings story. Update the cost logic around
the SELECT that computes input_cost, output_cost, and total_cost so the
cache_type IS NOT NULL branch zeros out output_cost and excludes it from
total_cost, while leaving prompt_cache_hit behavior unchanged. Use the existing
cache_type and prompt_cache_hit conditions in this cost block to distinguish
local cache hits from provider prompt-cache hits.
- Around line 86-88: The sqlite3 seeding block is missing a fail-fast setting,
so errors can still allow the script to proceed toward COMMIT and leave partial
data behind. Update the sqlite3 heredoc in the seed-demo-data shell script to
enable .bail on before any transactional work, keeping the rest of the seed flow
intact and using the existing sqlite3 invocation/PRAGMA block as the insertion
point.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4e19e876-0d57-4b8b-8597-beb2ee4f7626

📥 Commits

Reviewing files that changed from the base of the PR and between 236c2f0 and 2111be7.

📒 Files selected for processing (4)
  • Makefile
  • internal/auditlog/reader_postgresql.go
  • internal/auditlog/reader_sqlite.go
  • tools/seed-demo-data.sh

Comment thread tools/seed-demo-data.sh
Comment thread tools/seed-demo-data.sh

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/auditlog/reader_postgresql_test.go`:
- Around line 56-97: The current test only covers scanPostgreSQLLogEntry, but
the NULL handling change also affects the GetLogs row iteration path in
reader_postgresql.go. Add or extend a test around GetLogs that returns a row
with error_type set to NULL and verifies the resulting log entry keeps ErrorType
empty, using the existing scanPostgreSQLLogEntry/GetLogs symbols to locate the
behavior. Ensure the new test exercises the production path end-to-end rather
than only the row scanner helper.

In `@tools/seed-demo-data.sh`:
- Line 684: The cache classification in the `cache_mix` query is treating
zero-valued cache counters as cached because `json_extract(...) IS NOT NULL`
only checks presence, not whether tokens were actually used. Update the `SELECT`
logic in `tools/seed-demo-data.sh` to use a positive-token predicate for
`prompt_cached_tokens`, `cached_tokens`, and `cache_read_input_tokens` so only
rows with values greater than zero are classified as `prompt-cache`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e26b43a8-a1d5-41c8-aa9b-2735602864ed

📥 Commits

Reviewing files that changed from the base of the PR and between 2111be7 and 3d63dad.

📒 Files selected for processing (3)
  • internal/auditlog/reader_postgresql_test.go
  • internal/auditlog/store_sqlite_test.go
  • tools/seed-demo-data.sh

Comment thread internal/auditlog/reader_postgresql_test.go Outdated
Comment thread tools/seed-demo-data.sh Outdated
@SantiagoDePolonia
SantiagoDePolonia merged commit 77ca8e5 into main Jun 29, 2026
20 checks passed
Comment thread tools/seed-demo-data.sh
Comment on lines +657 to +661
ON CONFLICT(user_path, period_seconds) DO UPDATE SET
amount = excluded.amount,
source = excluded.source,
last_reset_at = excluded.last_reset_at,
updated_at = excluded.updated_at;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Preserve existing budgets
The budget upsert rewrites any existing budget for these shared user_path/period_seconds keys, not just rows from the requested seed prefix. If a SQLite demo database already has a real /engineering monthly budget, rerunning the seeder changes its amount, source, and reset timestamp to ${prefix}, so the advertised prefix-scoped replacement clobbers non-demo budget configuration.

Artifacts

Repro: generated SQLite harness that creates the conflicting budget row and runs the seeder

  • Contains supporting evidence from the run (text/x-shellscript; charset=utf-8).

Repro: command transcript with before and after SQLite query output showing the budget row was overwritten

  • Keeps the command output available without making the summary code-heavy.

View artifacts

T-Rex Ran code and verified through T-Rex

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.

2 participants