Skip to content

feat: 增加 WebUI 配置选项禁用匿名使用统计#7946

Open
Blueteemo wants to merge 3 commits intoAstrBotDevs:masterfrom
Blueteemo:feat/issue-7941-disable-metrics-config
Open

feat: 增加 WebUI 配置选项禁用匿名使用统计#7946
Blueteemo wants to merge 3 commits intoAstrBotDevs:masterfrom
Blueteemo:feat/issue-7941-disable-metrics-config

Conversation

@Blueteemo
Copy link
Copy Markdown
Contributor

@Blueteemo Blueteemo commented May 1, 2026

问题描述

Metric 模块当前只能通过环境变量 ASTRBOT_DISABLE_METRICS 控制,用户需要在 WebUI 中添加配置选项。

修复方案

  1. 在 default.py 添加 disable_metrics 配置项
  2. 在 metrics.py 添加 _is_disabled() 方法检查配置
  3. 在 config-metadata.json 添加中英俄翻译

关联 Issue

Fixes #7941

Summary by Sourcery

Add a configurable option to disable anonymous metrics collection via the WebUI and centralize the metrics-disable check.

New Features:

  • Introduce a disable_metrics configuration flag exposed in the WebUI to control anonymous usage statistics upload.

Enhancements:

  • Refactor metrics disabling logic into a shared helper that respects both environment variables and configuration options.
  • Update i18n config metadata to include labels and descriptions for the new disable_metrics setting in Chinese and English.

@auto-assign auto-assign Bot requested review from advent259141 and anka-afk May 1, 2026 13:05
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend area:webui The bug / feature is about webui(dashboard) of astrbot. labels May 1, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The Metric._disable_metrics class attribute is never written to anywhere, so it’s effectively dead code; consider removing it or adding a clear public setter/use-site if you intend it to be configurable at runtime.
  • In _is_disabled(), you’re catching a broad Exception around the config import and access; narrowing this to the specific expected exceptions (e.g. ImportError / AttributeError / KeyError) would avoid hiding unrelated runtime errors.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `Metric._disable_metrics` class attribute is never written to anywhere, so it’s effectively dead code; consider removing it or adding a clear public setter/use-site if you intend it to be configurable at runtime.
- In `_is_disabled()`, you’re catching a broad `Exception` around the config import and access; narrowing this to the specific expected exceptions (e.g. `ImportError` / `AttributeError` / `KeyError`) would avoid hiding unrelated runtime errors.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist 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

This pull request introduces a feature to disable anonymous usage statistics via a new configuration option and environment variable. The changes include updates to the default configuration, the metrics utility logic, and localization files for the dashboard. A review comment suggests optimizing the logic for checking the disabled status and using more specific exception handling to improve code robustness and readability.

Comment thread astrbot/core/utils/metrics.py
@Blueteemo
Copy link
Copy Markdown
Contributor Author

@sourcery-ai review

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend area:webui The bug / feature is about webui(dashboard) of astrbot. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]在 WebUI 增加配置 Metric 选项

1 participant