Search in sources :

Example 1 with CentralisedMetrics

use of com.hotels.styx.metrics.CentralisedMetrics in project styx by ExpediaGroup.

the class OriginsInventoryTest method stopsMonitoringAndUnregistersWhenClosed.

@Test
public void stopsMonitoringAndUnregistersWhenClosed() {
    ConnectionPool.Factory connectionFactory = mock(ConnectionPool.Factory.class);
    ConnectionPool pool1 = mock(ConnectionPool.class);
    when(pool1.getOrigin()).thenReturn(ORIGIN_1);
    ConnectionPool pool2 = mock(ConnectionPool.class);
    when(pool2.getOrigin()).thenReturn(ORIGIN_2);
    when(connectionFactory.create(eq(ORIGIN_1))).thenReturn(pool1);
    when(connectionFactory.create(eq(ORIGIN_2))).thenReturn(pool2);
    inventory = new OriginsInventory(eventBus, GENERIC_APP, monitor, connectionFactory, hostClientFactory, new CentralisedMetrics(meterRegistry));
    inventory.setOrigins(ORIGIN_1, ORIGIN_2);
    inventory.close();
    verify(monitor).stopMonitoring(eq(Set.of(ORIGIN_1)));
    verify(monitor).stopMonitoring(eq(Set.of(ORIGIN_2)));
    assertThat(gaugeValue("generic-app", "app-01"), isAbsent());
    assertThat(gaugeValue("generic-app", "app-02"), isAbsent());
    verify(pool1).close();
    verify(pool2).close();
    verify(eventBus, times(2)).post(any(OriginsSnapshot.class));
    verify(eventBus).unregister(eq(inventory));
}
Also used : ConnectionPool(com.hotels.styx.client.connectionpool.ConnectionPool) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) Test(org.junit.jupiter.api.Test)

Example 2 with CentralisedMetrics

use of com.hotels.styx.metrics.CentralisedMetrics in project styx by ExpediaGroup.

the class OriginsInventoryTest method shutsConnectionPoolForModifiedOrigin.

@Test
public void shutsConnectionPoolForModifiedOrigin() {
    Origin originV1 = newOriginBuilder("acme01.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
    Origin originV2 = newOriginBuilder("acme02.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
    ConnectionPool.Factory connectionFactory = mock(ConnectionPool.Factory.class);
    ConnectionPool pool1 = mock(ConnectionPool.class);
    ConnectionPool pool2 = mock(ConnectionPool.class);
    when(connectionFactory.create(eq(originV1))).thenReturn(pool1);
    when(connectionFactory.create(eq(originV2))).thenReturn(pool2);
    inventory = new OriginsInventory(eventBus, GENERIC_APP, monitor, connectionFactory, hostClientFactory, new CentralisedMetrics(meterRegistry));
    inventory.setOrigins(originV1);
    verify(connectionFactory).create(eq(originV1));
    inventory.setOrigins(originV2);
    verify(connectionFactory).create(eq(originV2));
    verify(pool1).close();
}
Also used : DisableOrigin(com.hotels.styx.client.origincommands.DisableOrigin) EnableOrigin(com.hotels.styx.client.origincommands.EnableOrigin) Origin(com.hotels.styx.api.extension.Origin) ConnectionPool(com.hotels.styx.client.connectionpool.ConnectionPool) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Test(org.junit.jupiter.api.Test)

Example 3 with CentralisedMetrics

use of com.hotels.styx.metrics.CentralisedMetrics in project styx by ExpediaGroup.

the class OriginsInventoryTest method setUp.

@BeforeEach
public void setUp() {
    meterRegistry = new MicrometerRegistry(new SimpleMeterRegistry());
    logger = new LoggingTestSupport(OriginsInventory.class);
    monitor = mock(OriginHealthStatusMonitor.class);
    eventBus = mock(EventBus.class);
    inventory = new OriginsInventory(eventBus, GENERIC_APP, monitor, connectionFactory, hostClientFactory, new CentralisedMetrics(meterRegistry));
}
Also used : MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) OriginHealthStatusMonitor(com.hotels.styx.client.healthcheck.OriginHealthStatusMonitor) EventBus(com.google.common.eventbus.EventBus) LoggingTestSupport(com.hotels.styx.support.matchers.LoggingTestSupport) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with CentralisedMetrics

use of com.hotels.styx.metrics.CentralisedMetrics in project styx by ExpediaGroup.

the class StyxBackendServiceClientTest method setUp.

@BeforeEach
public void setUp() {
    meterRegistry = new MicrometerRegistry(new SimpleMeterRegistry());
    metrics = new CentralisedMetrics(meterRegistry);
}
Also used : MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with CentralisedMetrics

use of com.hotels.styx.metrics.CentralisedMetrics 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)

Aggregations

CentralisedMetrics (com.hotels.styx.metrics.CentralisedMetrics)15 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)12 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)12 Test (org.junit.jupiter.api.Test)9 MeterRegistry (com.hotels.styx.api.MeterRegistry)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 ConnectionPool (com.hotels.styx.client.connectionpool.ConnectionPool)3 RequestStatsCollector (com.hotels.styx.server.RequestStatsCollector)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 Origin (com.hotels.styx.api.extension.Origin)2 DisableOrigin (com.hotels.styx.client.origincommands.DisableOrigin)2 EnableOrigin (com.hotels.styx.client.origincommands.EnableOrigin)2 EventBus (com.google.common.eventbus.EventBus)1 Version (com.hotels.styx.Version)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)1 OriginsSnapshot (com.hotels.styx.api.extension.OriginsSnapshot)1 Connection (com.hotels.styx.client.Connection)1 OriginHealthStatusMonitor (com.hotels.styx.client.healthcheck.OriginHealthStatusMonitor)1 LoggingTestSupport (com.hotels.styx.support.matchers.LoggingTestSupport)1