Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE#11659] Develop config query chain of responsibility. #12892

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

MatthewAden
Copy link
Contributor

it closes #11659

What is the purpose of the change

XXXXX

Brief changelog

XX

Verifying this change

XXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed 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.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. 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.
  • 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 integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

	modified:   config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigController.java
	modified:   config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigServletInner.java
	modified:   config/src/main/java/com/alibaba/nacos/config/server/controller/v2/ConfigControllerV2.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/enums/ApiVersionEnum.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/model/ConfigQueryChainRequest.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/model/ConfigQueryChainResponse.java
	modified:   config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigQueryRequestHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/ConfigQueryChainService.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/ConfigQueryHandlerChain.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/ConfigQueryHandlerChainBuilder.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/DefaultConfigQueryHandlerChainBuilder.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/AbstractConfigQueryHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/ConfigChainEntryHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/ConfigQueryHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/FormalHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/GrayRuleMatchHandler.java

	modified:   config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigController.java
	modified:   config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigServletInner.java
	modified:   config/src/main/java/com/alibaba/nacos/config/server/controller/v2/ConfigControllerV2.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/enums/ApiVersionEnum.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/model/ConfigQueryChainRequest.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/model/ConfigQueryChainResponse.java
	modified:   config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigQueryRequestHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/ConfigQueryChainService.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/ConfigQueryHandlerChain.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/ConfigQueryHandlerChainBuilder.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/DefaultConfigQueryHandlerChainBuilder.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/AbstractConfigQueryHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/ConfigChainEntryHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/ConfigQueryHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/FormalHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/GrayRuleMatchHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/TagNotFoundHandler.java
	new file:   config/src/main/resources/META-INF/services/com.alibaba.nacos.config.server.remote.query.ConfigQueryHandlerChainBuilder
	modified:   config/src/test/java/com/alibaba/nacos/config/server/controller/ConfigServletInnerTest.java
	modified:   config/src/test/java/com/alibaba/nacos/config/server/controller/v2/ConfigControllerV2Test.java
	modified:   config/src/test/java/com/alibaba/nacos/config/server/remote/ConfigQueryRequestHandlerTest.java
Copy link

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格式)。

if (StringUtils.isNotBlank(tag)) {
appLabels.put(TagGrayRule.VIP_SERVER_TAG_LABEL, tag);
} else {
appLabels = new HashMap<>(meta.getAppLabels());
Copy link
Collaborator

Choose a reason for hiding this comment

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

appLabels.putAll(meta.getAppLabels());

public enum ConfigQueryStatus {
BETA,
TAG,
TAG_NOT_FOUND,
Copy link
Collaborator

Choose a reason for hiding this comment

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

beta,tag-> gray

private final ConfigQueryHandlerChain configQueryHandlerChain;

public ConfigQueryChainService() {
Collection<ConfigQueryHandlerChainBuilder> configQueryHandlerChainBuilders =
Copy link
Collaborator

Choose a reason for hiding this comment

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

ConfigQueryHandlerChainBuilder should load multi , but use only one with specific name which's default value is nacos.

configQueryHandlerChain = builder.addHandler(new ConfigChainEntryHandler())
.addHandler(new GrayRuleMatchHandler())
.addHandler(new TagNotFoundHandler())
.addHandler(new FormalHandler())
Copy link
Collaborator

Choose a reason for hiding this comment

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

should be extracted to DefaultConfigQueryHandlerChainBuilder with name of 'nacos.'


private static final String GRAY_RULE_MATCH_HANDLER = "grayRuleMatchHandler";

private ConfigCacheGray matchedGray;
Copy link
Collaborator

@shiyiyue1102 shiyiyue1102 Nov 25, 2024

Choose a reason for hiding this comment

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

not Thread Safe.
Every handler should be stateless.

response.setStatus(ConfigQueryChainResponse.ConfigQueryStatus.BETA);
} else if (TagGrayRule.TYPE_TAG.equals(matchedGray.getGrayRule().getType())) {
response.setStatus(ConfigQueryChainResponse.ConfigQueryStatus.TAG);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

set match gray only, ignore beta& tag

*
* @author Nacos
*/
public class TagNotFoundHandler extends AbstractConfigQueryHandler {
Copy link
Collaborator

Choose a reason for hiding this comment

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

change to SpecificTagConfigQueryHandler

delayed, clientIp, notify, "grpc");

return response;

} catch (Exception e) {
return ConfigQueryResponse.buildFailResponse(ResponseCode.FAIL.getCode(), e.getMessage());
Copy link
Collaborator

Choose a reason for hiding this comment

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

add error log to nacos.log


@Override
public ConfigQueryHandlerChain build() {
return new ConfigQueryHandlerChain(head);
Copy link
Collaborator

Choose a reason for hiding this comment

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

ConfigQueryHandlerChain chain =new ConfigQueryHandlerChain();
chain.addHandler(new ConfigChainEntryHandler())
.addHandler(new GrayRuleMatchHandler())
.addHandler(new TagNotFoundHandler())
.addHandler(new FormalHandler());
return chain;

tail.setNextHandler(handler);
tail = handler;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

move to ConfigQueryHandlerChain#addHandler

* @param handler the handler to be added
* @return the current builder instance
*/
ConfigQueryHandlerChainBuilder addHandler(ConfigQueryHandler handler);
Copy link
Collaborator

Choose a reason for hiding this comment

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

move to ConfigQueryHandlerChain#addHandler


private static final Logger LOGGER = LoggerFactory.getLogger(AbstractConfigQueryHandler.class);

public ConfigQueryHandler nextHandler;
Copy link
Collaborator

Choose a reason for hiding this comment

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

add prevHandler

@wuyfee
Copy link

wuyfee commented Nov 25, 2024

$\color{green}{SUCCESS}$
DETAILS
✅ - docker: success
✅ - deploy (standalone & cluster & standalone_auth): success
✅ - e2e-java-test (standalone & cluster & standalone_auth): success
✅ - e2e-go-test (standalone & cluster): success
✅ - e2e-cpp-test (standalone & cluster): success
✅ - e2e-csharp-test (standalone & cluster): success
✅ - e2e-nodejs-test (standalone & cluster): success
✅ - e2e-python-test (standalone & cluster): success
✅ - clean (standalone & cluster & standalone_auth): success

* @author Nacos
*/
public class ConfigQueryHandlerChain {

Copy link
Collaborator

@shiyiyue1102 shiyiyue1102 Nov 25, 2024

Choose a reason for hiding this comment

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

这些类迁移到service包下,不应该放在remote下

return configQueryHandlerChain.handle(request);
} catch (Exception e) {
LOGGER.error("[Error] Fail to handle ConfigQueryChainRequest", e);
return new ConfigQueryChainResponse();
Copy link
Collaborator

Choose a reason for hiding this comment

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

should return error response with error info

* Gets the name of the handler.
* @return The name of the handler.
*/
String getQueryHandlerName();
Copy link
Collaborator

Choose a reason for hiding this comment

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

change to getName()

* @param meta the request meta
* @return the constructed ConfigQueryChainRequest object
*/
public ConfigQueryChainRequest buildChainRequest(ConfigQueryRequest request, RequestMeta meta) {
Copy link
Collaborator

@shiyiyue1102 shiyiyue1102 Nov 25, 2024

Choose a reason for hiding this comment

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

extract a new spi component which named ConfigQueryChainRequestExtractor, with two method.

ConfigQueryChainRequest extract(HttpServerletRequest request) , ConfigQueryChainRequest extract(ConfigQueryRequest request, RequestMeta requestMeta)

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.

using Chain of Responsibility to refactor ConfigQueryRequestHandler and ConfigServletInner
3 participants