Search in sources :

Example 6 with MicrometerRegistry

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

the class StyxBackendServiceClientFactoryTest method setUp.

@BeforeEach
public void setUp() {
    connectionFactory = mock(Connection.Factory.class);
    environment = new Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).build();
    backendService = newBackendServiceBuilder().origins(newOriginBuilder("localhost", 8081).build()).build();
    when(connectionFactory.createConnection(any(Origin.class), any(ConnectionSettings.class))).thenReturn(Mono.just(mock(Connection.class)));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) CachingOriginStatsFactory(com.hotels.styx.client.OriginStatsFactory.CachingOriginStatsFactory) ConnectionPools.simplePoolFactory(com.hotels.styx.client.connectionpool.ConnectionPools.simplePoolFactory) OriginStatsFactory(com.hotels.styx.client.OriginStatsFactory) Environment(com.hotels.styx.Environment) ConnectionSettings(com.hotels.styx.client.ConnectionSettings) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with MicrometerRegistry

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

the class StyxBackendServiceClientFactoryTest method usesTheOriginSpecifiedInTheOriginsRestrictionCookie.

@Test
public void usesTheOriginSpecifiedInTheOriginsRestrictionCookie() {
    MapBackedConfiguration config = new MapBackedConfiguration();
    config.set("originRestrictionCookie", ORIGINS_RESTRICTION_COOKIE);
    environment = new Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).configuration(new StyxConfig(config)).build();
    BackendService backendService = newBackendServiceBuilder().origins(newOriginBuilder("localhost", 9091).id("x").build(), newOriginBuilder("localhost", 9092).id("y").build(), newOriginBuilder("localhost", 9093).id("z").build()).build();
    BackendServiceClient styxBackendServiceClient = new StyxBackendServiceClientFactory(environment).createClient(backendService, newOriginsInventoryBuilder(environment.centralisedMetrics(), backendService).hostClientFactory((pool) -> {
        if (pool.getOrigin().id().equals(id("x"))) {
            return hostClient(response(OK).header("X-Origin-Id", "x").build());
        } else if (pool.getOrigin().id().equals(id("y"))) {
            return hostClient(response(OK).header("X-Origin-Id", "y").build());
        } else {
            return hostClient(response(OK).header("X-Origin-Id", "z").build());
        }
    }).build(), new CachingOriginStatsFactory(environment.centralisedMetrics()));
    LiveHttpRequest requestz = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("z").toString())).build();
    LiveHttpRequest requestx = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("x").toString())).build();
    LiveHttpRequest requesty = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("y").toString())).build();
    LiveHttpResponse responsez = Mono.from(styxBackendServiceClient.sendRequest(requestz, requestContext())).block();
    LiveHttpResponse responsex = Mono.from(styxBackendServiceClient.sendRequest(requestx, requestContext())).block();
    LiveHttpResponse responsey = Mono.from(styxBackendServiceClient.sendRequest(requesty, requestContext())).block();
    assertThat(responsex.header("X-Origin-Id").get(), is("x"));
    assertThat(responsey.header("X-Origin-Id").get(), is("y"));
    assertThat(responsez.header("X-Origin-Id").get(), is("z"));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) StyxConfig(com.hotels.styx.StyxConfig) StyxBackendServiceClient(com.hotels.styx.client.StyxBackendServiceClient) BackendServiceClient(com.hotels.styx.client.BackendServiceClient) CachingOriginStatsFactory(com.hotels.styx.client.OriginStatsFactory.CachingOriginStatsFactory) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) OriginsInventory.newOriginsInventoryBuilder(com.hotels.styx.client.OriginsInventory.newOriginsInventoryBuilder) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) BackendService.newBackendServiceBuilder(com.hotels.styx.api.extension.service.BackendService.newBackendServiceBuilder) StickySessionConfig.newStickySessionConfigBuilder(com.hotels.styx.api.extension.service.StickySessionConfig.newStickySessionConfigBuilder) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MapBackedConfiguration(com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 8 with MicrometerRegistry

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

the class FileBackedBackendServicesRegistryFactoryTest method instantiatesFromYaml.

@Test
public void instantiatesFromYaml() {
    environment = new com.hotels.styx.Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).configuration(StyxConfig.fromYaml("config: {originsFile: '${CONFIG_LOCATION:classpath:}/conf/origins/backend-factory-origins.yml'}", false)).build();
    JsonNodeConfig factoryConfig = new JsonNodeConfig(environment.configuration().get("config", JsonNode.class).get());
    Registry registry = new FileBackedBackendServicesRegistry.Factory().create(environment, factoryConfig);
    assertThat(registry != null, is(true));
}
Also used : MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) JsonNodeConfig(com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Registry(com.hotels.styx.api.extension.service.spi.Registry) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) Test(org.junit.jupiter.api.Test)

Example 9 with MicrometerRegistry

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

the class InterceptorPipelineBuilderTest method setUp.

@BeforeEach
public void setUp() {
    environment = new Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).configuration(StyxConfig.defaultConfig()).build();
    plugins = List.of(namedPlugin("plug1", (request, chain) -> chain.proceed(request).map(response -> response.newBuilder().header("plug1", "1").build())), namedPlugin("plug2", (request, chain) -> chain.proceed(request).map(response -> response.newBuilder().header("plug2", "1").build())));
    handler = mock(RoutingObject.class);
    when(handler.handle(any(LiveHttpRequest.class), any(HttpInterceptor.Context.class))).thenReturn(Eventual.of(response(OK).build()));
}
Also used : RoutingObject(com.hotels.styx.routing.RoutingObject) BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) LiveHttpResponse.response(com.hotels.styx.api.LiveHttpResponse.response) StyxConfig(com.hotels.styx.StyxConfig) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) Support.requestContext(com.hotels.styx.support.Support.requestContext) LiveHttpRequest.get(com.hotels.styx.api.LiveHttpRequest.get) NamedPlugin.namedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Eventual(com.hotels.styx.api.Eventual) HttpHandler(com.hotels.styx.api.HttpHandler) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Test(org.junit.jupiter.api.Test) Matchers.any(org.mockito.Matchers.any) List(java.util.List) IsOptional.isValue(com.hotels.styx.support.matchers.IsOptional.isValue) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Environment(com.hotels.styx.Environment) OK(com.hotels.styx.api.HttpResponseStatus.OK) Matchers.is(org.hamcrest.Matchers.is) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Mockito.mock(org.mockito.Mockito.mock) RoutingObject(com.hotels.styx.routing.RoutingObject) Support.requestContext(com.hotels.styx.support.Support.requestContext) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with MicrometerRegistry

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

the class StyxServerComponentsTest method loadsPlugins.

@Test
public void loadsPlugins() {
    ConfiguredPluginFactory f1 = new ConfiguredPluginFactory("plugin1", any -> stubPlugin("MyResponse1"));
    ConfiguredPluginFactory f2 = new ConfiguredPluginFactory("plugin2", any -> stubPlugin("MyResponse2"));
    StyxServerComponents components = new StyxServerComponents.Builder().registry(new MicrometerRegistry(new CompositeMeterRegistry())).styxConfig(new StyxConfig()).pluginFactories(List.of(f1, f2)).build();
    List<NamedPlugin> plugins = components.plugins();
    List<String> names = plugins.stream().map(NamedPlugin::name).collect(toList());
    assertThat(names, contains("plugin1", "plugin2"));
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) StyxConfig(com.hotels.styx.StyxConfig) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) ConfiguredPluginFactory(com.hotels.styx.startup.extensions.ConfiguredPluginFactory) Test(org.junit.jupiter.api.Test)

Aggregations

MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)28 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)21 Test (org.junit.jupiter.api.Test)16 CentralisedMetrics (com.hotels.styx.metrics.CentralisedMetrics)12 BeforeEach (org.junit.jupiter.api.BeforeEach)11 Environment (com.hotels.styx.Environment)8 StyxConfig (com.hotels.styx.StyxConfig)7 MeterRegistry (com.hotels.styx.api.MeterRegistry)7 CompositeMeterRegistry (io.micrometer.core.instrument.composite.CompositeMeterRegistry)7 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)3 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)3 NamedPlugin (com.hotels.styx.proxy.plugin.NamedPlugin)3 List (java.util.List)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 Eventual (com.hotels.styx.api.Eventual)2 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)2 Configuration (com.hotels.styx.api.configuration.Configuration)2 BackendService (com.hotels.styx.api.extension.service.BackendService)2 BackendService.newBackendServiceBuilder (com.hotels.styx.api.extension.service.BackendService.newBackendServiceBuilder)2 StyxService (com.hotels.styx.api.extension.service.spi.StyxService)2