Skip to content

Go CLI: add admin stats commands - #17090

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
JinHai-CN:fix564
Jul 20, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
JinHai-CN:fix564

Conversation

@JinHai-CN

@JinHai-CN JinHai-CN commented Jul 20, 2026 •

Copy link
Copy Markdown
Member

Summary

RAGFlow(admin)> STATS USERS TOP 5 FROM '2026-01-01' TO '2026-02-01';
+-----------------------+----------------------------------------------+------------+---------------------+-----+
| command               | error                                        | from_date  | to_date             | top |
+-----------------------+----------------------------------------------+------------+---------------------+-----+
| get_token_users_stats | 'Get API token users stats' is not supported | 2026-01-01 | 2026-02-01 23:59:59 | 5   |
+-----------------------+----------------------------------------------+------------+---------------------+-----+
RAGFlow(admin)> STATS USER '[email protected]' FROM '2026-01-01' TO '2026-02-01' MONTH;
+-----------------+----------------------------------------+------------+-------------+---------------------+-------------+
| command         | error                                  | from_date  | granularity | to_date             | user_name   |
+-----------------+----------------------------------------+------------+-------------+---------------------+-------------+
| get_token_stats | 'Get API token stats' is not supported | 2026-01-01 | month       | 2026-02-01 23:59:59 | [email protected] |
+-----------------+----------------------------------------+------------+-------------+---------------------+-------------+
RAGFlow(admin)> STATS SUMMARY FROM '2026-01-01' TO '2026-02-01';
+-----------+------------------------------------------------+
| field     | value                                          |
+-----------+------------------------------------------------+
| to_date   | 2026-02-01 23:59:59                            |
| command   | get_token_stats_summary                        |
| error     | 'Get API token stats summary' is not supported |
| from_date | 2026-01-01                                     |
+-----------+------------------------------------------------+

@JinHai-CN
JinHai-CN marked this pull request as ready for review July 20, 2026 05:48
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 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: CHILL

Plan: Pro

Run ID: b3f1052f-88c0-4902-97e6-59f86dc8cf36

📥 Commits

Reviewing files that changed from the base of the PR and between 86ee9d7 and 6e1df77.

📒 Files selected for processing (2)
  • internal/admin/router.go
  • internal/cli/admin_command.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/admin/router.go
  • internal/cli/admin_command.go

📝 Walkthrough

Walkthrough

Adds three authenticated admin token-statistics endpoints, corresponding CLI STATS commands, parser and lexer support, request dispatching, parameter validation, and service responses containing request parameters.

Changes

Token statistics administration

Layer / File(s) Summary
CLI token and command parsing
internal/cli/types.go, internal/cli/lexer.go, internal/cli/parser.go, internal/cli/admin_parser.go
Recognizes STATS, HOUR, DAY, and MONTH, then parses USER, USERS, and SUMMARY command forms with optional date and top parameters.
CLI statistics requests
internal/cli/cli_http.go, internal/cli/admin_command.go
Dispatches parsed commands, validates inputs, builds query strings, and calls the new statistics endpoints.
Admin statistics endpoints
internal/admin/router.go, internal/admin/handler_ee.go
Registers protected routes and adds handlers that parse, normalize, validate, and forward token-statistics query parameters.
Statistics service responses
internal/admin/service_ee.go
Adds service methods returning command payloads, request parameters, and unsupported-operation errors.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant AdminRouter
  participant Handler
  participant Service
  CLI->>AdminRouter: GET /admin/stats/token*
  AdminRouter->>Handler: route token statistics request
  Handler->>Service: invoke statistics method
  Service-->>Handler: return payload or error
  Handler-->>CLI: return success or error response
Loading

Poem

I’m a bunny with stats in my paws,
Parsing commands without any flaws.
Through routes they all hop,
With dates, users, and top,
Then service replies to applause!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding admin stats commands to the Go CLI.
Description check ✅ Passed The description includes the required Summary section and provides useful background plus example command outputs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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.

@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: 1

🤖 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/cli/admin_command.go`:
- Around line 1742-1765: Direct query-string concatenation in the admin stats
CLI commands must be replaced with URL encoding. In
internal/cli/admin_command.go lines 1742-1765, use url.Values or equivalent
encoding for user_name, from, to, and granularity; apply the same change to top,
from, and to at lines 1781-1798, and from and to at lines 1814-1825. Preserve
the existing command behavior while generating correctly encoded query
parameters.
🪄 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: 5db15ee8-87da-4c04-9f96-ba8e20e98b18

📥 Commits

Reviewing files that changed from the base of the PR and between 2e39662 and 86ee9d7.

📒 Files selected for processing (9)
  • internal/admin/handler_ee.go
  • internal/admin/router.go
  • internal/admin/service_ee.go
  • internal/cli/admin_command.go
  • internal/cli/admin_parser.go
  • internal/cli/cli_http.go
  • internal/cli/lexer.go
  • internal/cli/parser.go
  • internal/cli/types.go

Comment thread internal/cli/admin_command.go Resolved
@JinHai-CN JinHai-CN added the ci Continue Integration label Jul 20, 2026
@JinHai-CN
JinHai-CN merged commit 7ad27ad into infiniflow:main Jul 20, 2026
6 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant