【问题标题】:Spring Cloud Netflix Hystrix Turbine not getting info from services on the same hostSpring Cloud Netflix Hystrix Turbine 未从同一主机上的服务获取信息
【发布时间】:2016-02-29 18:42:11
【问题描述】:

我已关注Spring Cloud Netflix's guide 配置 Turbine。在两个微服务中启用 Hystrix 后,我已验证 /hystrix.stream 端点生成正确的输出。

现在,在 hystrix 仪表板项目中,我已配置 Turbine 以获取所有服务的聚合结果。然而,我得到的只是一系列的:

: ping
data: {"reportingHostsLast10Seconds":0,"name":"meta","type":"meta","timestamp":1448552456486}

这是我的配置:

HystrixDashboard + Turbine 应用程序:

@EnableHystrixDashboard
@EnableTurbine
@SpringBootApplication
public class HystrixDashboardApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixDashboardApplication.class, args);
    }
}

HystrixDashboard + Turbine application.yml:

spring:
  application:
    name: hystrix-dashboard

server:
  port: 10000

turbine:
  appConfig: random-story-microservice,storyteller-api
  instanceUrlSuffix: /hystrix.stream

logging:
  level:
    com.netflix.turbine: 'TRACE'

更新

按照 kreel 的指示,我以这种方式配置了 Turbine:

turbine:
  appConfig: random-story-microservice,storyteller-api
  instanceUrlSuffix: /hystrix.stream
  clusterNameExpression: new String("default")

它不再因异常而失败,在日志中我看到 Turbine 找到了两个候选主机/微服务:

[        Timer-0] c.n.t.discovery.InstanceObservable       : Retrieved hosts from InstanceDiscovery: 2

但是最终只有其中一个被注册。在InstanceObservable.run() 中,仅添加了一个主机,因为它们具有相同的哈希码,因此在添加到 newState.hostsUp 时它们被认为是相同的。 com.netflix.turbine.discovery.Instance 哈希码是根据主机名(在这两种情况下都是“myhost”)和集群(“默认”)计算得出的:

// set the current state
            for(Instance host: newList) {
                if(host.isUp()) {
                    newState.hostsUp.add(host);
                } else {
                    newState.hostsDown.add(host);
                }
            }

当同一台主机提供两种不同的微服务时,我们该怎么办?在这种情况下只注册了第一个实例。

【问题讨论】:

标签: spring spring-cloud netflix hystrix turbine


【解决方案1】:

我想我有一个答案,但首先,可以肯定的是,你为什么期待“默认”?

【讨论】:

  • 我没有在turbine: aggregator: clusterConfig: XXXX配置任何集群,因此clusterName的值为default
【解决方案2】:

事实上我认为你误解了文档:

The configuration key turbine.appConfig is a list of eureka serviceIds that turbine will use to lookup instances. The turbine stream is then used in the Hystrix dashboard using a url that looks like: http://my.turbine.sever:8080/turbine.stream?cluster=<CLUSTERNAME>; (the cluster parameter can be omitted if the name is "default"). The cluster parameter must match an entry in turbine.aggregator.clusterConfig. Values returned from eureka are uppercase, thus we expect this example to work if there is an app registered with Eureka called "customers":

turbine:
  aggregator:
    clusterConfig: CUSTOMERS
  appConfig: customers

在你的情况下:

turbine:
  aggregator:
    clusterConfig: MY_CLUSTER
  appConfig: random-story-microservice,storyteller-api

所以它会以大写形式返回“random-story-microservice,storyteller-api”。

【讨论】:

  • 感谢您的回复。你是对的,我误解了文档。但是(请参阅问题中的更新 2),这样您一次只能获取有关一项服务的信息
【解决方案3】:

所以,我认为你需要应用这部分:

The clusterName can be customized by a SPEL expression in turbine.clusterNameExpression with root an instance of InstanceInfo. The default value is appName, which means that the Eureka serviceId ends up as the cluster key (i.e. the InstanceInfo for customers has an appName of "CUSTOMERS"). A different example would be turbine.clusterNameExpression=aSGName, which would get the cluster name from the AWS ASG name. Another example:

turbine:
  aggregator:
    clusterConfig: SYSTEM,USER
  appConfig: customers,stores,ui,admin
  clusterNameExpression: metadata['cluster']

In this case, the cluster name from 4 services is pulled from their metadata map, and is expected to have values that include "SYSTEM" and "USER".

To use the "default" cluster for all apps you need a string literal expression (with single quotes):

turbine:
  appConfig: customers,stores
  clusterNameExpression: 'default'

Spring Cloud provides a spring-cloud-starter-turbine that has all the dependencies you need to get a Turbine server running. Just create a Spring Boot application and annotate it with @EnableTurbine.

在你的配置中添加这个: clusterNameExpression: '默认'

【讨论】:

  • 当使用 clusterNameExpression: 'default' 我在启动时遇到异常:org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'default' cannot be found on object of type 'com.netflix.appinfo.InstanceInfo' - maybe not public?
  • 我将尝试使用通用名称设置 Eureka 客户端的元数据映射。再次感谢您的帮助
  • 不,我认为这是现在直接向您发送汇总信息。只需尝试打印查询结果即可查看。
猜你喜欢
  • 2016-03-31
  • 1970-01-01
  • 2015-12-25
  • 2018-07-07
  • 2018-08-17
  • 1970-01-01
  • 2015-08-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多