Skip to content

[ISSUE #8354] Make prometheus client optional in nacos-client SDK#15212

Open
EvanYao826 wants to merge 1 commit into
alibaba:developfrom
EvanYao826:refactor/make-prometheus-optional
Open

[ISSUE #8354] Make prometheus client optional in nacos-client SDK#15212
EvanYao826 wants to merge 1 commit into
alibaba:developfrom
EvanYao826:refactor/make-prometheus-optional

Conversation

@EvanYao826
Copy link
Copy Markdown

What does this PR do?

Fixes #8354: Make the nacos-client SDK lighter by making the prometheus dependency optional.

Problem

nacos-client has a hard dependency on io.prometheus:simpleclient. Users who don't need metrics monitoring still pull in this dependency, which adds to the SDK footprint and can cause version conflicts.

Solution

  1. Mark io.prometheus:simpleclient as <optional>true</optional> in client/pom.xml
  2. Refactor MetricsMonitor to detect prometheus availability at runtime via Class.forName(). When prometheus is not on the classpath, all monitoring operations become no-ops.
  3. Extract prometheus API calls into PrometheusMetricsHelper (only loaded when prometheus is available)
  4. Replace direct Histogram.Child usage in MetricsHttpAgent with a MetricsTimer interface
  5. Update all callers (ClientWorker, ServiceInfoHolder, NamingGrpcClientProxy) to use the new simplified API

Changes

File Change
client/pom.xml Add <optional>true</optional> to prometheus dependency
MetricsMonitor.java Rewrite with runtime prometheus detection and no-op fallback
PrometheusMetricsHelper.java New file: isolates all prometheus direct API calls
MetricsHttpAgent.java Use MetricsTimer instead of direct Histogram.Child
ClientWorker.java Use recordListenConfigCount()
ServiceInfoHolder.java Use recordServiceInfoMapSize()
NamingGrpcClientProxy.java Use recordNamingRequestFailed()

Backward Compatibility

  • Users who already include prometheus in their classpath see no behavior change
  • Users without prometheus get no-op monitoring instead of ClassNotFoundException

Assisted-by: Hermes Agent

@github-actions
Copy link
Copy Markdown

Thanks for your this PR. 🙏
Please check again for your PR changes whether contains any usage/api/configuration change such as Add new API , Add new configuration, Change default value of configuration.
If so, please add or update documents(markdown type) in docs/next/ for repository nacos-group/nacos-group.github.io


感谢您提交的PR。 🙏
请再次查看您的PR内容,确认是否包含任何使用方式/API/配置参数的变更,如:新增API新增配置参数修改默认配置等操作。
如果是,请确保在提交之前,在仓库nacos-group/nacos-group.github.io中的docs/next/目录下添加或更新文档(markdown格式)。

@github-actions
Copy link
Copy Markdown

⚠️ Commit Author Verification Failed

The following commits have author emails not linked to any GitHub account.
This will prevent CLA signing and block your PR from being merged.

Commit Author Email
df384a6 EvanYao826 evanyao826@gmail.com

How to fix:

  1. Add your commit email to your GitHub account: https://github.com/settings/emails
  2. Or update your local git config to use an email already linked to GitHub:
    git config user.name "Your GitHub Username"
    git config user.email "your-github-email@example.com"
    
  3. Amend your commits and force-push:
    git rebase -i HEAD~1 # mark commits as "edit" and amend author
    git push --force-with-lease
    

This check will re-run automatically after you push.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 21, 2026

CLA assistant check
All committers have signed the CLA.

@EvanYao826
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

- Mark io.prometheus:simpleclient as <optional>true</optional>
- Refactor MetricsMonitor with runtime prometheus detection and no-op fallback
- Extract prometheus API calls into PrometheusMetricsHelper
- Replace direct Histogram.Child usage in MetricsHttpAgent with MetricsTimer interface
- Update all callers to use simplified API

Assisted-by: Hermes Agent
@EvanYao826 EvanYao826 force-pushed the refactor/make-prometheus-optional branch from df384a6 to 61ddbc3 Compare May 21, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make nacos-client sdk remove prometheus dependency and metrics with other way.

3 participants