org.springframework.boot.actuate.endpoint.EndpointsSupplier Java Examples

The following examples show how to use org.springframework.boot.actuate.endpoint.EndpointsSupplier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SkipPatternAutoConfiguration.java    From java-spring-web with Apache License 2.0 6 votes vote down vote up
static Optional<Pattern> getEndpointsPatterns(WebEndpointProperties webEndpointProperties,
                                              EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier) {
  Collection<ExposableWebEndpoint> endpoints = endpointsSupplier.getEndpoints();

  if (endpoints.isEmpty()) {
    return Optional.empty();
  }

  String pattern = endpoints.stream().map(PathMappedEndpoint::getRootPath)
      .map(path -> path + "|" + path + "/.*").collect(
          Collectors.joining("|",
              getPathPrefix(webEndpointProperties.getBasePath()) + "/(",
              ")"));
  if (StringUtils.hasText(pattern)) {
    return Optional.of(Pattern.compile(pattern));
  }
  return Optional.empty();
}
 
Example #2
Source File: SkipPatternConfigTest.java    From java-spring-web with Apache License 2.0 6 votes vote down vote up
@Test
public void testShouldReturnEndpointsWithoutContextPath() {
  WebEndpointProperties webEndpointProperties = new WebEndpointProperties();
  ServerProperties properties = new ServerProperties();
  properties.getServlet().setContextPath("foo");

  EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = () -> {
    ExposableWebEndpoint infoEndpoint = createEndpoint("info");
    ExposableWebEndpoint healthEndpoint = createEndpoint("health");

    return Arrays.asList(infoEndpoint, healthEndpoint);
  };

  Optional<Pattern> pattern = new SkipPatternAutoConfiguration.ActuatorSkipPatternProviderConfig()
      .skipPatternForActuatorEndpointsSamePort(webEndpointProperties, endpointsSupplier)
      .pattern();

  then(pattern).isNotEmpty();
  then(pattern.get().pattern())
      .isEqualTo("/actuator/(info|info/.*|health|health/.*)");
}
 
Example #3
Source File: SkipPatternConfigTest.java    From java-spring-web with Apache License 2.0 6 votes vote down vote up
@Test
public void testShouldReturnEndpointsWithoutContextPathAndBasePathSetToRoot() {
  WebEndpointProperties webEndpointProperties = new WebEndpointProperties();
  webEndpointProperties.setBasePath("/");

  EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = () -> {
    ExposableWebEndpoint infoEndpoint = createEndpoint("info");
    ExposableWebEndpoint healthEndpoint = createEndpoint("health");

    return Arrays.asList(infoEndpoint, healthEndpoint);
  };

  Optional<Pattern> pattern = new SkipPatternAutoConfiguration.ActuatorSkipPatternProviderConfig()
      .skipPatternForActuatorEndpointsSamePort(webEndpointProperties, endpointsSupplier)
      .pattern();

  then(pattern).isNotEmpty();
  then(pattern.get().pattern()).isEqualTo("/(info|info/.*|health|health/.*)");
}
 
Example #4
Source File: SkipPatternConfigTest.java    From java-spring-web with Apache License 2.0 6 votes vote down vote up
@Test
public void testShouldReturnEndpointsWithContextPathAndBasePathSetToRoot() {
  WebEndpointProperties webEndpointProperties = new WebEndpointProperties();
  webEndpointProperties.setBasePath("/");

  EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = () -> {
    ExposableWebEndpoint infoEndpoint = createEndpoint("info");
    ExposableWebEndpoint healthEndpoint = createEndpoint("health");

    return Arrays.asList(infoEndpoint, healthEndpoint);
  };

  Optional<Pattern> pattern = new SkipPatternAutoConfiguration.ActuatorSkipPatternProviderConfig()
      .skipPatternForActuatorEndpointsSamePort(webEndpointProperties, endpointsSupplier)
      .pattern();

  then(pattern).isNotEmpty();
  then(pattern.get().pattern()).isEqualTo("/(info|info/.*|health|health/.*)");
}
 
Example #5
Source File: SkipPatternAutoConfiguration.java    From java-spring-web with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnManagementPort(ManagementPortType.SAME)
public SkipPattern skipPatternForActuatorEndpointsSamePort(
    final WebEndpointProperties webEndpointProperties,
    final EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier) {
  return () -> getEndpointsPatterns(webEndpointProperties, endpointsSupplier);
}
 
Example #6
Source File: SkipPatternAutoConfiguration.java    From java-spring-web with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnManagementPort(ManagementPortType.DIFFERENT)
@ConditionalOnProperty(name = "management.server.servlet.context-path", havingValue = "/", matchIfMissing = true)
public SkipPattern skipPatternForActuatorEndpointsDifferentPort(
    final WebEndpointProperties webEndpointProperties,
    final EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier) {
  return () -> getEndpointsPatterns(webEndpointProperties, endpointsSupplier);
}
 
Example #7
Source File: SkipPatternConfigTest.java    From java-spring-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testShouldReturnEmptyWhenNoEndpoints() {
  EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = Collections::emptyList;
  Optional<Pattern> pattern = new SkipPatternAutoConfiguration.ActuatorSkipPatternProviderConfig()
      .skipPatternForActuatorEndpointsSamePort(new WebEndpointProperties(), endpointsSupplier)
      .pattern();

  then(pattern).isEmpty();
}
 
Example #8
Source File: SkipPatternConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
static Optional<Pattern> getEndpointsPatterns(String contextPath,
		WebEndpointProperties webEndpointProperties,
		EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier) {
	Collection<ExposableWebEndpoint> endpoints = endpointsSupplier.getEndpoints();
	if (endpoints.isEmpty()) {
		return Optional.empty();
	}
	String basePath = webEndpointProperties.getBasePath();
	String pattern = patternFromEndpoints(contextPath, endpoints, basePath);
	if (StringUtils.hasText(pattern)) {
		return Optional.of(Pattern.compile(pattern));
	}
	return Optional.empty();
}
 
Example #9
Source File: SkipPatternConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnManagementPort(ManagementPortType.SAME)
public SingleSkipPattern skipPatternForActuatorEndpointsSamePort(
		final ServerProperties serverProperties,
		final WebEndpointProperties webEndpointProperties,
		final EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier) {
	return () -> getEndpointsPatterns(
			serverProperties.getServlet().getContextPath(), webEndpointProperties,
			endpointsSupplier);
}
 
Example #10
Source File: SkipPatternConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnManagementPort(ManagementPortType.DIFFERENT)
@ConditionalOnProperty(name = "management.server.servlet.context-path",
		havingValue = "/", matchIfMissing = true)
public SingleSkipPattern skipPatternForActuatorEndpointsDifferentPort(
		final ServerProperties serverProperties,
		final WebEndpointProperties webEndpointProperties,
		final EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier) {
	return () -> getEndpointsPatterns(null, webEndpointProperties,
			endpointsSupplier);
}
 
Example #11
Source File: SkipPatternProviderConfigTest.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_empty_when_no_endpoints() {
	EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = Collections::emptyList;
	Optional<Pattern> pattern = new SkipPatternConfiguration.ActuatorSkipPatternProviderConfig()
			.skipPatternForActuatorEndpointsSamePort(new ServerProperties(),
					new WebEndpointProperties(), endpointsSupplier)
			.skipPattern();

	then(pattern).isEmpty();
}