Search in sources :

Example 1 with MeterRegistry

use of com.hotels.styx.api.MeterRegistry in project styx by ExpediaGroup.

the class SimpleConnectionPoolFactoryTest method registersMetricsUnderOriginsScope.

@Test
public void registersMetricsUnderOriginsScope() {
    MeterRegistry meterRegistry = new MicrometerRegistry(new SimpleMeterRegistry());
    SimpleConnectionPoolFactory factory = new SimpleConnectionPoolFactory.Builder().connectionFactory(mock(Connection.Factory.class)).connectionPoolSettings(defaultConnectionPoolSettings()).metrics(new CentralisedMetrics(meterRegistry)).build();
    factory.create(origin);
    Tags tags = Tags.of("appId", "test-app", "originId", "origin-X");
    assertThat(meterRegistry.find("proxy.client.connectionpool.pendingConnections").tags(tags).gauge(), notNullValue());
    assertThat(meterRegistry.find("proxy.client.connectionpool.availableConnections").tags(tags).gauge(), notNullValue());
    assertThat(meterRegistry.find("proxy.client.connectionpool.busyConnections").tags(tags).gauge(), notNullValue());
    assertThat(meterRegistry.find("proxy.client.connectionpool.connectionsInEstablishment").tags(tags).gauge(), notNullValue());
}
Also used : MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) Connection(com.hotels.styx.client.Connection) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Tags(io.micrometer.core.instrument.Tags) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(com.hotels.styx.api.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 2 with MeterRegistry

use of com.hotels.styx.api.MeterRegistry in project styx by ExpediaGroup.

the class HttpPipelineHandlerTest method updatesRequestsOngoingCountOnChannelReadEvent.

@Test
public void updatesRequestsOngoingCountOnChannelReadEvent() throws Exception {
    MeterRegistry registry = new MicrometerRegistry(new SimpleMeterRegistry());
    HttpPipelineHandler pipelineHandler = handlerWithMocks(doNotRespondHandler).responseEnhancer(DO_NOT_MODIFY_RESPONSE).progressListener(new RequestStatsCollector(new CentralisedMetrics(registry))).build();
    ChannelHandlerContext ctx = mockCtx();
    pipelineHandler.channelActive(ctx);
    pipelineHandler.channelRead0(ctx, get("/foo").build());
    assertThat(requestOutstandingValue(registry), is(1.0));
}
Also used : RequestStatsCollector(com.hotels.styx.server.RequestStatsCollector) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(com.hotels.styx.api.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 3 with MeterRegistry

use of com.hotels.styx.api.MeterRegistry in project styx by ExpediaGroup.

the class BackendServicesRouterTest method deregistersAndReregistersMetricsAppropriately.

// This test exists due to a real bug we had when reloading in prod
@Test
public void deregistersAndReregistersMetricsAppropriately() {
    MeterRegistry metrics = new MicrometerRegistry(new SimpleMeterRegistry());
    Environment environment = new Environment.Builder().registry(metrics).build();
    MeterRegistry meterRegistry = environment.meterRegistry();
    BackendServicesRouter router = new BackendServicesRouter(new StyxBackendServiceClientFactory(environment), environment, executor);
    router.onChange(added(backendService(APP_B, "/appB/", 9094, "appB-01", 9095, "appB-02")));
    Tags tags01 = Tags.of(APPID_TAG, APP_B, ORIGINID_TAG, "appB-01");
    Tags tags02 = Tags.of(APPID_TAG, APP_B, ORIGINID_TAG, "appB-02");
    assertThat(meterRegistry.find("proxy.client.originHealthStatus").tags(tags01).gauge().value(), is(1.0));
    assertThat(meterRegistry.find("proxy.client.originHealthStatus").tags(tags02).gauge().value(), is(1.0));
    BackendService appMinusOneOrigin = backendService(APP_B, "/appB/", 9094, "appB-01");
    router.onChange(updated(appMinusOneOrigin));
    assertThat(meterRegistry.find("proxy.client.originHealthStatus").tags(tags01).gauge().value(), is(1.0));
    assertThat(meterRegistry.find("proxy.client.originHealthStatus").tags(tags02).gauge(), is(nullValue()));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) BackendService.newBackendServiceBuilder(com.hotels.styx.api.extension.service.BackendService.newBackendServiceBuilder) Environment(com.hotels.styx.Environment) Tags(io.micrometer.core.instrument.Tags) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(com.hotels.styx.api.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 4 with MeterRegistry

use of com.hotels.styx.api.MeterRegistry in project styx by ExpediaGroup.

the class HttpPipelineHandlerTest method decrementsRequestsOngoingOnExceptionCaught.

@Test
public void decrementsRequestsOngoingOnExceptionCaught() throws Exception {
    MeterRegistry registry = new MicrometerRegistry(new SimpleMeterRegistry());
    HttpPipelineHandler adapter = handlerWithMocks(doNotRespondHandler).progressListener(new RequestStatsCollector(new CentralisedMetrics(registry))).build();
    ChannelHandlerContext ctx = mockCtx();
    adapter.channelActive(ctx);
    LiveHttpRequest request = get("/foo").build();
    adapter.channelRead0(ctx, request);
    assertThat(requestOutstandingValue(registry), is(1.0));
    adapter.exceptionCaught(ctx, new Throwable("Exception"));
    assertThat(requestOutstandingValue(registry), is(0.0));
    adapter.channelInactive(ctx);
    assertThat(requestOutstandingValue(registry), is(0.0));
    verify(responseEnhancer).enhance(any(LiveHttpResponse.Transformer.class), eq(request));
}
Also used : RequestStatsCollector(com.hotels.styx.server.RequestStatsCollector) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(com.hotels.styx.api.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 5 with MeterRegistry

use of com.hotels.styx.api.MeterRegistry in project styx by ExpediaGroup.

the class HttpPipelineHandlerTest method decrementsRequestsOngoingCountOnChannelInactiveWhenRequestIsOngoing.

@Test
public void decrementsRequestsOngoingCountOnChannelInactiveWhenRequestIsOngoing() throws Exception {
    MeterRegistry registry = new MicrometerRegistry(new SimpleMeterRegistry());
    HttpPipelineHandler adapter = handlerWithMocks(doNotRespondHandler).responseEnhancer(DO_NOT_MODIFY_RESPONSE).progressListener(new RequestStatsCollector(new CentralisedMetrics(registry))).build();
    ChannelHandlerContext ctx = mockCtx();
    adapter.channelActive(ctx);
    adapter.channelRead0(ctx, get("/foo").build());
    assertThat(requestOutstandingValue(registry), is(1.0));
    adapter.channelInactive(ctx);
    assertThat(requestOutstandingValue(registry), is(0.0));
}
Also used : RequestStatsCollector(com.hotels.styx.server.RequestStatsCollector) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(com.hotels.styx.api.MeterRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

MeterRegistry (com.hotels.styx.api.MeterRegistry)7 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)7 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)7 Test (org.junit.jupiter.api.Test)7 CentralisedMetrics (com.hotels.styx.metrics.CentralisedMetrics)6 RequestStatsCollector (com.hotels.styx.server.RequestStatsCollector)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)2 Tags (io.micrometer.core.instrument.Tags)2 Environment (com.hotels.styx.Environment)1 Version (com.hotels.styx.Version)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 BackendService (com.hotels.styx.api.extension.service.BackendService)1 BackendService.newBackendServiceBuilder (com.hotels.styx.api.extension.service.BackendService.newBackendServiceBuilder)1 Connection (com.hotels.styx.client.Connection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.hasItems (org.hamcrest.Matchers.hasItems)1 Matchers.hasSize (org.hamcrest.Matchers.hasSize)1