当前位置: 首页 > news >正文

springcould-config git源情况下报错app仓库找不到

在使用spring config server服务的时候发现在启动之后的一段时间内控制台会抛出异常,spring admin监控爆红,控制台信息如下

--2024-06-26 20:38:59.615  - WARN 2944 --- [oundedElastic-7] o.s.c.c.s.e.JGitEnvironmentRepository    : Error occured cloning to base directory.
-
org.eclipse.jgit.api.errors.TransportException: git@gitee.com:xxx/app-config.git: socket is not establishedat org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:254) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar:5.1.3.201810200350-r]at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:306) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar:5.1.3.201810200350-r]at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:200) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar:5.1.3.201810200350-r]

配置的 spring.cloud.config.server.git.uri=git@gitee.com:xxx/{application}-config.git采用的是多微服务git仓库隔离的方式进行管理,但是我当前的集群中仅仅启动了spring cloud config server节点,并且集群中并不存在名字为app的服务,通过断点代码查询发现是actuate health功能导致的,在org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration.ConfigServerActuatorConfiguration根据配置spring.cloud.config.server.health.enabled实例化了一个health bean,而该值在默认情况下为true

  @ConditionalOnClass({AbstractHealthIndicator.class})@ConditionalOnProperty(value = {"spring.cloud.config.server.health.enabled"},matchIfMissing = true)protected static class ConfigServerActuatorConfiguration {protected ConfigServerActuatorConfiguration() {}@Beanpublic ConfigServerHealthIndicator configServerHealthIndicator(EnvironmentRepository repository) {return new ConfigServerHealthIndicator(repository);}}

ConfigServerHealthIndicator实现了HealthIndicator接口,在当前节点内,在eureka调用/actuator/health 的时候就会执行(之前一一直理解为定时器执行),它的health check如下

@Overrideprotected void doHealthCheck(Health.Builder builder) throws Exception {builder.up();List<Map<String, Object>> details = new ArrayList<>();for (String name : this.repositories.keySet()) {Repository repository = this.repositories.get(name);String application = (repository.getName() == null) ? name: repository.getName();String profiles = repository.getProfiles();try {Environment environment = this.environmentRepository.findOne(application,profiles, repository.getLabel(), false);HashMap<String, Object> detail = new HashMap<>();detail.put("name", environment.getName());detail.put("label", environment.getLabel());if (environment.getProfiles() != null&& environment.getProfiles().length > 0) {detail.put("profiles", Arrays.asList(environment.getProfiles()));}if (!CollectionUtils.isEmpty(environment.getPropertySources())) {List<String> sources = new ArrayList<>();for (PropertySource source : environment.getPropertySources()) {sources.add(source.getName());}detail.put("sources", sources);}details.add(detail);}catch (Exception e) {logger.debug("Could not read repository: " + application, e);HashMap<String, String> map = new HashMap<>();map.put("application", application);map.put("profiles", profiles);builder.withDetail("repository", map);builder.down(e);return;}}builder.withDetail("repositories", details);}@PostConstructpublic void init() {if (this.repositories.isEmpty()) {this.repositories.put("app", new Repository());}}

在bean 构造完成的时候会执行一个init方法,直接推了一个app 进去,这就是罪魁祸首,可以把spring.cloud.config.server.health.enabled设置为false关闭health的检查或者配置一个spring.cloud.config.server.health.repositories配置一个真实的应用比如

spring.cloud.config.server.health.repositories.fxdanmugw-config.label=master
spring.cloud.config.server.health.repositories.fxdanmugw-config.name=xxx

排查这个问题的时候还在好奇为什么spring会提供这种能力?不过一想,确实有存在的必要,比如仓库中提供的配置被不小心删除了,微服务那边自己本身有一套默认配置,默认配置也可以让微服务成功启动,但是提供的服务存在差异,此时从服务状态上是很难直接预警的,但是如果有这个能力之后,endpoint 就能提供对应监视仓库文件是否存在,且配合Grafana Prometheus 提供预警能力,另外config server完全可以给客户端提供配置服务,比如游戏的配置服务,还自带版本管理,是一个有效的使用场景

我明确的记得在使用单个固定的git仓库的时候这个配置点是可以正常进行health check的,为什么改为多项目单仓库隔离就会出问题?真是奇怪这个需要进一步探究,又或者在启动的时候直接吧app这个给移除?

对应的官方描述在这里 health_indicator
在这里插入图片描述

相关文章:

  • Python功能制作之使用streamlit做一个简单的WebUI
  • 速盾:ddos高防ip是什么?
  • 基于Web技术的教育辅助系统设计与实现(SpringBoot MySQL)+文档
  • Docker入门指南:构建、部署与管理容器化应用
  • 打卡第二十七天 455分发饼干 376摆动序列
  • Mac如何杀毒?Mac电脑如何杀毒 mac杀毒软件推荐 mac杀毒软件哪个好用
  • 运维锅总浅析云原生DevOps工具
  • 华为od-C卷200分题目4 -电脑病毒感染
  • 如何选择适合自己的虚拟化技术?
  • leetCode.97. 交错字符串
  • PHP爬虫类的并发与多线程处理技巧
  • Postman接口工具实战
  • C++初学者指南-3.自定义类型(第一部分)-异常
  • 使用supportFragmentManager管理多个fragment切换
  • OpenSSL的一些使用案例
  • [deviceone开发]-do_Webview的基本示例
  • Java方法详解
  • js写一个简单的选项卡
  • JS专题之继承
  • MySQL几个简单SQL的优化
  • Spring Cloud Alibaba迁移指南(一):一行代码从 Hystrix 迁移到 Sentinel
  • Vue2 SSR 的优化之旅
  • Web Storage相关
  • 第十八天-企业应用架构模式-基本模式
  • 技术:超级实用的电脑小技巧
  • 简单易用的leetcode开发测试工具(npm)
  • 来,膜拜下android roadmap,强大的执行力
  • 聊聊spring cloud的LoadBalancerAutoConfiguration
  • 目录与文件属性:编写ls
  • 前端性能优化——回流与重绘
  • 浅谈Golang中select的用法
  • 浅谈Kotlin实战篇之自定义View图片圆角简单应用(一)
  • 使用iElevator.js模拟segmentfault的文章标题导航
  • 提醒我喝水chrome插件开发指南
  • 通过几道题目学习二叉搜索树
  • 为视图添加丝滑的水波纹
  • 一个6年java程序员的工作感悟,写给还在迷茫的你
  • 译有关态射的一切
  • 因为阿里,他们成了“杭漂”
  • 正则表达式小结
  • 关于Kubernetes Dashboard漏洞CVE-2018-18264的修复公告
  • ​无人机石油管道巡检方案新亮点:灵活准确又高效
  • #162 (Div. 2)
  • #微信小程序:微信小程序常见的配置传旨
  • (09)Hive——CTE 公共表达式
  • (1)svelte 教程:hello world
  • (LeetCode) T14. Longest Common Prefix
  • (附源码)springboot 房产中介系统 毕业设计 312341
  • (附源码)springboot 校园学生兼职系统 毕业设计 742122
  • (深入.Net平台的软件系统分层开发).第一章.上机练习.20170424
  • (十八)SpringBoot之发送QQ邮件
  • (十五)Flask覆写wsgi_app函数实现自定义中间件
  • .net core 调用c dll_用C++生成一个简单的DLL文件VS2008
  • .NET Core 实现 Redis 批量查询指定格式的Key
  • .NET Framework 服务实现监控可观测性最佳实践