Skip to content

Enhanced support for Nacos weight configuration#11498

Open
November22 wants to merge 1 commit intoapache:3.2from
November22:feat/support_nacos_weight
Open

Enhanced support for Nacos weight configuration#11498
November22 wants to merge 1 commit intoapache:3.2from
November22:feat/support_nacos_weight

Conversation

@November22
Copy link
Copy Markdown

What is the purpose of the change

support for Nacos weight configuration #11494

Brief changelog

  1. add method: org.apache.dubbo.registry.nacos.NacosRegistry#setWeight
  2. upadte method: org.apache.dubbo.registry.nacos.NacosRegistry#buildURL

Verifying this change

image

Checklist

  • Make sure there is a GitHub_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GitHub issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Add some description to dubbo-website project if you are requesting to add a feature.
  • GitHub Actions works fine on your own branch.
  • If this contribution is large, please follow the Software Donation Guide.



private void setWeight(Map<String, String> metadata, double nacosWeight) {
long weight = Math.round(org.apache.dubbo.rpc.cluster.Constants.DEFAULT_WEIGHT * nacosWeight);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. skip if nacos weight has not changed
  2. We should consider if weight has been set in instance

Copy link
Copy Markdown
Author

@November22 November22 Feb 7, 2023

Choose a reason for hiding this comment

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

  1. There is no flag to judge whether the weight of Nacos is modified,nacos will pass in the default weight of 1.0
    image
  2. If it is not set in the instance, Nacos sends 1.0 by default, and the calculated result according to the code logic is 100, which is consistent with the default weight of dubbo;
    image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If it is not set in the instance, Nacos sends 1.0 by default, and the calculated result according to the code logic is 100, which is consistent with the default weight of dubbo;

If dubbo has set 200 in url, then set nacos weight as 3, the weight should be 600 as expected.

Copy link
Copy Markdown
Author

@November22 November22 Feb 7, 2023

Choose a reason for hiding this comment

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

If it is not set in the instance, Nacos sends 1.0 by default, and the calculated result according to the code logic is 100, which is consistent with the default weight of dubbo;

If dubbo has set 200 in url, then set nacos weight as 3, the weight should be 600 as expected.

  1. Here, the default weight of dubbo is multiplied by 100, because the weight field type of Nacos is double, so two decimal places can be reserved;
  2. When the instance and Nacos set the weight at the same time, the weight set by Nacos is used first;(There will be no situation where dubbo sets the weight to 200, Nacos sets the weight to 3, and the calculation result is 600)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Math.round(org.apache.dubbo.rpc.cluster.Constants.DEFAULT_WEIGHT * nacosWeight) will override the weight from Dubbo provider

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The changes are as shown in the figure (default rounding for double) image

This is an good idea. But I am afraid that it would not work in ServiceDiscovery model.

I verified it, it works. When registering, set the weight of dubbo to Nacos; the weight issued by Nacos can be set to Dubbo;

image

If different service has different weight, it may conflict.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No, both the reported weight and the issued weight are only related to each instance of the service and will not conflict.
————————
不会的,上报的权重和下发的权重都只会和服务的每个实例相关,并不会冲突。

Copy link
Copy Markdown
Author

@November22 November22 Feb 28, 2023

Choose a reason for hiding this comment

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

For example, for the A interface, I start three instances and set three different weights respectively. The set weights are stored in the org.apache.dubbo.common.URL parameter. When reporting, the weight is obtained from the URL parameter. When sending Obtained from com.alibaba.nacos.api.naming.pojo.Instance#weight
——————
比如A接口,我启动三个实例,分别设置三个不同的权重,设置的权重存储在org.apache.dubbo.common.URL 参数中,上报的时候从URL参数中获取到权重,下发的时候从com.alibaba.nacos.api.naming.pojo.Instance#weight 获取

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Dubbo 的应用级服务发现是把多个服务(接口)聚合为一个应用级的大服务注册到注册中心的,因此如果每个接口权重不一样的话,大服务注册到注册中心的权重就无法确认了

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

明白了,我新加的这个代码应该合并在2.7.x里面

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Feb 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication



private void setWeight(Map<String, String> metadata, double nacosWeight) {
long weight = Math.round(org.apache.dubbo.rpc.cluster.Constants.DEFAULT_WEIGHT * nacosWeight);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Math.round(org.apache.dubbo.rpc.cluster.Constants.DEFAULT_WEIGHT * nacosWeight) will override the weight from Dubbo provider

@lakkr11
Copy link
Copy Markdown

lakkr11 commented Nov 30, 2023

Is the feature still not finished and released?
If I want to modify the weight of different providers in runtime for traffic grayscale, what should I do?

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.

3 participants