Skip to content

feat(insights): add cost breakdown by role#2970

Merged
subomi merged 4 commits into
mainfrom
cost-breakdown-by-role
May 21, 2026
Merged

feat(insights): add cost breakdown by role#2970
subomi merged 4 commits into
mainfrom
cost-breakdown-by-role

Conversation

@subomi
Copy link
Copy Markdown
Contributor

@subomi subomi commented May 20, 2026

Summary

  • Adds a group_by=role parameter to the searchUsers telemetry endpoint that aggregates per-user costs by RBAC role
  • Backend fetches per-user costs from ClickHouse, joins with role assignments from Postgres, and returns role-level aggregates (cost, tokens, sessions, user count)
  • Frontend gains an Employee | Role toggle on the "Usage by Employee" table that lazy-loads role data when activated

Test plan

  • Verify Employee view (default) works unchanged
  • Toggle to Role view — confirm roles appear with correct cost/token aggregates
  • Verify "Unassigned" bucket appears for users without role assignments
  • Confirm role names resolve correctly from the existing roles API
  • Test sorting on all role columns (Role, Users, Total Cost, Cost/User, Input Tokens, Output Tokens, Sessions)
  • Verify pagination works in role view
  • Confirm switching between Employee/Role resets sort and page state

🤖 Generated with Claude Code

Add a group_by=role mode to the searchUsers telemetry endpoint so orgs
can view cost aggregated by RBAC role instead of individual employees.
The backend fetches per-user costs from ClickHouse, joins with role
assignments from Postgres, and returns role-level aggregates. The
frontend gains an Employee/Role toggle on the cost table that
lazy-loads role data when activated.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@subomi subomi requested review from a team as code owners May 20, 2026 20:40
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gram-docs-redirect Ready Ready Preview, Comment May 21, 2026 12:24am

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 20, 2026

⚠️ No Changeset found

Latest commit: 5d38442

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

# Conflicts:
#	client/sdk/.speakeasy/gen.lock
#	server/gen/http/openapi3.json
@github-actions github-actions Bot added the preview Spawn a preview environment label May 20, 2026
@speakeasybot
Copy link
Copy Markdown
Collaborator

speakeasybot commented May 20, 2026

🚀 Preview Environment (PR #2970)

Preview URL: https://pr-2970.dev.getgram.ai

Component Status Details Updated (UTC)
✅ Database Ready Existing database reused 2026-05-21 00:28:11.
✅ Images Available Container images ready 2026-05-21 00:27:56.

Gram Preview Bot

…gregation

Fetch ClickHouse per-user costs and Postgres role assignments
concurrently via errgroup. Aggregate directly into the response
type to eliminate an intermediate struct and extra iteration pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
# Conflicts:
#	client/sdk/.speakeasy/gen.lock
#	server/gen/http/openapi3.json
@subomi
Copy link
Copy Markdown
Contributor Author

subomi commented May 21, 2026

@claude review

Copy link
Copy Markdown

@claude claude 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 skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit at claude.ai/admin-settings/claude-code.

Once credits are available, comment @claude review on this pull request to trigger a review.

@claude
Copy link
Copy Markdown

claude Bot commented May 21, 2026

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

1 similar comment
@claude
Copy link
Copy Markdown

claude Bot commented May 21, 2026

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

@subomi subomi added this pull request to the merge queue May 21, 2026
Merged via the queue into main with commit 929a68d May 21, 2026
57 of 59 checks passed
@subomi subomi deleted the cost-breakdown-by-role branch May 21, 2026 00:39
@github-actions github-actions Bot locked and limited conversation to collaborators May 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

preview Spawn a preview environment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants