Hystrix状态未在/ health下公开

问题描述 投票:0回答:2

根据https://cloud.spring.io/spring-cloud-netflix/multi/multi__circuit_breaker_hystrix_clients.html,我的应用程序应该在/ health下提供hystrix数据。尽管开放式断路器,我在该网址下看到的唯一内容是

{"status":"UP"}

我期待看到类似的东西

{
    "hystrix": {
        "openCircuitBreakers": [
            "somedata::somedata"
        ],
        "status": "CIRCUIT_OPEN"
    },
    "status": "UP"
}

我错过了什么?

我的build.gradle

buildscript {
    ext {
        springBootVersion = '1.5.10.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }

}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

group = 'com.somecompany'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


ext {
    springCloudVersion = 'Edgware.SR1'
}

dependencies {
    compile('org.springframework.cloud:spring-cloud-starter-hystrix')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-actuator')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

应用类

@EnableCircuitBreaker
@SpringBootApplication
public class HystrixDemoApplication {

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

Hystrix控制下的资源

@RestController
public class SomeResourceController {

    @HystrixCommand(fallbackMethod = "defaultValue", commandProperties = {@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds", value="1500")})
    @RequestMapping(path = "/resource-with-hystrix", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public String someResource(){
        URI uri = URI.create("http://localhost:8080/some-resource");
        RestOperations restTemplate = new RestTemplate();
        return restTemplate.getForObject(uri, String.class);
    }

    private String defaultValue(){
        return "local value in case of something goes wrong";
    }
}
java spring-boot hystrix spring-boot-actuator
2个回答
1
投票

将Health端点设置为不敏感(默认):

endpoints.health.sensitive=false

根据端点的暴露方式,敏感属性可以用作安全提示。例如,敏感端点在通过HTTP访问时需要用户名/密码(如果未启用Web安全性,则只需禁用)。

从健康端点的文档:

显示应用程序运行状况信息(当应用程序是安全的时,通过未经身份验证的连接访问时的简单“状态”或经过身份验证时的完整消息详细信息)。


2
投票

documentation说:

健康端点公开的信息取决于management.endpoint.health.show-details属性 默认值为 never

因此,为了显示hystrix信息,您需要将management.endpoint.health.show-details设置为以下任何一个:

  • when_authorized
  • 总是

像这样:

management.endpoint.health.show-details = always

msfoster提供的答案不再有效(从Spring Boot 2.1.x和云发布列车Greenwich.RELEASE开始):

端点敏感标志不再可自定义,因为Spring Boot不再提供可自定义的安全自动配置。相应地创建或调整您的安全配置

© www.soinside.com 2019 - 2024. All rights reserved.