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

Refactor ConfigCache and related pathways ,uniformly use UTF-8 encoding for md5 fields #12876

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2a4da2a
Refactor ConfigCache and related pathways ,remove md5GBK to uniformly…
Sunrisea Nov 21, 2024
cec625c
fix test bug
Sunrisea Nov 21, 2024
fc7a15a
fix test bug
Sunrisea Nov 21, 2024
9644edc
optimize the ConfigCacheFactoryDelegate interface, fix test bug
Sunrisea Nov 21, 2024
07da6e3
test bug fix
Sunrisea Nov 21, 2024
0ea6fe0
test bug fix
Sunrisea Nov 21, 2024
392ef61
test bug fix
Sunrisea Nov 21, 2024
b8dea6a
test bug fix
Sunrisea Nov 21, 2024
042db53
test bug fix
Sunrisea Nov 21, 2024
2a0dafa
fix flaky tests (#12885)
DaniellaHubble Nov 22, 2024
3042bf2
log optimize
Sunrisea Nov 25, 2024
4f67995
Update mysql-schema.sql (#12904)
ifrankwang Dec 3, 2024
52c661b
Log in to the console through a browser http://ip:8848/nacos and be r…
littlesparklet Dec 4, 2024
0de3352
Delete the gray version of the console configuration. (#12913)
KiteSoar Dec 4, 2024
5c4bdb4
[ISSUE#11659] Develop config query chain of responsibility. (#12892)
KiteSoar Dec 5, 2024
7651eb3
[ISSUE #12257] client auth plugin support refreshing server list (#12…
misakacoder Dec 5, 2024
66705e3
The error message is not user-friendly when adding duplicate permissi…
zhouchunhai Dec 5, 2024
4961191
The error message is not user-friendly when adding duplicate permissi…
littlesparklet Dec 5, 2024
28548c1
[ISSUE #12342]: Improve the retrieval of ConfigInfoState to facilitat…
gongycn Dec 5, 2024
fce80e3
Refactor ConfigCache and related pathways ,remove md5GBK to uniformly…
Sunrisea Nov 21, 2024
1d73500
fix test bug
Sunrisea Nov 21, 2024
135bf61
fix test bug
Sunrisea Nov 21, 2024
4616dd4
optimize the ConfigCacheFactoryDelegate interface, fix test bug
Sunrisea Nov 21, 2024
16b6a80
test bug fix
Sunrisea Nov 21, 2024
a5c2855
test bug fix
Sunrisea Nov 21, 2024
e6389f9
test bug fix
Sunrisea Nov 21, 2024
9831fa7
test bug fix
Sunrisea Nov 21, 2024
fae642f
test bug fix
Sunrisea Nov 21, 2024
12699ee
log optimize
Sunrisea Nov 25, 2024
96d2c73
Merge remote-tracking branch 'origin/develop-issue#12872' into develo…
Sunrisea Dec 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public ConfigTransportClient(NacosClientProperties properties, ConfigServerListM
this.tenant = properties.getProperty(PropertyKeyConst.NAMESPACE);
this.serverListManager = serverListManager;
this.properties = properties.asProperties();
this.securityProxy = new SecurityProxy(serverListManager.getServerList(),
this.securityProxy = new SecurityProxy(serverListManager,
ConfigHttpClientManager.getInstance().getNacosRestTemplate());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void init(Properties properties) throws NacosException {
InitUtils.initWebRootContext(nacosClientProperties);
serverListManager = new NamingServerListManager(nacosClientProperties, namespace);
serverListManager.start();
securityProxy = new SecurityProxy(serverListManager.getServerList(),
securityProxy = new SecurityProxy(serverListManager,
NamingHttpClientManager.getInstance().getNacosRestTemplate());
initSecurityProxy(properties);
serverProxy = new NamingHttpClientProxy(namespace, securityProxy, serverListManager, nacosClientProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public NamingClientProxyDelegate(String namespace, ServiceInfoHolder serviceInfo
this.serverListManager = new NamingServerListManager(properties, namespace);
this.serverListManager.start();
this.serviceInfoHolder = serviceInfoHolder;
this.securityProxy = new SecurityProxy(this.serverListManager.getServerList(),
this.securityProxy = new SecurityProxy(this.serverListManager,
NamingHttpClientManager.getInstance().getNacosRestTemplate());
initSecurityProxy(properties);
this.httpClientProxy = new NamingHttpClientProxy(namespace, securityProxy, serverListManager, properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@
package com.alibaba.nacos.client.security;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.address.AbstractServerListManager;
import com.alibaba.nacos.client.address.ServerListChangeEvent;
import com.alibaba.nacos.client.auth.impl.NacosAuthLoginConstant;
import com.alibaba.nacos.plugin.auth.spi.client.ClientAuthPluginManager;
import com.alibaba.nacos.plugin.auth.api.LoginIdentityContext;
import com.alibaba.nacos.plugin.auth.spi.client.ClientAuthService;
import com.alibaba.nacos.plugin.auth.api.RequestResource;
import com.alibaba.nacos.common.http.client.NacosRestTemplate;
import com.alibaba.nacos.common.lifecycle.Closeable;
import com.alibaba.nacos.common.notify.Event;
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.common.notify.listener.Subscriber;
import com.alibaba.nacos.plugin.auth.api.LoginIdentityContext;
import com.alibaba.nacos.plugin.auth.api.RequestResource;
import com.alibaba.nacos.plugin.auth.spi.client.ClientAuthPluginManager;
import com.alibaba.nacos.plugin.auth.spi.client.ClientAuthService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

Expand All @@ -45,15 +49,25 @@ public class SecurityProxy implements Closeable {
private ClientAuthPluginManager clientAuthPluginManager;

/**
* Construct from serverList, nacosRestTemplate, init client auth plugin.
* // TODO change server list to serverListManager after serverListManager refactor and unite.
* Construct from serverListManager, nacosRestTemplate, init client auth plugin.
*
* @param serverList a server list that client request to.
* @param serverListManager a server list manager that client request to.
* @Param nacosRestTemplate http request template.
*/
public SecurityProxy(List<String> serverList, NacosRestTemplate nacosRestTemplate) {
public SecurityProxy(AbstractServerListManager serverListManager, NacosRestTemplate nacosRestTemplate) {
clientAuthPluginManager = new ClientAuthPluginManager();
clientAuthPluginManager.init(serverList, nacosRestTemplate);
clientAuthPluginManager.init(serverListManager.getServerList(), nacosRestTemplate);
NotifyCenter.registerSubscriber(new Subscriber<ServerListChangeEvent>() {
@Override
public void onEvent(ServerListChangeEvent event) {
clientAuthPluginManager.refreshServerList(serverListManager.getServerList());
}

@Override
public Class<? extends Event> subscribeType() {
return ServerListChangeEvent.class;
}
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -92,6 +92,7 @@ public void testNewIpSelector() {
@Test
public void testNewMetadataSelector() {
Instance ins1 = new Instance();
ins1.setMetadata(new LinkedHashMap<>());
ins1.addMetadata("a", "1");
ins1.addMetadata("b", "2");
Instance ins2 = new Instance();
Expand All @@ -102,7 +103,7 @@ public void testNewMetadataSelector() {
NamingContext namingContext = mock(NamingContext.class);
when(namingContext.getInstances()).thenReturn(Arrays.asList(ins1, ins2, ins3));

NamingSelector metadataSelector = NamingSelectorFactory.newMetadataSelector(new HashMap() {
NamingSelector metadataSelector = NamingSelectorFactory.newMetadataSelector(new LinkedHashMap() {
{
put("a", "1");
put("b", "2");
Expand All @@ -117,6 +118,7 @@ public void testNewMetadataSelector() {
@Test
public void testNewMetadataSelector2() {
Instance ins1 = new Instance();
ins1.setMetadata(new LinkedHashMap<>());
ins1.addMetadata("a", "1");
ins1.addMetadata("c", "3");
Instance ins2 = new Instance();
Expand All @@ -127,7 +129,7 @@ public void testNewMetadataSelector2() {
NamingContext namingContext = mock(NamingContext.class);
when(namingContext.getInstances()).thenReturn(Arrays.asList(ins1, ins2, ins3));

NamingSelector metadataSelector = NamingSelectorFactory.newMetadataSelector(new HashMap() {
NamingSelector metadataSelector = NamingSelectorFactory.newMetadataSelector(new LinkedHashMap() {
{
put("a", "1");
put("b", "2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.address.AbstractServerListManager;
import com.alibaba.nacos.client.auth.impl.NacosAuthLoginConstant;
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.common.http.HttpRestResult;
import com.alibaba.nacos.common.http.client.NacosRestTemplate;
import com.alibaba.nacos.common.http.param.Header;
Expand Down Expand Up @@ -68,7 +70,34 @@ void setUp() throws Exception {

List<String> serverList = new ArrayList<>();
serverList.add("localhost");
securityProxy = new SecurityProxy(serverList, nacosRestTemplate);
NacosClientProperties properties = NacosClientProperties.PROTOTYPE.derive(new Properties());
AbstractServerListManager serverListManager = new AbstractServerListManager(properties) {
@Override
protected String getModuleName() {
return "Test";
}

@Override
protected NacosRestTemplate getNacosRestTemplate() {
return nacosRestTemplate;
}

@Override
public String genNextServer() {
return serverList.get(0);
}

@Override
public String getCurrentServer() {
return serverList.get(0);
}

@Override
public List<String> getServerList() {
return serverList;
}
};
securityProxy = new SecurityProxy(serverListManager, nacosRestTemplate);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void testIgnoreExpiredEvent() throws InterruptedException {
defaultSharePublisher.addSubscriber(smartSubscriber2, MockSlowEvent2.class);
defaultSharePublisher.publish(mockSlowEvent1);
defaultSharePublisher.publish(mockSlowEvent2);
TimeUnit.MILLISECONDS.sleep(1100);
TimeUnit.MILLISECONDS.sleep(1500);
verify(smartSubscriber1).onEvent(mockSlowEvent1);
verify(smartSubscriber2).onEvent(mockSlowEvent2);
reset(smartSubscriber1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.alibaba.nacos.config.server.filter.CircuitFilter;
import com.alibaba.nacos.config.server.filter.NacosWebFilter;
import com.alibaba.nacos.persistence.configuration.condition.ConditionDistributedEmbedStorage;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
Expand All @@ -34,6 +35,7 @@
public class NacosConfigConfiguration {

@Bean
@ConditionalOnProperty(name = "nacos.web.charset.filter", havingValue = "nacos", matchIfMissing = true)
public FilterRegistrationBean<NacosWebFilter> nacosWebFilterRegistration() {
FilterRegistrationBean<NacosWebFilter> registration = new FilterRegistrationBean<>();
registration.setFilter(nacosWebFilter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.constant.ParametersField;
import com.alibaba.nacos.config.server.controller.parameters.SameNamespaceCloneConfigBean;
import com.alibaba.nacos.config.server.enums.ApiVersionEnum;
import com.alibaba.nacos.config.server.model.ConfigAdvanceInfo;
import com.alibaba.nacos.config.server.model.ConfigAllInfo;
import com.alibaba.nacos.config.server.model.ConfigInfo;
Expand Down Expand Up @@ -244,7 +245,7 @@ public void getConfig(HttpServletRequest request, HttpServletResponse response,

final String clientIp = RequestUtil.getRemoteIp(request);
String isNotify = request.getHeader("notify");
inner.doGetConfig(request, response, dataId, group, tenant, tag, isNotify, clientIp);
inner.doGetConfig(request, response, dataId, group, tenant, tag, isNotify, clientIp, ApiVersionEnum.V1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import java.util.List;
import java.util.Map;

import static com.alibaba.nacos.config.server.constant.Constants.ENCODE_UTF8;
import static com.alibaba.nacos.config.server.utils.LogUtil.PULL_LOG;

/**
Expand Down Expand Up @@ -135,8 +134,6 @@ public String doGetConfig(HttpServletRequest request, HttpServletResponse respon

boolean notify = StringUtils.isNotBlank(isNotify) && Boolean.parseBoolean(isNotify);

String acceptCharset = ENCODE_UTF8;

if (isV2) {
response.setHeader(HttpHeaderConsts.CONTENT_TYPE, MediaType.APPLICATION_JSON);
}
Expand Down Expand Up @@ -187,7 +184,7 @@ public String doGetConfig(HttpServletRequest request, HttpServletResponse respon
String encryptedDataKey;

if (matchedGray != null) {
md5 = matchedGray.getMd5(acceptCharset);
md5 = matchedGray.getMd5();
lastModified = matchedGray.getLastModifiedTs();
encryptedDataKey = matchedGray.getEncryptedDataKey();
content = ConfigDiskServiceFactory.getInstance()
Expand All @@ -211,7 +208,7 @@ public String doGetConfig(HttpServletRequest request, HttpServletResponse respon
response.setHeader(com.alibaba.nacos.api.common.Constants.VIPSERVER_TAG,
URLEncoder.encode(tag, StandardCharsets.UTF_8.displayName()));
} else {
md5 = cacheItem.getConfigCache().getMd5(acceptCharset);
md5 = cacheItem.getConfigCache().getMd5();
lastModified = cacheItem.getConfigCache().getLastModifiedTs();
encryptedDataKey = cacheItem.getConfigCache().getEncryptedDataKey();
content = ConfigDiskServiceFactory.getInstance().getContent(dataId, group, tenant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.controller.ConfigServletInner;
import com.alibaba.nacos.config.server.enums.ApiVersionEnum;
import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.config.server.model.ConfigRequestInfo;
import com.alibaba.nacos.config.server.paramcheck.ConfigBlurSearchHttpParamExtractor;
Expand Down Expand Up @@ -105,7 +106,7 @@ public void getConfig(HttpServletRequest request, HttpServletResponse response,
ParamUtils.checkParamV2(tag);
final String clientIp = RequestUtil.getRemoteIp(request);
String isNotify = request.getHeader("notify");
inner.doGetConfig(request, response, dataId, group, namespaceId, tag, isNotify, clientIp, true);
inner.doGetConfig(request, response, dataId, group, namespaceId, tag, isNotify, clientIp, ApiVersionEnum.V2);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 1999-$toady.year Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.config.server.enums;

/**
* Config Api Version enum.
* @author Nacos
*/
public enum ApiVersionEnum {

/**
* API version v1.
*/
V1("v1"),

/**
* API version v2.
*/
V2("v2");

private final String version;

ApiVersionEnum(String version) {
this.version = version;
}

public String getVersion() {
return version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CacheItem {

public String type;

ConfigCache configCache = new ConfigCache();
ConfigCache configCache = ConfigCacheFactoryDelegate.getInstance().createConfigCache();

/**
* Use for gray.
Expand Down Expand Up @@ -92,7 +92,7 @@ public void initConfigGrayIfEmpty() {
public void initConfigGrayIfEmpty(String grayName) {
initConfigGrayIfEmpty();
if (!this.configCacheGray.containsKey(grayName)) {
this.configCacheGray.put(grayName, new ConfigCacheGray(grayName));
this.configCacheGray.put(grayName, ConfigCacheFactoryDelegate.getInstance().createConfigCacheGray(grayName));
}
}

Expand Down
Loading
Loading