Search in sources :

Example 1 with WebEndpointResponse

use of org.springframework.boot.actuate.endpoint.web.WebEndpointResponse in project spring-boot by spring-projects.

the class PrometheusScrapeEndpoint method scrape.

@ReadOperation(producesFrom = TextOutputFormat.class)
public WebEndpointResponse<String> scrape(TextOutputFormat format, @Nullable Set<String> includedNames) {
    try {
        Writer writer = new StringWriter();
        Enumeration<MetricFamilySamples> samples = (includedNames != null) ? this.collectorRegistry.filteredMetricFamilySamples(includedNames) : this.collectorRegistry.metricFamilySamples();
        format.write(writer, samples);
        return new WebEndpointResponse<>(writer.toString(), format);
    } catch (IOException ex) {
        // This actually never happens since StringWriter doesn't throw an IOException
        throw new IllegalStateException("Writing metrics failed", ex);
    }
}
Also used : StringWriter(java.io.StringWriter) WebEndpointResponse(org.springframework.boot.actuate.endpoint.web.WebEndpointResponse) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) IOException(java.io.IOException) StringWriter(java.io.StringWriter) Writer(java.io.Writer) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation)

Example 2 with WebEndpointResponse

use of org.springframework.boot.actuate.endpoint.web.WebEndpointResponse in project spring-boot by spring-projects.

the class CachesEndpointWebExtension method cache.

@ReadOperation
public WebEndpointResponse<CacheEntry> cache(@Selector String cache, @Nullable String cacheManager) {
    try {
        CacheEntry entry = this.delegate.cache(cache, cacheManager);
        int status = (entry != null) ? WebEndpointResponse.STATUS_OK : WebEndpointResponse.STATUS_NOT_FOUND;
        return new WebEndpointResponse<>(entry, status);
    } catch (NonUniqueCacheException ex) {
        return new WebEndpointResponse<>(WebEndpointResponse.STATUS_BAD_REQUEST);
    }
}
Also used : WebEndpointResponse(org.springframework.boot.actuate.endpoint.web.WebEndpointResponse) CacheEntry(org.springframework.boot.actuate.cache.CachesEndpoint.CacheEntry) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation)

Example 3 with WebEndpointResponse

use of org.springframework.boot.actuate.endpoint.web.WebEndpointResponse in project spring-boot by spring-projects.

the class HealthEndpointAutoConfigurationTests method runWhenHasReactiveHealthEndpointWebExtensionBeanDoesNotCreateExtraReactiveHealthEndpointWebExtension.

@Test
void runWhenHasReactiveHealthEndpointWebExtensionBeanDoesNotCreateExtraReactiveHealthEndpointWebExtension() {
    this.reactiveContextRunner.withUserConfiguration(ReactiveHealthEndpointWebExtensionConfiguration.class).run((context) -> {
        ReactiveHealthEndpointWebExtension webExtension = context.getBean(ReactiveHealthEndpointWebExtension.class);
        Mono<WebEndpointResponse<? extends HealthComponent>> response = webExtension.health(ApiVersion.V3, WebServerNamespace.SERVER, SecurityContext.NONE, true, "simple");
        assertThat(response).isNull();
    });
}
Also used : HealthComponent(org.springframework.boot.actuate.health.HealthComponent) WebEndpointResponse(org.springframework.boot.actuate.endpoint.web.WebEndpointResponse) ReactiveHealthEndpointWebExtension(org.springframework.boot.actuate.health.ReactiveHealthEndpointWebExtension) Test(org.junit.jupiter.api.Test)

Example 4 with WebEndpointResponse

use of org.springframework.boot.actuate.endpoint.web.WebEndpointResponse in project spring-boot by spring-projects.

the class HealthEndpointAutoConfigurationTests method runCreatesReactiveHealthEndpointWebExtension.

@Test
void runCreatesReactiveHealthEndpointWebExtension() {
    this.reactiveContextRunner.run((context) -> {
        ReactiveHealthEndpointWebExtension webExtension = context.getBean(ReactiveHealthEndpointWebExtension.class);
        Mono<WebEndpointResponse<? extends HealthComponent>> response = webExtension.health(ApiVersion.V3, WebServerNamespace.SERVER, SecurityContext.NONE, true, "simple");
        Health health = (Health) (response.block().getBody());
        assertThat(health.getDetails()).containsEntry("counter", 42);
    });
}
Also used : HealthComponent(org.springframework.boot.actuate.health.HealthComponent) Health(org.springframework.boot.actuate.health.Health) WebEndpointResponse(org.springframework.boot.actuate.endpoint.web.WebEndpointResponse) ReactiveHealthEndpointWebExtension(org.springframework.boot.actuate.health.ReactiveHealthEndpointWebExtension) Test(org.junit.jupiter.api.Test)

Aggregations

WebEndpointResponse (org.springframework.boot.actuate.endpoint.web.WebEndpointResponse)4 Test (org.junit.jupiter.api.Test)2 ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)2 HealthComponent (org.springframework.boot.actuate.health.HealthComponent)2 ReactiveHealthEndpointWebExtension (org.springframework.boot.actuate.health.ReactiveHealthEndpointWebExtension)2 MetricFamilySamples (io.prometheus.client.Collector.MetricFamilySamples)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 CacheEntry (org.springframework.boot.actuate.cache.CachesEndpoint.CacheEntry)1 Health (org.springframework.boot.actuate.health.Health)1