Spring Cloud Gray 接入及部署记录

小技巧

  • 如果灰度实例不生效,可尝试将Gray Status先置为CLOSE,再置为OPEN
  • 如果HttpTrack不起作用,可尝试重新配置提交

数据库编码

ALTER DATABASE gray_service CHARACTER SET utf8 COLLATE utf8_general_ci;

数据库字段长度

ALTER TABLE `gray_service` CHANGE `service_id` `service_id` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
ALTER TABLE `user_service_authority` CHANGE `service_id` `service_id` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;
ALTER TABLE `gray_track` CHANGE `service_id` `service_id` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;
ALTER TABLE `gray_instance` CHANGE `instance_id` `instance_id` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
ALTER TABLE `gray_instance` CHANGE `service_id` `service_id` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;
ALTER TABLE `route_policy_record` CHANGE `resource` `resource` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;
ALTER TABLE `gray_event_log` CHANGE `source_id` `source_id` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;

端口开放

gray-server的端口需要对所有gray-client及管理前端开发

一直报记录下ip

一直报:记录下ip:192.168.10.88,其中192.168.10.88是注册中心的IP
解决:删除traceIP
分析:traceIP不用在每个服务添加。一般只需要在流量入口添加即可,比如网关,会全链路传递下去(可添加HttpReceive)。在每个服务添加traceIP,反而会覆盖掉用户的ip

2020-10-15 09:15:05.015 [cn-appblog-provider-test][ DEBUG] [5108] [nio-8862-exec-9] [5185f3bd86d5af0b] [5185f3bd86d5af0b] [false] --- [cn.springcloud.gray.web.tracker.HttpIPGrayInfoTracker] [call] [18] : 记录下ip:192.168.10.88
2020-10-15 09:16:05.075 [cn-appblog-provider-test][ DEBUG] [5108] [nio-8862-exec-9] [7c99bf7eb98b6d62] [7c99bf7eb98b6d62] [false] --- [cn.springcloud.gray.web.tracker.HttpIPGrayInfoTracker] [call] [18] : 记录下ip:192.168.10.88

LongPollingWorker监听错误

发生场景:gray-server重启或宕机

注意日志级别是ERROR

2020-10-21 18:09:06.938 [cn-appblog-provider-test][ ERROR] [116537] [ling-1-thread-1] [] [] [] --- [cn.springcloud.gray.client.plugin.event.longpolling.LongPollingWorker] [listenEvents] [78] : 监听失败1次
java.lang.RuntimeException: java.net.ConnectException: Connection refused
    at cn.springcloud.gray.routing.connectionpoint.RoutingConnectionPoint.executeOrMock(RoutingConnectionPoint.java:41)
    at cn.springcloud.gray.client.netflix.resttemplate.GrayClientHttpRequestIntercptor.intercept(GrayClientHttpRequestIntercptor.java:64)
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92)
    at brave.spring.web.TracingClientHttpRequestInterceptor.intercept(TracingClientHttpRequestInterceptor.java:53)
    at org.springframework.cloud.sleuth.instrument.web.client.LazyTracingClientHttpRequestInterceptor.intercept(TraceWebClientAutoConfiguration.java:306)
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92)
    at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:76)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:691)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:589)
    at cn.springcloud.gray.communication.http.RestTemplateAgent.request(RestTemplateAgent.java:57)
    at cn.springcloud.gray.client.plugin.event.longpolling.GrayEventRemoteClient.request(GrayEventRemoteClient.java:106)
    at cn.springcloud.gray.client.plugin.event.longpolling.GrayEventRemoteClient.listeningNewestStatus(GrayEventRemoteClient.java:68)
    at cn.springcloud.gray.client.plugin.event.longpolling.LongPollingWorker.listening(LongPollingWorker.java:115)
    at cn.springcloud.gray.client.plugin.event.longpolling.LongPollingWorker.listenEvents(LongPollingWorker.java:76)
    at cn.springcloud.gray.client.plugin.event.longpolling.LongPollingWorker$$Lambda$752/494951073.run(Unknown Source)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
2020-10-14 13:59:06.492 [cn-appblog-provider-test][ ERROR] [103347] [ling-1-thread-1] [] [] [] --- [cn.springcloud.gray.client.plugin.event.longpolling.LongPollingWorker] [listenEvents] [78] : 监听失败1次
org.springframework.web.client.HttpClientErrorException$BadRequest: 400 null
    at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:79)
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:122)
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:102)
    at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
    at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:778)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:736)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:691)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:589)
    at cn.springcloud.gray.communication.http.RestTemplateAgent.request(RestTemplateAgent.java:57)
    at cn.springcloud.gray.client.plugin.event.longpolling.GrayEventRemoteClient.request(GrayEventRemoteClient.java:106)
    at cn.springcloud.gray.client.plugin.event.longpolling.GrayEventRemoteClient.listeningNewestStatus(GrayEventRemoteClient.java:68)
    at cn.springcloud.gray.client.plugin.event.longpolling.LongPollingWorker.listening(LongPollingWorker.java:115)
    at cn.springcloud.gray.client.plugin.event.longpolling.LongPollingWorker.listenEvents(LongPollingWorker.java:76)
    at cn.springcloud.gray.client.plugin.event.longpolling.LongPollingWorker$$Lambda$752/1286771084.run(Unknown Source)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

gray-server连接超时

访问超时:如端口未开放等原因

2020-10-22 09:21:38.071 [cn-appblog-provider-test][ ERROR] [19265] [           main] [] [] [] --- [cn.springcloud.gray.communication.HttpInformationClient] [requestData] [139] : 获取所有灰度信息失败:java.net.ConnectException: Connection timed out (Connection timed out)
java.lang.RuntimeException: java.net.ConnectException: Connection timed out (Connection timed out)
    at cn.springcloud.gray.routing.connectionpoint.RoutingConnectionPoint.executeOrMock(RoutingConnectionPoint.java:41)
    at cn.springcloud.gray.client.netflix.resttemplate.GrayClientHttpRequestIntercptor.intercept(GrayClientHttpRequestIntercptor.java:64)
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92)
    at brave.spring.web.TracingClientHttpRequestInterceptor.intercept(TracingClientHttpRequestInterceptor.java:53)
    at org.springframework.cloud.sleuth.instrument.web.client.LazyTracingClientHttpRequestInterceptor.intercept(TraceWebClientAutoConfiguration.java:306)
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92)
    at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:76)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:691)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:589)
    at cn.springcloud.gray.communication.http.RestTemplateAgent.request(RestTemplateAgent.java:57)
    at cn.springcloud.gray.communication.HttpInformationClient.request(HttpInformationClient.java:118)
    at cn.springcloud.gray.communication.HttpInformationClient.requestData(HttpInformationClient.java:132)
    at cn.springcloud.gray.communication.HttpInformationClient.allInfos(HttpInformationClient.java:48)
    at cn.springcloud.gray.communication.InformationClientDecorator$3.execute(InformationClientDecorator.java:70)
    at cn.springcloud.gray.communication.InformationClientDecorator$3.execute(InformationClientDecorator.java:67)
    at cn.springcloud.gray.communication.RetryableInformationClient.execute(RetryableInformationClient.java:30)
    at cn.springcloud.gray.communication.InformationClientDecorator.allInfos(InformationClientDecorator.java:67)
    at cn.springcloud.gray.refresh.GrayInformationRefresher.load(GrayInformationRefresher.java:62)
    at cn.springcloud.gray.refresh.GrayInformationRefresher.refresh(GrayInformationRefresher.java:57)
    at cn.springcloud.gray.refresh.SimpleRefreshDriver.refresh(SimpleRefreshDriver.java:21)
    at cn.springcloud.gray.client.initialize.DefaultGrayInfosInitializer.doUpdate(DefaultGrayInfosInitializer.java:113)
    at cn.springcloud.gray.client.initialize.DefaultGrayInfosInitializer.openForWork(DefaultGrayInfosInitializer.java:71)
    at cn.springcloud.gray.client.initialize.DefaultGrayInfosInitializer.scheduleOpenForWork(DefaultGrayInfosInitializer.java:63)
    at cn.springcloud.gray.client.initialize.DefaultGrayInfosInitializer.setup(DefaultGrayInfosInitializer.java:47)
    at cn.springcloud.gray.client.initialize.GrayClientApplicationRunner.initializeGrayInfos(GrayClientApplicationRunner.java:60)
    at cn.springcloud.gray.client.initialize.GrayClientApplicationRunner.run(GrayClientApplicationRunner.java:52)
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:804)
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:794)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:324)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
    at com.lianlian.global.thai.gateway.sdk.GatewaySdkApplication.main(GatewaySdkApplication.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.net.ConnectException: Connection timed out (Connection timed out)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)

actuator心跳访问路径未被授权

[cn.springcloud.gray.server.configuration.OAuth2Config] [commence] [163] : path:/actuator -> Full authentication is required to access this resource

(1)修改:cn.springcloud.gray.server.configuration.OAuth2ConfigpermitPathPatterns加入/actuator/**
(2)spring-cloud-gray-serverspring-cloud-starter-gray-server重新mvn installmvn deploy

@ConditionalOnProperty(value = "gray.server.security.oauth2.enabled", matchIfMissing = true)
@Configuration
public class OAuth2Config {

    ...

    @Configuration
    @EnableResourceServer
    public static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {

        public String[] permitPathPatterns = {
                "/**.html", "/**.js", "/**.css", "/**.png",
                "/swagger-resources/**", "/v2/api-docs", "/webjars/**",
                "/gray/user/login", "/gray/user/login", "/gray/instances/enable",
                "/gray/instances", "/gray/trackDefinitions", "/gray/v1/**", "/gray/v2/**",
                "/server/synch/accept", "/actuator/**"
        };

        @Autowired
        private TokenStore tokenStore;

        @Override
        public void configure(HttpSecurity http) throws Exception {
            http.formLogin().and()
                    .authorizeRequests()
//                    .antMatchers("/gray/user/login").permitAll()
//                    .antMatchers("/gray/user/login").permitAll()
//                    .antMatchers("/gray/instances/enable").permitAll()
//                    .antMatchers("/gray/instances").permitAll()
//                    .antMatchers("/gray/trackDefinitions").permitAll()
//                    .antMatchers("/gray/v1/**", "/gray/v2/**").permitAll()
                    .antMatchers(permitPathPatterns).permitAll()

                    .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
//                    .antMatchers("/gray/service/**").authenticated()
//                    .antMatchers("/gray/policy/**").authenticated()
//                    .antMatchers("/gray/decision/**").authenticated()
//                    .antMatchers("/gray/discover/**").authenticated()
//                    .antMatchers("/gray/track/**").authenticated()
//                    .antMatchers("/route/**").authenticated()
                    .anyRequest().authenticated()
                    .and()
                    .csrf().disable();
        }

    ....

Zipkin调用链报错

(1)修改:cn.springcloud.gray.client.netflix.ribbon.GrayChooserRule.chooseWARN日志级别改为DEBUG
(2)spring-cloud-gray-clientspring-cloud-starter-gray-client重新mvn installmvn deploy

2020-10-14 10:59:32.206 [cn-appblog-provider-test][ DEBUG ] [86752] [ender@60d8c0dc}] [] [] [] --- [cn.springcloud.gray.choose.DefaultServerChooser] [chooseServer] [57] : serviceId: null
2020-10-14 10:59:32.208 [cn-appblog-provider-test][ WARN  ] [86752] [ender@60d8c0dc}] [] [] [] --- [cn.springcloud.gray.client.netflix.ribbon.GrayChooserRule] [choose] [32] : gray choose server occur exception:null, execute super method.
java.lang.NullPointerException: null
    at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
    at cn.springcloud.gray.SimpleGrayManager.getGrayService(SimpleGrayManager.java:52)
    at cn.springcloud.gray.GrayManager.hasServiceGray(GrayManager.java:37)
    at cn.springcloud.gray.DefaultGrayManager.hasServiceGray(DefaultGrayManager.java:22)
    at cn.springcloud.gray.choose.DefaultServerChooser.chooseServer(DefaultServerChooser.java:60)
    at cn.springcloud.gray.client.netflix.ribbon.GrayChooserRule.choose(GrayChooserRule.java:23)
    at com.netflix.loadbalancer.BaseLoadBalancer.chooseServer(BaseLoadBalancer.java:755)
    at com.netflix.loadbalancer.ZoneAwareLoadBalancer.chooseServer(ZoneAwareLoadBalancer.java:113)
    at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.getServer(RibbonLoadBalancerClient.java:189)
    at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.choose(RibbonLoadBalancerClient.java:88)
    at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.choose(RibbonLoadBalancerClient.java:78)
    at org.springframework.cloud.sleuth.zipkin2.sender.LoadBalancerClientZipkinLoadBalancer.instance(LoadBalancerClientZipkinLoadBalancer.java:43)
    at org.springframework.cloud.sleuth.zipkin2.sender.ZipkinRestTemplateSenderConfiguration$1.zipkinUrl(ZipkinRestTemplateSenderConfiguration.java:69)
    at org.springframework.cloud.sleuth.zipkin2.sender.ZipkinRestTemplateWrapper.doExecute(ZipkinRestTemplateSenderConfiguration.java:160)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:637)
    at org.springframework.cloud.sleuth.zipkin2.sender.RestTemplateSender.post(RestTemplateSender.java:129)
    at org.springframework.cloud.sleuth.zipkin2.sender.RestTemplateSender$HttpPostCall.doExecute(RestTemplateSender.java:142)
    at org.springframework.cloud.sleuth.zipkin2.sender.RestTemplateSender$HttpPostCall.doExecute(RestTemplateSender.java:132)
    at zipkin2.Call$Base.execute(Call.java:379)
    at zipkin2.reporter.AsyncReporter$BoundedAsyncReporter.flush(AsyncReporter.java:286)
    at zipkin2.reporter.AsyncReporter$Builder$1.run(AsyncReporter.java:190)
@Slf4j
public class GrayChooserRule extends ZoneAvoidanceRule {

    private ServerChooser<Server> serverChooser;

    public GrayChooserRule() {
        serverChooser = GrayClientHolder.getServerChooser();
    }

    @Override
    public Server choose(Object key) {
        try {
            return serverChooser.chooseServer(getLoadBalancer().getAllServers(), (group, servers) -> {
                Optional<Server> server = getPredicate().chooseRoundRobinAfterFiltering(servers, key);
                if (server.isPresent()) {
                    return server.get();
                } else {
                    return null;
                }
            });
        } catch (Exception e) {
            //log.warn("gray choose server occur exception:{}, execute super method.", e.getMessage(), e);
            log.debug("gray choose server occur exception:{}, execute super method.", e.getMessage(), e);
            return super.choose(key);
        }
    }
}

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/27/spring-cloud-gray-access-and-deployment-record/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Spring Cloud Gray 接入及部署记录
小技巧 如果灰度实例不生效,可尝试将Gray Status先置为CLOSE,再置为OPEN 如果HttpTrack不起作用,可尝试重新配置提交 数据库编码 ALTER DATABASE gray_se……
<<上一篇
下一篇>>
文章目录
关闭
目 录