Skip to content

feat: add token comparison queries - #10

Merged
SKTT1Ryze merged 2 commits into
mainfrom
feat/usage-comparison
Oct 23, 2026
Merged

SKTT1Ryze merged 2 commits into
mainfrom
feat/usage-comparison

Conversation

@SKTT1Ryze

@SKTT1Ryze SKTT1Ryze commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Adds a comparison endpoint that aggregates token totals and request counts into client-provided time buckets, grouped by Agent, model, provider, or platform. It supports exact-value filters, including session IDs, and preserves owner scoping in SQLite and PostgreSQL.

Joins, optional filters, grouping, aggregates, and facet queries use typed Diesel expressions and typed result mappings. The only custom SQL syntax is a small QueryFragment extension for a bound VALUES CTE, which Diesel does not provide as a built-in query source. Bucket values remain parameters; the implementation does not load events into application memory for aggregation or issue a query per bucket.

Ranges and bucket continuity are validated, and a comparison dimension cannot also be filtered. Diesel's minimum version is 2.3 for aggregate filters. The endpoint, filter semantics, and CTE boundary are documented.

Validation: formatting and clippy passed for both storage feature sets; PostgreSQL unit tests (85) and SQLite unit tests (91) passed. Both full HTTP/storage black-box suites passed, including microsecond boundaries, totals above 32-bit range, quoted filter values, empty matches, 400 buckets, and DST transitions.

- Add validated bucketed token aggregation with dimension and session filters.
- Implement owner-scoped comparison queries for SQLite and PostgreSQL.
- Document the endpoint and cover its HTTP contract with black-box tests.

Signed-off-by: chunchi.che@lexmount.com

Co-Authored-By: GPT-6 <noreply@openai.com>
@SKTT1Ryze
SKTT1Ryze marked this pull request as ready for review October 23, 2026 08:08
- Use typed Diesel joins, filters, grouping, and facets in PostgreSQL and SQLite.
- Share a bound VALUES CTE extension across both storage backends.
- Remove raw comparison statements, column strings, and JSON-encoded filters.
- Verify microsecond boundaries, large totals, literal filters, DST, and 400 buckets.

Signed-off-by: chunchi.che@lexmount.com

Co-Authored-By: GPT-6 <noreply@openai.com>
@SKTT1Ryze
SKTT1Ryze merged commit 2d02c84 into main Oct 23, 2026
3 checks passed
@SKTT1Ryze
SKTT1Ryze deleted the feat/usage-comparison branch October 23, 2026 08:42
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