Skip to content

Conversation

@JaneLiuL
Copy link

@JaneLiuL JaneLiuL commented Dec 30, 2025

Ⅰ. Describe what this PR did

fix #3214

Ⅱ. Does this pull request fix one issue?

fix #3214

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

run e2e for verify

Ⅴ. Special notes for reviews

Ⅵ. AI Coding Tool Usage Checklist (if applicable)

no ai coding tools

Please check all applicable items:

  • For new standalone features (e.g., new wasm plugin or golang-filter plugin):
    • I have created a design/ directory in the plugin folder
    • I have added the design document to the design/ directory
    • I have included the AI Coding summary below
      will add design directory later
  • For regular updates/changes (not new plugins):
    • I have provided the prompts/instructions I gave to the AI Coding tool below
    • I have included the AI Coding summary below

AI Coding Prompts (for regular updates)

AI Coding Summary

@CLAassistant
Copy link

CLAassistant commented Dec 30, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ JaneLiuL
❌ undertaker86001


undertaker86001 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@JaneLiuL JaneLiuL changed the title [WIP] init token statistics plugin Jan 12, 2026
normalizedType := strings.TrimSpace(strings.ToLower(model))

// 处理别名(兼容不同命名习惯)
switch normalizedType {
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里的模型名字会这么规范吗?

Copy link
Author

Choose a reason for hiding this comment

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

是需要处理如果model比如用户输入错误的model 要兼容对吗?是否需要加入模糊匹配?

Copy link
Collaborator

Choose a reason for hiding this comment

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

问题是这里能识别准吗?是否有别的办法?

defaultConfigDisable: false
```

### 4.6.3 功能验证
Copy link
Collaborator

Choose a reason for hiding this comment

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

为什么这里是 4.6.3?

Copy link
Author

Choose a reason for hiding this comment

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

本地的一些笔记,写readme的时候不想重复写把本地笔记拷贝了,会更正的

go run ./
```

跟着官网https://higress.cn/zh-cn/blog/e2e-debug/测试插件
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个链接不对


注意:插件在真实运行时依赖 proxy-wasm hostcalls(例如定义/记录指标、获取 HTTP header 等)。直接在本地通过 `go run` 或 `go test` 运行会遇到 hostcall 不可用的问题(��触发 panic)。为方便本地开发,本仓库做了以下改进:

- 在 `main.go` 中,将指标抽象为 `metricCounter` 并提供 `noopCounter`,在非 Wasm 环境下跳过调用真实 hostcalls,避免 panic。
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个地方用测试的 VM 也不行吗?

如有问题,请在仓库中创建 issue,或直接在 PR 中指明你遇到的问题与预期行为。

创建WasmPlugin资源配置:
确保插件执行在 AI-Cache 插件之后(通过priority配置,数值越大执行越晚);
Copy link
Collaborator

Choose a reason for hiding this comment

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

这部分最好放在配置那边,也最好注明推荐的执行阶段和优先级。现在太不显眼了

@@ -0,0 +1,180 @@
# Token Statistics Plugin

该目录实现了 Higress 的 `token-statistics` wasm 插件,用于从各类 AI 服务响应中提取 token 使用量并导出到日志/指标,以便进行成本统计与监控。
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个插件与 ai-statistics 插件的关系是什么呢,是否可以同时使用?

undertaker86001 added 2 commits January 19, 2026 09:54
…ken-statistics

Key improvements:
- Restore full Prometheus metrics verification logic
- Increase retry count from 10 to 15 times (45s total timeout)
- Increase retry interval from 2s to 3s for better stability
- Add detailed error logging and troubleshooting hints
- Implement graceful degradation when Prometheus unavailable
- Restore complete exporter and dimensions configuration

Metrics verified:
- input_tokens_total
- output_tokens_total
- total_tokens_total
- Aggregate queries across all models
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants