Skip to content

Add metrics command#19

Merged
itssimon merged 4 commits into
mainfrom
dev-101-add-metrics-command-to-cli
Apr 13, 2026
Merged

Add metrics command#19
itssimon merged 4 commits into
mainfrom
dev-101-add-metrics-command-to-cli

Conversation

@itssimon

@itssimon itssimon commented Apr 13, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added a metrics command to fetch aggregated per-app metrics with required --since and --metrics, optional --until, --interval, --group-by, --filters, --timezone, and --db to persist results to DuckDB.
    • NDJSON output or DuckDB ingestion with automatic metrics table creation and overlap-safe updates.
  • Documentation

    • Updated CLI reference, README, skill docs, and DuckDB table docs to include metrics usage and schema.
  • Tests

    • Added CLI parsing and ingestion tests for the new command.

@itssimon itssimon self-assigned this Apr 13, 2026
@coderabbitai

coderabbitai Bot commented Apr 13, 2026

Copy link
Copy Markdown

Walkthrough

Adds a new metrics CLI subcommand and a src/metrics.rs module to fetch aggregated app metrics from POST /v1/apps/{app_id}/metrics, output NDJSON or ingest into DuckDB via Arrow, plus documentation and DuckDB schema updates.

Changes

Cohort / File(s) Summary
Documentation & References
README.md, AGENTS.md, skills/apitally-cli/SKILL.md, skills/apitally-cli/references/commands.md, skills/apitally-cli/references/duckdb_tables.md
Added docs for metrics command, parameters (--since, --metrics, --until, --interval, --group-by, --filters, --timezone, --db), updated investigation workflow, and added metrics DuckDB table schema and relationships.
CLI Subcommand Infrastructure
src/main.rs
Added Command::Metrics variant, CLI parsing/tests, routing to metrics::run(...), mod metrics; declaration, and updated sql help text to include metrics table.
Metrics Module Implementation
src/metrics.rs
New module implementing request payload parsing, POST to /v1/apps/{app_id}/metrics, NDJSON streaming output, DuckDB ingestion with ensure_metrics_table(), Arrow IPC staging, overlap-deletion and merge, progress reporting, and unit tests for NDJSON and Arrow ingestion.
Database Utilities
src/reset_db.rs
Call to metrics::ensure_metrics_table(&conn)? added to DB reset sequence and tests updated to expect the metrics table.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add metrics command' accurately and directly describes the main change—adding a new metrics CLI command with full implementation and documentation across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev-101-add-metrics-command-to-cli

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
skills/apitally-cli/SKILL.md (1)

59-144: Add fence languages to the new workflow examples.

The new CLI and SQL snippets are currently untyped, which is what the MD040 warnings are complaining about. Adding bash for command blocks and sql for query blocks will keep the skill docs lint-clean.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@skills/apitally-cli/SKILL.md` around lines 59 - 144, The code fences in
SKILL.md for CLI commands (e.g., the npx `@apitally/cli` examples such as the
endpoints, consumers, metrics, request-logs, request-details commands) and the
SQL examples (the DuckDB queries under "Query DuckDB" and the investigation SQL
blocks) need explicit languages to satisfy MD040; update each backtick-fenced
block so command examples use ```bash and SQL examples use ```sql (search for
snippets containing npx `@apitally/cli` and the SELECT ... FROM request_logs /
metrics queries) to remove the lint warnings.
skills/apitally-cli/references/commands.md (1)

84-144: Add language identifiers to the new metrics fences.

Markdownlint is already flagging these new blocks. Tag the CLI example as bash and the filter/output samples as json so the reference stays lint-clean.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@skills/apitally-cli/references/commands.md` around lines 84 - 144, The
markdown code fences for the `metrics` CLI docs are missing language
identifiers; update the three new fences so the first command block (the npx
`@apitally/cli` metrics example) is tagged as bash, and the two JSON example
blocks (the Filters examples block and the Example NDJSON output block) are
tagged as json—look for the triple-backtick blocks surrounding the npx command,
the filter examples JSON array, and the NDJSON output and add the appropriate
language identifiers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/metrics.rs`:
- Around line 13-31: The DuckDB refresh is too weak because deletion/refresh
logic only keys off app_id and period bounds, allowing mixed rollups to
conflict; add persistent fetch-shape discriminator columns to the metrics table
(e.g., interval, group_by, metric_set or similar column names used in your
ingest path) and change the refresh/delete logic in the refresh routine to
include those discriminator columns when deleting/upserting rows for a staged
load (replace the current app_id + MIN/MAX(period_*) logic). Also ensure the
refresh path (the code that computes staged MIN/MAX(period_start/period_end))
rejects empty staged fetches or falls back to a safe sentinel so NULL MIN/MAX
cannot cause no-op deletions; if you prefer, alternatively make db writes reject
mixed-shape writes by validating the staged fetch-shape against existing stored
discriminator values before deleting/upserting.

---

Nitpick comments:
In `@skills/apitally-cli/references/commands.md`:
- Around line 84-144: The markdown code fences for the `metrics` CLI docs are
missing language identifiers; update the three new fences so the first command
block (the npx `@apitally/cli` metrics example) is tagged as bash, and the two
JSON example blocks (the Filters examples block and the Example NDJSON output
block) are tagged as json—look for the triple-backtick blocks surrounding the
npx command, the filter examples JSON array, and the NDJSON output and add the
appropriate language identifiers.

In `@skills/apitally-cli/SKILL.md`:
- Around line 59-144: The code fences in SKILL.md for CLI commands (e.g., the
npx `@apitally/cli` examples such as the endpoints, consumers, metrics,
request-logs, request-details commands) and the SQL examples (the DuckDB queries
under "Query DuckDB" and the investigation SQL blocks) need explicit languages
to satisfy MD040; update each backtick-fenced block so command examples use
```bash and SQL examples use ```sql (search for snippets containing npx
`@apitally/cli` and the SELECT ... FROM request_logs / metrics queries) to remove
the lint warnings.
🪄 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: CHILL

Plan: Pro

Run ID: ffeba5e0-82f2-4174-b157-bf101a2c8761

📥 Commits

Reviewing files that changed from the base of the PR and between 5c63348 and e108abf.

📒 Files selected for processing (8)
  • AGENTS.md
  • README.md
  • skills/apitally-cli/SKILL.md
  • skills/apitally-cli/references/commands.md
  • skills/apitally-cli/references/duckdb_tables.md
  • src/main.rs
  • src/metrics.rs
  • src/reset_db.rs

Comment thread src/metrics.rs
@sentry

sentry Bot commented Apr 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.69841% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.80%. Comparing base (5c63348) to head (8a12289).

Files with missing lines Patch % Lines
src/main.rs 38.46% 24 Missing ⚠️
src/metrics.rs 96.68% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #19      +/-   ##
==========================================
- Coverage   91.30%   90.80%   -0.51%     
==========================================
  Files          11       12       +1     
  Lines        1565     1817     +252     
==========================================
+ Hits         1429     1650     +221     
- Misses        136      167      +31     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 the current code and only fix it if needed.

Inline comments:
In `@skills/apitally-cli/references/commands.md`:
- Around line 86-90: Add a language tag (e.g., bash) to the fenced code block
that contains the npx `@apitally/cli` metrics usage example so the markdown fence
becomes ```bash ... ```, updating the block that starts with "npx `@apitally/cli`
metrics <app-id> --since <datetime> --metrics <json> \" to include the language
identifier for proper linting and rendering.
- Around line 103-104: Update the "Deduplication in DuckDB" description to
precisely reflect the implemented bounded delete semantics: state that for each
app_id the process deletes existing rows where period_start >= min(period_start)
and period_end <= max(period_end) of the staged (fetched) rows, rather than
saying "within the fetched time range", so readers understand the delete uses
those exact bounds and not arbitrary overlap matching.
🪄 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: CHILL

Plan: Pro

Run ID: e6b375f9-1a5e-4af5-8884-f4515776edda

📥 Commits

Reviewing files that changed from the base of the PR and between e108abf and 324dc26.

📒 Files selected for processing (1)
  • skills/apitally-cli/references/commands.md

Comment thread skills/apitally-cli/references/commands.md
Comment thread skills/apitally-cli/references/commands.md
@itssimon itssimon merged commit 6efbec7 into main Apr 13, 2026
2 checks passed
@itssimon itssimon deleted the dev-101-add-metrics-command-to-cli branch April 13, 2026 12:15
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