Search in sources :

Example 16 with HealthEndpointGroup

use of org.springframework.boot.actuate.health.HealthEndpointGroup in project spring-boot by spring-projects.

the class AvailabilityProbesHealthEndpointGroupsTests method getLivenessProbeHasOnlyLivenessStateAsMember.

@Test
void getLivenessProbeHasOnlyLivenessStateAsMember() {
    HealthEndpointGroups availabilityProbes = new AvailabilityProbesHealthEndpointGroups(this.delegate, false);
    HealthEndpointGroup probeGroup = availabilityProbes.get("liveness");
    assertThat(probeGroup.isMember("livenessState")).isTrue();
    assertThat(probeGroup.isMember("readinessState")).isFalse();
}
Also used : HealthEndpointGroups(org.springframework.boot.actuate.health.HealthEndpointGroups) HealthEndpointGroup(org.springframework.boot.actuate.health.HealthEndpointGroup) Test(org.junit.jupiter.api.Test)

Example 17 with HealthEndpointGroup

use of org.springframework.boot.actuate.health.HealthEndpointGroup in project spring-boot by spring-projects.

the class AutoConfiguredHealthEndpointGroups method createGroups.

private Map<String, HealthEndpointGroup> createGroups(Map<String, Group> groupProperties, BeanFactory beanFactory, StatusAggregator defaultStatusAggregator, HttpCodeStatusMapper defaultHttpCodeStatusMapper, Show defaultShowComponents, Show defaultShowDetails, Set<String> defaultRoles) {
    Map<String, HealthEndpointGroup> groups = new LinkedHashMap<>();
    groupProperties.forEach((groupName, group) -> {
        Status status = group.getStatus();
        Show showComponents = (group.getShowComponents() != null) ? group.getShowComponents() : defaultShowComponents;
        Show showDetails = (group.getShowDetails() != null) ? group.getShowDetails() : defaultShowDetails;
        Set<String> roles = !CollectionUtils.isEmpty(group.getRoles()) ? group.getRoles() : defaultRoles;
        StatusAggregator statusAggregator = getQualifiedBean(beanFactory, StatusAggregator.class, groupName, () -> {
            if (!CollectionUtils.isEmpty(status.getOrder())) {
                return new SimpleStatusAggregator(status.getOrder());
            }
            return defaultStatusAggregator;
        });
        HttpCodeStatusMapper httpCodeStatusMapper = getQualifiedBean(beanFactory, HttpCodeStatusMapper.class, groupName, () -> {
            if (!CollectionUtils.isEmpty(status.getHttpMapping())) {
                return new SimpleHttpCodeStatusMapper(status.getHttpMapping());
            }
            return defaultHttpCodeStatusMapper;
        });
        Predicate<String> members = new IncludeExcludeGroupMemberPredicate(group.getInclude(), group.getExclude());
        AdditionalHealthEndpointPath additionalPath = (group.getAdditionalPath() != null) ? AdditionalHealthEndpointPath.from(group.getAdditionalPath()) : null;
        groups.put(groupName, new AutoConfiguredHealthEndpointGroup(members, statusAggregator, httpCodeStatusMapper, showComponents, showDetails, roles, additionalPath));
    });
    return Collections.unmodifiableMap(groups);
}
Also used : Status(org.springframework.boot.actuate.autoconfigure.health.HealthProperties.Status) SimpleStatusAggregator(org.springframework.boot.actuate.health.SimpleStatusAggregator) AdditionalHealthEndpointPath(org.springframework.boot.actuate.health.AdditionalHealthEndpointPath) HealthEndpointGroup(org.springframework.boot.actuate.health.HealthEndpointGroup) LinkedHashMap(java.util.LinkedHashMap) SimpleStatusAggregator(org.springframework.boot.actuate.health.SimpleStatusAggregator) StatusAggregator(org.springframework.boot.actuate.health.StatusAggregator) HttpCodeStatusMapper(org.springframework.boot.actuate.health.HttpCodeStatusMapper) SimpleHttpCodeStatusMapper(org.springframework.boot.actuate.health.SimpleHttpCodeStatusMapper) Show(org.springframework.boot.actuate.autoconfigure.health.HealthProperties.Show) SimpleHttpCodeStatusMapper(org.springframework.boot.actuate.health.SimpleHttpCodeStatusMapper)

Example 18 with HealthEndpointGroup

use of org.springframework.boot.actuate.health.HealthEndpointGroup in project spring-boot by spring-projects.

the class AutoConfiguredHealthEndpointGroupsTests method createWhenHasHttpCodeStatusMapperPropertyReturnsInstanceWithPropertyUsedForAllGroups.

@Test
void createWhenHasHttpCodeStatusMapperPropertyReturnsInstanceWithPropertyUsedForAllGroups() {
    this.contextRunner.withPropertyValues("management.endpoint.health.status.http-mapping.down=201", "management.endpoint.health.group.a.include=*").run((context) -> {
        HealthEndpointGroups groups = context.getBean(HealthEndpointGroups.class);
        HealthEndpointGroup primary = groups.getPrimary();
        HealthEndpointGroup groupA = groups.get("a");
        assertThat(primary.getHttpCodeStatusMapper().getStatusCode(Status.DOWN)).isEqualTo(201);
        assertThat(groupA.getHttpCodeStatusMapper().getStatusCode(Status.DOWN)).isEqualTo(201);
    });
}
Also used : HealthEndpointGroups(org.springframework.boot.actuate.health.HealthEndpointGroups) HealthEndpointGroup(org.springframework.boot.actuate.health.HealthEndpointGroup) Test(org.junit.jupiter.api.Test)

Example 19 with HealthEndpointGroup

use of org.springframework.boot.actuate.health.HealthEndpointGroup in project spring-boot by spring-projects.

the class AutoConfiguredHealthEndpointGroupsTests method createWhenHasGroupSpecificStatusAggregatorPropertyAndGroupQualifiedBeanReturnsInstanceWithBeanUsedForExpectedGroups.

@Test
void createWhenHasGroupSpecificStatusAggregatorPropertyAndGroupQualifiedBeanReturnsInstanceWithBeanUsedForExpectedGroups() {
    this.contextRunner.withUserConfiguration(CustomStatusAggregatorGroupAConfiguration.class).withPropertyValues("management.endpoint.health.group.a.include=*", "management.endpoint.health.group.a.status.order=up,down", "management.endpoint.health.group.b.include=*", "management.endpoint.health.group.b.status.order=up,down").run((context) -> {
        HealthEndpointGroups groups = context.getBean(HealthEndpointGroups.class);
        HealthEndpointGroup primary = groups.getPrimary();
        HealthEndpointGroup groupA = groups.get("a");
        HealthEndpointGroup groupB = groups.get("b");
        assertThat(primary.getStatusAggregator().getAggregateStatus(Status.UP, Status.DOWN, Status.UNKNOWN)).isEqualTo(Status.DOWN);
        assertThat(groupA.getStatusAggregator().getAggregateStatus(Status.UP, Status.DOWN, Status.UNKNOWN)).isEqualTo(Status.UNKNOWN);
        assertThat(groupB.getStatusAggregator().getAggregateStatus(Status.UP, Status.DOWN, Status.UNKNOWN)).isEqualTo(Status.UP);
    });
}
Also used : HealthEndpointGroups(org.springframework.boot.actuate.health.HealthEndpointGroups) HealthEndpointGroup(org.springframework.boot.actuate.health.HealthEndpointGroup) Test(org.junit.jupiter.api.Test)

Example 20 with HealthEndpointGroup

use of org.springframework.boot.actuate.health.HealthEndpointGroup in project spring-boot by spring-projects.

the class AutoConfiguredHealthEndpointGroupsTests method getGroupWhenGroupDoesNotExistReturnsNull.

@Test
void getGroupWhenGroupDoesNotExistReturnsNull() {
    this.contextRunner.withPropertyValues("management.endpoint.health.group.a.include=*").run((context) -> {
        HealthEndpointGroups groups = context.getBean(HealthEndpointGroups.class);
        HealthEndpointGroup group = groups.get("b");
        assertThat(group).isNull();
    });
}
Also used : HealthEndpointGroups(org.springframework.boot.actuate.health.HealthEndpointGroups) HealthEndpointGroup(org.springframework.boot.actuate.health.HealthEndpointGroup) Test(org.junit.jupiter.api.Test)

Aggregations

HealthEndpointGroup (org.springframework.boot.actuate.health.HealthEndpointGroup)25 Test (org.junit.jupiter.api.Test)22 HealthEndpointGroups (org.springframework.boot.actuate.health.HealthEndpointGroups)22 AdditionalHealthEndpointPath (org.springframework.boot.actuate.health.AdditionalHealthEndpointPath)3 WebOperation (org.springframework.boot.actuate.endpoint.web.WebOperation)2 WebOperationRequestPredicate (org.springframework.boot.actuate.endpoint.web.WebOperationRequestPredicate)2 LinkedHashMap (java.util.LinkedHashMap)1 Show (org.springframework.boot.actuate.autoconfigure.health.HealthProperties.Show)1 Status (org.springframework.boot.actuate.autoconfigure.health.HealthProperties.Status)1 HttpCodeStatusMapper (org.springframework.boot.actuate.health.HttpCodeStatusMapper)1 SimpleHttpCodeStatusMapper (org.springframework.boot.actuate.health.SimpleHttpCodeStatusMapper)1 SimpleStatusAggregator (org.springframework.boot.actuate.health.SimpleStatusAggregator)1 StatusAggregator (org.springframework.boot.actuate.health.StatusAggregator)1 RequestMappingInfo (org.springframework.web.reactive.result.method.RequestMappingInfo)1