feat(usage): attribute Sources rows to user accounts in admin view#9935
Merged
Conversation
The merged feature (#9920) let admins see per-API-key and per-source totals but did not surface which user owned each key, and lumped every user's Web UI traffic into a single global Web UI row. This makes the admin Sources tab properly per-user attributable: - KeyTotal gains UserID + UserName, populated from the snapshot the usage middleware already records. The by_key roll-up now groups by (api_key_id, api_key_name, user_id, user_name). - New SourceTotals.ByUserSource roll-up groups (source, user_id, user_name) for sources without a key identity (web, legacy). Only populated on the admin path (includeLegacy=true); the non-admin endpoint stays unchanged for backwards compatibility. - SourcesTable accepts showUserColumn={isAdmin}; admin view renders a User column, makes the search match user name/id, and expands Web UI / legacy pseudo-rows from the global aggregate to one row per user using by_user_source. Refs: #9862 Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #9920.
Problem
Admin Sources tab in #9920 shows per-API-key and per-source totals, but:
Even though every
UsageRecordcarriesuser_id/user_name, theby_keyroll-up dropped those fields, andby_sourceonly groupedby source class.
Change
Backend (
core/http/auth/usage.go):KeyTotalgainsUserID+UserName.by_keynow groups by(api_key_id, api_key_name, user_id, user_name).SourceTotals.ByUserSource []UserSourceTotalroll-up groups(source, user_id, user_name)for sources without a key identity(web, legacy). Populated only on the admin path
(
includeLegacy=true); the non-admin endpoint stays unchanged forbackwards compatibility.
Frontend (
SourcesTable.jsx):showUserColumnprop (admin-only). Renders aUsercolumn,extends search to match user name/id, and expands the Web UI /
Legacy pseudo-rows from one global row to one row per user using
by_user_source.i18n: adds
usage.sources.sortUser = "User".Test plan
ginkgo -tags auth ./core/http/auth/- 150/150 pass (3 new specs)go test -tags auth ./core/http/middleware/...- cleanginkgo -tags auth ./core/http/routes/- 63/63 passgo vet -tags auth ./core/http/...- cleannpm run buildincore/http/react-ui/- clean