Search in sources :

Example 1 with MemoryBackedRegistry

use of com.hotels.styx.infrastructure.MemoryBackedRegistry in project styx by ExpediaGroup.

the class StyxServerTest method disablesResourceLeakDetectionByDefault.

@Test
public void disablesResourceLeakDetectionByDefault() {
    StyxServerComponents config = new StyxServerComponents.Builder().registry(new MicrometerRegistry(new CompositeMeterRegistry())).configuration(EMPTY_CONFIGURATION).additionalServices(Map.of("backendServiceRegistry", new RegistryServiceAdapter(new MemoryBackedRegistry<>()))).build();
    new StyxServer(config);
    assertThat(ResourceLeakDetector.getLevel(), is(DISABLED));
}
Also used : StyxServerComponents(com.hotels.styx.startup.StyxServerComponents) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry) RegistryServiceAdapter(com.hotels.styx.infrastructure.RegistryServiceAdapter) Test(org.junit.jupiter.api.Test)

Example 2 with MemoryBackedRegistry

use of com.hotels.styx.infrastructure.MemoryBackedRegistry in project styx by ExpediaGroup.

the class DashboardDataSupplierTest method originsHaveStatuses.

@Test
public void originsHaveStatuses() throws JsonProcessingException {
    MemoryBackedRegistry<BackendService> registry = new MemoryBackedRegistry<>();
    DashboardDataSupplier supplier = new DashboardDataSupplier(registry, environment, styxConfig);
    Origin foo1 = origin("foo1");
    Origin foo2 = origin("foo2");
    registry.add(backend("foo", foo1, foo2));
    registry.add(backend("bar", origin("bar1")));
    // Set statuses
    environment.eventBus().post(new OriginsSnapshot(id("foo"), pools(foo1), pools(foo2), pools()));
    DashboardData.Downstream downstream = supplier.get().downstream();
    DashboardData.Backend fooBackend = downstream.backend("STYXPRES-foo");
    assertThat(downstream.backendIds(), containsInAnyOrder("STYXPRES-foo", "STYXPRES-bar"));
    assertThat(fooBackend.statusesByOriginId(), is(equalTo(Map.of("foo1", "active", "foo2", "inactive"))));
    assertThat(fooBackend.origin("foo1").status(), is("active"));
    // Set statuses again
    environment.eventBus().post(new OriginsSnapshot(id("foo"), pools(), pools(foo1), pools(foo2)));
    fooBackend = supplier.get().downstream().backend("STYXPRES-foo");
    assertThat(fooBackend.statusesByOriginId(), is(equalTo(Map.of("foo1", "inactive", "foo2", "disabled"))));
    assertThat(fooBackend.origin("foo1").status(), is("inactive"));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) BackendService(com.hotels.styx.api.extension.service.BackendService) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry) OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) Test(org.junit.jupiter.api.Test)

Example 3 with MemoryBackedRegistry

use of com.hotels.styx.infrastructure.MemoryBackedRegistry in project styx by ExpediaGroup.

the class StyxPipelineFactory method configuredPipeline.

private RoutingObject configuredPipeline(RoutingObjectFactory.Context routingObjectFactoryContext) {
    boolean requestTracking = environment.configuration().get("requestTracking", Boolean.class).orElse(false);
    Optional<JsonNode> rootHandlerNode = environment.configuration().get("httpPipeline", JsonNode.class);
    if (rootHandlerNode.isPresent()) {
        return Builtins.build(List.of("httpPipeline"), routingObjectFactoryContext, toRoutingConfigNode(rootHandlerNode.get()));
    }
    Registry<BackendService> registry = (Registry<BackendService>) services.get("backendServiceRegistry");
    return new StaticPipelineFactory(environment, registry != null ? registry : new MemoryBackedRegistry<>(), plugins, executor, requestTracking).build();
}
Also used : StaticPipelineFactory(com.hotels.styx.routing.StaticPipelineFactory) BackendService(com.hotels.styx.api.extension.service.BackendService) JsonNode(com.fasterxml.jackson.databind.JsonNode) Registry(com.hotels.styx.api.extension.service.spi.Registry) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry)

Example 4 with MemoryBackedRegistry

use of com.hotels.styx.infrastructure.MemoryBackedRegistry in project styx by ExpediaGroup.

the class DashboardDataTest method unsubscribesFromEventBus.

@Test
public void unsubscribesFromEventBus() {
    EventBus eventBus = mock(EventBus.class);
    MemoryBackedRegistry<BackendService> backendServicesRegistry = new MemoryBackedRegistry<>();
    backendServicesRegistry.add(application("app", origin("app-01", "localhost", 9090)));
    backendServicesRegistry.add(application("test", origin("test-01", "localhost", 9090)));
    DashboardData dashbaord = new DashboardData(metricRegistry, backendServicesRegistry, "styx-prod1-presentation-01", new Version("releaseTag"), eventBus);
    // Twice for each backend. One during backend construction, another from BackendServicesRegistry listener callback.
    verify(eventBus, times(4)).register(any(DashboardData.Origin.class));
    dashbaord.unregister();
    verify(eventBus, times(4)).unregister(any(DashboardData.Origin.class));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) BackendService(com.hotels.styx.api.extension.service.BackendService) Version(com.hotels.styx.Version) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry) EventBus(com.google.common.eventbus.EventBus) Test(org.junit.jupiter.api.Test)

Example 5 with MemoryBackedRegistry

use of com.hotels.styx.infrastructure.MemoryBackedRegistry in project styx by ExpediaGroup.

the class DashboardDataTest method providesBackendTotalConnections.

@Test
public void providesBackendTotalConnections() {
    BackendServices backendServices = newBackendServices(application("app", origin("app-01", "localhost", 9090), origin("app-02", "localhost", 9091)));
    MemoryBackedRegistry<BackendService> backendServicesRegistry = new MemoryBackedRegistry<>();
    backendServices.forEach(backendServicesRegistry::add);
    metricRegistry.register("origins.app.app-01.connectionspool.available-connections", gauge(100));
    metricRegistry.register("origins.app.app-01.connectionspool.busy-connections", gauge(300));
    metricRegistry.register("origins.app.app-01.connectionspool.pending-connections", gauge(500));
    metricRegistry.register("origins.app.app-02.connectionspool.available-connections", gauge(200));
    metricRegistry.register("origins.app.app-02.connectionspool.busy-connections", gauge(400));
    metricRegistry.register("origins.app.app-02.connectionspool.pending-connections", gauge(600));
    DashboardData.Backend backend = newDashboardData(backendServicesRegistry).downstream().firstBackend();
    DashboardData.ConnectionsPoolsAggregate connectionsPool = backend.totalConnections();
    assertThat(connectionsPool.available(), is(300));
    assertThat(connectionsPool.busy(), is(700));
    assertThat(connectionsPool.pending(), is(1100));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) BackendServices(com.hotels.styx.applications.BackendServices) BackendServices.newBackendServices(com.hotels.styx.applications.BackendServices.newBackendServices) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

MemoryBackedRegistry (com.hotels.styx.infrastructure.MemoryBackedRegistry)7 BackendService (com.hotels.styx.api.extension.service.BackendService)6 Test (org.junit.jupiter.api.Test)6 Origin (com.hotels.styx.api.extension.Origin)2 OriginsSnapshot (com.hotels.styx.api.extension.OriginsSnapshot)2 BackendServices (com.hotels.styx.applications.BackendServices)2 BackendServices.newBackendServices (com.hotels.styx.applications.BackendServices.newBackendServices)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 EventBus (com.google.common.eventbus.EventBus)1 Version (com.hotels.styx.Version)1 HttpResponse (com.hotels.styx.api.HttpResponse)1 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)1 Registry (com.hotels.styx.api.extension.service.spi.Registry)1 RegistryServiceAdapter (com.hotels.styx.infrastructure.RegistryServiceAdapter)1 StaticPipelineFactory (com.hotels.styx.routing.StaticPipelineFactory)1 StyxServerComponents (com.hotels.styx.startup.StyxServerComponents)1 CompositeMeterRegistry (io.micrometer.core.instrument.composite.CompositeMeterRegistry)1