org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties Java Examples

The following examples show how to use org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties. 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: ClusterCheckerTask.java    From genie with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor.
 *
 * @param genieHostInfo         Information about the host this Genie process is running on
 * @param properties            The properties to use to configure the task
 * @param dataServices          The {@link DataServices} encapsulation instance to use
 * @param restTemplate          The rest template for http calls
 * @param webEndpointProperties The properties where Spring actuator is running
 * @param registry              The spectator registry for getting metrics
 */
public ClusterCheckerTask(
    @NotNull final GenieHostInfo genieHostInfo,
    @NotNull final ClusterCheckerProperties properties,
    @NotNull final DataServices dataServices,
    @NotNull final RestTemplate restTemplate,
    @NotNull final WebEndpointProperties webEndpointProperties,
    @NotNull final MeterRegistry registry
) {
    this.hostname = genieHostInfo.getHostname();
    this.properties = properties;
    this.persistenceService = dataServices.getPersistenceService();
    this.restTemplate = restTemplate;
    this.registry = registry;
    this.scheme = this.properties.getScheme() + "://";
    this.healthEndpoint = ":" + this.properties.getPort() + webEndpointProperties.getBasePath() + "/health";
    this.healthIndicatorsToIgnore = Splitter.on(",").omitEmptyStrings()
        .trimResults().splitToList(properties.getHealthIndicatorsToIgnore());
    // Keep track of the number of nodes currently unreachable from the the master
    Gauge.builder(UNHEALTHY_HOSTS_GAUGE_METRIC_NAME, this.errorCounts, Map::size)
        .register(registry);
}
 
Example #3
Source File: LeaderAutoConfiguration.java    From genie with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link ClusterCheckerTask} if one hasn't been supplied.
 *
 * @param genieHostInfo         Information about the host this Genie process is running on
 * @param properties            The properties to use to configure the task
 * @param dataServices          The {@link DataServices} instance to use
 * @param restTemplate          The rest template for http calls
 * @param webEndpointProperties The properties where Spring actuator is running
 * @param registry              The spectator registry for getting metrics
 * @return The {@link ClusterCheckerTask} instance
 */
@Bean
@ConditionalOnMissingBean(ClusterCheckerTask.class)
public ClusterCheckerTask clusterCheckerTask(
    final GenieHostInfo genieHostInfo,
    final ClusterCheckerProperties properties,
    final DataServices dataServices,
    @Qualifier("genieRestTemplate") final RestTemplate restTemplate,
    final WebEndpointProperties webEndpointProperties,
    final MeterRegistry registry
) {
    return new ClusterCheckerTask(
        genieHostInfo,
        properties,
        dataServices,
        restTemplate,
        webEndpointProperties,
        registry
    );
}
 
Example #4
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 #5
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 #6
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 #7
Source File: LightminClientProperties.java    From spring-batch-lightmin with Apache License 2.0 6 votes vote down vote up
@Autowired
public LightminClientProperties(final ManagementServerProperties managementServerProperties,
                                final ServerProperties serverProperties,
                                @Value("${spring.batch.lightmin.application-name:null}") final String name,
                                @Value("${endpoints.health.id:health}") final String healthEndpointId,
                                final WebEndpointProperties webEndpointProperties,
                                final Environment environment) {
    if (name == null || "null".equals(name)) {
        this.name = environment.getProperty("spring.application.name", "spring-boot-application");
    } else {
        this.name = name;
    }
    this.healthEndpointId = healthEndpointId;
    this.managementServerProperties = managementServerProperties;
    this.serverProperties = serverProperties;
    this.webEndpointProperties = webEndpointProperties;
}
 
Example #8
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 #9
Source File: SpringBootAdminClientCloudFoundryAutoConfiguration.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Bean
@Lazy(false)
@ConditionalOnMissingBean
public CloudFoundryApplicationFactory applicationFactory(InstanceProperties instance,
		ManagementServerProperties management, ServerProperties server, PathMappedEndpoints pathMappedEndpoints,
		WebEndpointProperties webEndpoint, ObjectProvider<List<MetadataContributor>> metadataContributors,
		CloudFoundryApplicationProperties cfApplicationProperties) {
	return new CloudFoundryApplicationFactory(instance, management, server, pathMappedEndpoints, webEndpoint,
			new CompositeMetadataContributor(metadataContributors.getIfAvailable(Collections::emptyList)),
			cfApplicationProperties);
}
 
Example #10
Source File: SpringBootAdminClientAutoConfiguration.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Bean
@Lazy(false)
@ConditionalOnMissingBean
public ApplicationFactory applicationFactory(InstanceProperties instance, ManagementServerProperties management,
		ServerProperties server, PathMappedEndpoints pathMappedEndpoints, WebEndpointProperties webEndpoint,
		ObjectProvider<List<MetadataContributor>> metadataContributors) {
	return new DefaultApplicationFactory(instance, management, server, pathMappedEndpoints, webEndpoint,
			new CompositeMetadataContributor(metadataContributors.getIfAvailable(Collections::emptyList)));
}
 
Example #11
Source File: SpringBootAdminClientAutoConfiguration.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Bean
@Lazy(false)
@ConditionalOnMissingBean
public ApplicationFactory applicationFactory(InstanceProperties instance, ManagementServerProperties management,
		ServerProperties server, ServletContext servletContext, PathMappedEndpoints pathMappedEndpoints,
		WebEndpointProperties webEndpoint, ObjectProvider<List<MetadataContributor>> metadataContributors,
		DispatcherServletPath dispatcherServletPath) {
	return new ServletApplicationFactory(instance, management, server, servletContext, pathMappedEndpoints,
			webEndpoint,
			new CompositeMetadataContributor(metadataContributors.getIfAvailable(Collections::emptyList)),
			dispatcherServletPath);
}
 
Example #12
Source File: ServletApplicationFactory.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
public ServletApplicationFactory(InstanceProperties instance, ManagementServerProperties management,
		ServerProperties server, ServletContext servletContext, PathMappedEndpoints pathMappedEndpoints,
		WebEndpointProperties webEndpoint, MetadataContributor metadataContributor,
		DispatcherServletPath dispatcherServletPath) {
	super(instance, management, server, pathMappedEndpoints, webEndpoint, metadataContributor);
	this.servletContext = servletContext;
	this.server = server;
	this.management = management;
	this.instance = instance;
	this.dispatcherServletPath = dispatcherServletPath;
}
 
Example #13
Source File: DefaultApplicationFactory.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
public DefaultApplicationFactory(InstanceProperties instance, ManagementServerProperties management,
		ServerProperties server, PathMappedEndpoints pathMappedEndpoints, WebEndpointProperties webEndpoint,
		MetadataContributor metadataContributor) {
	this.instance = instance;
	this.management = management;
	this.server = server;
	this.pathMappedEndpoints = pathMappedEndpoints;
	this.webEndpoint = webEndpoint;
	this.metadataContributor = metadataContributor;
}
 
Example #14
Source File: CloudFoundryApplicationFactory.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
public CloudFoundryApplicationFactory(InstanceProperties instance, ManagementServerProperties management,
		ServerProperties server, PathMappedEndpoints pathMappedEndpoints, WebEndpointProperties webEndpoint,
		MetadataContributor metadataContributor, CloudFoundryApplicationProperties cfApplicationProperties) {
	super(instance, management, server, pathMappedEndpoints, webEndpoint, metadataContributor);
	this.cfApplicationProperties = cfApplicationProperties;
	this.instance = instance;
}
 
Example #15
Source File: ArmeriaSpringActuatorAutoConfiguration.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnProperty("management.server.port")
ArmeriaServerConfigurator secureActuatorServerConfigurator(WebEndpointProperties properties,
                                                           ManagementServerProperties serverProperties,
                                                           ConfigurableEnvironment environment,
                                                           ArmeriaSettings armeriaSettings) {
    return sb -> {
        final Port port = obtainManagementServerPort(serverProperties.getPort());
        if (port != null) {
            configurePorts(sb, ImmutableList.of(port));
            addLocalManagementPortPropertyAlias(environment, port);
            configureSecureDecorator(sb, port, properties.getBasePath(), armeriaSettings);
        }
    };
}
 
Example #16
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();
}
 
Example #17
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 #18
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 #19
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 #20
Source File: ActuatorRequestMatcher.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected RequestMatcher createDelegate(WebApplicationContext context, RequestMatcherFactory requestMatcherFactory) {
    WebEndpointProperties properties = context.getBean(WebEndpointProperties.class);
    if (StringUtils.hasText(properties.getBasePath())) {
        return requestMatcherFactory.antPath(properties.getBasePath() + "/**");
    }
    return EMPTY_MATCHER;
}
 
Example #21
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 #22
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 #23
Source File: GlobalModelAttributes.java    From edison-microservice with Apache License 2.0 4 votes vote down vote up
@Autowired
public GlobalModelAttributes(final WebEndpointProperties  webEndpointProperties,
                             final EdisonApplicationProperties edisonApplicationProperties) {
    this.webEndpointProperties = webEndpointProperties;
    this.edisonApplicationProperties = edisonApplicationProperties;
}
 
Example #24
Source File: LeaderAutoConfigurationTest.java    From genie with Apache License 2.0 4 votes vote down vote up
@Bean
WebEndpointProperties webEndpointProperties() {
    return Mockito.mock(WebEndpointProperties.class);
}