Search in sources :

Example 1 with Environment

use of com.hotels.styx.Environment in project styx by ExpediaGroup.

the class PluginLoadingForStartup method loadPlugin.

private static NamedPlugin loadPlugin(Environment environment, ConfiguredPluginFactory factory) {
    PluginFactory.Environment pluginEnvironment = new PluginFactory.Environment() {

        @Override
        public <T> T pluginConfig(Class<T> clazz) {
            return factory.pluginConfig(clazz);
        }

        @Override
        public Configuration configuration() {
            return environment.configuration();
        }

        @Override
        public MeterRegistry pluginMeterRegistry() {
            return environment.meterRegistry().scope("plugin.internal." + factory.name().toLowerCase());
        }

        @Override
        @Deprecated
        public MetricRegistry metricRegistry() {
            return environment.metricRegistry().scope("plugin.internal." + factory.name());
        }
    };
    Plugin plugin = factory.pluginFactory().create(pluginEnvironment);
    return namedPlugin(factory.name(), plugin);
}
Also used : Environment(com.hotels.styx.Environment) PluginFactory(com.hotels.styx.api.plugins.spi.PluginFactory) Plugin(com.hotels.styx.api.plugins.spi.Plugin) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) NamedPlugin.namedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin)

Example 2 with Environment

use of com.hotels.styx.Environment 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 3 with Environment

use of com.hotels.styx.Environment 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 4 with Environment

use of com.hotels.styx.Environment in project styx by ExpediaGroup.

the class InstrumentedPluginTest method setUp.

@BeforeEach
public void setUp() {
    registry = new MicrometerRegistry(new SimpleMeterRegistry());
    environment = new Environment.Builder().registry(registry).build();
    someRequest = get("/").build();
    chain = mock(Chain.class);
}
Also used : Chain(com.hotels.styx.api.HttpInterceptor.Chain) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Environment(com.hotels.styx.Environment) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with Environment

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

Aggregations

Environment (com.hotels.styx.Environment)8 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)6 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Test (org.junit.jupiter.api.Test)4 StyxConfig (com.hotels.styx.StyxConfig)2 NamedPlugin (com.hotels.styx.proxy.plugin.NamedPlugin)2 NamedPlugin.namedPlugin (com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin)2 Eventual (com.hotels.styx.api.Eventual)1 HttpHandler (com.hotels.styx.api.HttpHandler)1 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)1 Chain (com.hotels.styx.api.HttpInterceptor.Chain)1 OK (com.hotels.styx.api.HttpResponseStatus.OK)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 LiveHttpRequest.get (com.hotels.styx.api.LiveHttpRequest.get)1 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)1 LiveHttpResponse.response (com.hotels.styx.api.LiveHttpResponse.response)1 MeterRegistry (com.hotels.styx.api.MeterRegistry)1 Configuration (com.hotels.styx.api.configuration.Configuration)1 Origin (com.hotels.styx.api.extension.Origin)1