Search in sources :

Example 1 with HttpClient

use of com.hotels.styx.client.HttpClient in project styx by ExpediaGroup.

the class MetricsSnapshot method downloadFrom.

public static MetricsSnapshot downloadFrom(String host, int port) throws IOException {
    HttpClient client = new StyxHttpClient.Builder().build();
    HttpResponse response = await(client.sendRequest(get(format("http://%s:%d/admin/metrics", host, port)).build()));
    return new MetricsSnapshot(decodeToMap(response.bodyAs(UTF_8)));
}
Also used : StyxHttpClient(com.hotels.styx.client.StyxHttpClient) StyxHttpClient(com.hotels.styx.client.StyxHttpClient) HttpClient(com.hotels.styx.client.HttpClient) HttpResponse(com.hotels.styx.api.HttpResponse)

Example 2 with HttpClient

use of com.hotels.styx.client.HttpClient in project styx by ExpediaGroup.

the class UrlRequestHealthCheckTest method declaredOriginUnhealthyOnTransportException.

@Test
public void declaredOriginUnhealthyOnTransportException() {
    HttpClient client = request -> respondWith(new RuntimeException("health check failure, as expected"));
    new UrlRequestHealthCheck("/version.txt", metrics).check(client, someOrigin, state -> this.originState = state);
    assertThat(originState, is(UNHEALTHY));
    assertThat(metrics.getRegistry().find("proxy.client.originHealthCheckFailures").tags("originId", someOrigin.id().toString(), "appId", someOrigin.applicationId().toString()).counter().count(), is(1.0));
    assertThat(meters(id -> id.getName().equals("proxy.client.originHealthCheckFailures")).size(), is(1));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) HttpResponse(com.hotels.styx.api.HttpResponse) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) OriginState(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState) Predicate(java.util.function.Predicate) HttpResponse.response(com.hotels.styx.api.HttpResponse.response) NOT_FOUND(com.hotels.styx.api.HttpResponseStatus.NOT_FOUND) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) Meter(io.micrometer.core.instrument.Meter) CompletableFuture(java.util.concurrent.CompletableFuture) HttpClient(com.hotels.styx.client.HttpClient) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) Collectors(java.util.stream.Collectors) UNHEALTHY(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.UNHEALTHY) Test(org.junit.jupiter.api.Test) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Origin(com.hotels.styx.api.extension.Origin) OK(com.hotels.styx.api.HttpResponseStatus.OK) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Matchers.is(org.hamcrest.Matchers.is) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HEALTHY(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.HEALTHY) HttpClient(com.hotels.styx.client.HttpClient) Test(org.junit.jupiter.api.Test)

Example 3 with HttpClient

use of com.hotels.styx.client.HttpClient in project styx by ExpediaGroup.

the class UrlRequestHealthCheckTest method declaresOriginUnhealthyOnNon200Ok.

@Test
public void declaresOriginUnhealthyOnNon200Ok() {
    HttpClient client = request -> respondWith(NOT_FOUND);
    new UrlRequestHealthCheck("/version.txt", metrics).check(client, someOrigin, state -> this.originState = state);
    assertThat(originState, is(UNHEALTHY));
    assertThat(metrics.getRegistry().find("proxy.client.originHealthCheckFailures").tags("originId", someOrigin.id().toString(), "appId", someOrigin.applicationId().toString()).counter().count(), is(1.0));
    assertThat(meters(id -> id.getName().equals("proxy.client.originHealthCheckFailures")).size(), is(1));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) HttpResponse(com.hotels.styx.api.HttpResponse) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) OriginState(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState) Predicate(java.util.function.Predicate) HttpResponse.response(com.hotels.styx.api.HttpResponse.response) NOT_FOUND(com.hotels.styx.api.HttpResponseStatus.NOT_FOUND) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) Meter(io.micrometer.core.instrument.Meter) CompletableFuture(java.util.concurrent.CompletableFuture) HttpClient(com.hotels.styx.client.HttpClient) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) Collectors(java.util.stream.Collectors) UNHEALTHY(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.UNHEALTHY) Test(org.junit.jupiter.api.Test) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Origin(com.hotels.styx.api.extension.Origin) OK(com.hotels.styx.api.HttpResponseStatus.OK) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Matchers.is(org.hamcrest.Matchers.is) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HEALTHY(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.HEALTHY) HttpClient(com.hotels.styx.client.HttpClient) Test(org.junit.jupiter.api.Test)

Example 4 with HttpClient

use of com.hotels.styx.client.HttpClient in project styx by ExpediaGroup.

the class UrlRequestHealthCheckTest method sendsTheHealthCheckRequestToTheGivenUrl.

@Test
public void sendsTheHealthCheckRequestToTheGivenUrl() {
    HttpClient client = request -> {
        requestedUrl = request.url().path();
        return respondWith(NOT_FOUND);
    };
    new UrlRequestHealthCheck("/version-foo.txt", metrics).check(client, someOrigin, state -> {
    });
    assertThat(requestedUrl, is("/version-foo.txt"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) HttpResponse(com.hotels.styx.api.HttpResponse) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) OriginState(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState) Predicate(java.util.function.Predicate) HttpResponse.response(com.hotels.styx.api.HttpResponse.response) NOT_FOUND(com.hotels.styx.api.HttpResponseStatus.NOT_FOUND) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) Meter(io.micrometer.core.instrument.Meter) CompletableFuture(java.util.concurrent.CompletableFuture) HttpClient(com.hotels.styx.client.HttpClient) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) Collectors(java.util.stream.Collectors) UNHEALTHY(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.UNHEALTHY) Test(org.junit.jupiter.api.Test) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Origin(com.hotels.styx.api.extension.Origin) OK(com.hotels.styx.api.HttpResponseStatus.OK) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Matchers.is(org.hamcrest.Matchers.is) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HEALTHY(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.HEALTHY) HttpClient(com.hotels.styx.client.HttpClient) Test(org.junit.jupiter.api.Test)

Example 5 with HttpClient

use of com.hotels.styx.client.HttpClient in project styx by ExpediaGroup.

the class UrlRequestHealthCheckTest method declaresOriginHealthyOnOkResponseCode.

@Test
public void declaresOriginHealthyOnOkResponseCode() {
    HttpClient client = request -> respondWith(OK);
    new UrlRequestHealthCheck("/version.txt", metrics).check(client, someOrigin, state -> this.originState = state);
    assertThat(originState, is(HEALTHY));
    assertThat(meters(id -> id.getName().equals("proxy.client.originHealthCheckFailures")).size(), is(0));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) HttpResponse(com.hotels.styx.api.HttpResponse) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) OriginState(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState) Predicate(java.util.function.Predicate) HttpResponse.response(com.hotels.styx.api.HttpResponse.response) NOT_FOUND(com.hotels.styx.api.HttpResponseStatus.NOT_FOUND) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) Meter(io.micrometer.core.instrument.Meter) CompletableFuture(java.util.concurrent.CompletableFuture) HttpClient(com.hotels.styx.client.HttpClient) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) Collectors(java.util.stream.Collectors) UNHEALTHY(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.UNHEALTHY) Test(org.junit.jupiter.api.Test) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Origin(com.hotels.styx.api.extension.Origin) OK(com.hotels.styx.api.HttpResponseStatus.OK) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Matchers.is(org.hamcrest.Matchers.is) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HEALTHY(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.HEALTHY) HttpClient(com.hotels.styx.client.HttpClient) Test(org.junit.jupiter.api.Test)

Aggregations

HttpResponse (com.hotels.styx.api.HttpResponse)5 HttpClient (com.hotels.styx.client.HttpClient)5 HttpResponse.response (com.hotels.styx.api.HttpResponse.response)4 HttpResponseStatus (com.hotels.styx.api.HttpResponseStatus)4 NOT_FOUND (com.hotels.styx.api.HttpResponseStatus.NOT_FOUND)4 OK (com.hotels.styx.api.HttpResponseStatus.OK)4 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)4 Origin (com.hotels.styx.api.extension.Origin)4 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)4 OriginState (com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState)4 HEALTHY (com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.HEALTHY)4 UNHEALTHY (com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.UNHEALTHY)4 CentralisedMetrics (com.hotels.styx.metrics.CentralisedMetrics)4 Meter (io.micrometer.core.instrument.Meter)4 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)4 List (java.util.List)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Predicate (java.util.function.Predicate)4 Collectors (java.util.stream.Collectors)4 Collectors.toList (java.util.stream.Collectors.toList)4