Search in sources :

Example 1 with StyxServerComponents

use of com.hotels.styx.startup.StyxServerComponents 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 StyxServerComponents

use of com.hotels.styx.startup.StyxServerComponents in project styx by ExpediaGroup.

the class StyxServer method createStyxServer.

private static StyxServer createStyxServer(String[] args) {
    Stopwatch stopwatch = new Stopwatch();
    StartupConfig startupConfig = parseStartupConfig(args);
    LOG.info("Styx home={}", startupConfig.styxHome());
    LOG.info("Styx configFileLocation={}", startupConfig.configFileLocation());
    LOG.info("Styx logConfigLocation={}", startupConfig.logConfigLocation());
    PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
    CompositeMeterRegistry compositeMeterRegistry = new CompositeMeterRegistry();
    compositeMeterRegistry.add(prometheusRegistry);
    StyxServerComponents components = new StyxServerComponents.Builder().registry(new MicrometerRegistry(compositeMeterRegistry)).styxConfig(parseConfiguration(startupConfig)).startupConfig(startupConfig).loggingSetUp(environment -> activateLogbackConfigurer(startupConfig)).showBanner(true).build();
    return new StyxServer(components, stopwatch);
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) StyxServerComponents(com.hotels.styx.startup.StyxServerComponents) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) NettyServerBuilder(com.hotels.styx.server.netty.NettyServerBuilder) AdminServerBuilder(com.hotels.styx.admin.AdminServerBuilder) Stopwatch(com.hotels.styx.javaconvenience.Stopwatch)

Example 3 with StyxServerComponents

use of com.hotels.styx.startup.StyxServerComponents in project styx by ExpediaGroup.

the class StyxServer method httpServer.

private InetServer httpServer(StyxServerComponents components, ConnectorConfig connectorConfig, HttpHandler styxDataPlane) {
    Environment environment = components.environment();
    CharSequence styxInfoHeaderName = environment.configuration().styxHeaderConfig().styxInfoHeaderName();
    ResponseInfoFormat responseInfoFormat = new ResponseInfoFormat(environment);
    ServerConnector proxyConnector = new ProxyConnectorFactory(environment.configuration().proxyServerConfig(), environment.centralisedMetrics(), environment.errorListener(), environment.configuration().get(ENCODE_UNWISECHARS).orElse(""), (builder, request) -> builder.header(styxInfoHeaderName, responseInfoFormat.format(request)), environment.configuration().get("requestTracking", Boolean.class).orElse(false), environment.httpMessageFormatter(), environment.configuration().styxHeaderConfig().originIdHeaderName()).create(connectorConfig);
    return NettyServerBuilder.newBuilder().setMetricsRegistry(environment.metricRegistry()).bossExecutor(proxyBossExecutor).workerExecutor(proxyWorkerExecutor).setProtocolConnector(proxyConnector).handler(styxDataPlane).build();
}
Also used : ServerConnector(com.hotels.styx.server.netty.ServerConnector) DISABLED(io.netty.util.ResourceLeakDetector.Level.DISABLED) LOGBackConfigurer.shutdownLogging(com.hotels.styx.infrastructure.logging.LOGBackConfigurer.shutdownLogging) Registry(com.hotels.styx.api.extension.service.spi.Registry) ServiceManager(com.google.common.util.concurrent.ServiceManager) Stopwatch(com.hotels.styx.javaconvenience.Stopwatch) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) CompletableFuture(java.util.concurrent.CompletableFuture) ENCODE_UNWISECHARS(com.hotels.styx.proxy.encoders.ConfigurableUnwiseCharsEncoder.ENCODE_UNWISECHARS) ConnectorConfig(com.hotels.styx.server.ConnectorConfig) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) ArrayList(java.util.ArrayList) StyxServers.toGuavaService(com.hotels.styx.StyxServers.toGuavaService) CharStreams(com.google.common.io.CharStreams) SchemaValidationException(com.hotels.styx.config.schema.SchemaValidationException) AbstractService(com.google.common.util.concurrent.AbstractService) BackendService(com.hotels.styx.api.extension.service.BackendService) System.getProperty(java.lang.System.getProperty) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) NettyServerBuilder(com.hotels.styx.server.netty.NettyServerBuilder) AbstractStyxService(com.hotels.styx.api.extension.service.spi.AbstractStyxService) Logger(org.slf4j.Logger) HttpHandler(com.hotels.styx.api.HttpHandler) StyxServerComponents(com.hotels.styx.startup.StyxServerComponents) IOException(java.io.IOException) Reader(java.io.Reader) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) ResourceLeakDetector(io.netty.util.ResourceLeakDetector) CoreMetricsKt.registerCoreMetrics(com.hotels.styx.startup.CoreMetricsKt.registerCoreMetrics) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry) InputStreamReader(java.io.InputStreamReader) InetSocketAddress(java.net.InetSocketAddress) String.format(java.lang.String.format) Service(com.google.common.util.concurrent.Service) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Resource(com.hotels.styx.api.Resource) Paths(java.nio.file.Paths) MeterRegistry(com.hotels.styx.api.MeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) LOGBackConfigurer.initLogging(com.hotels.styx.infrastructure.logging.LOGBackConfigurer.initLogging) BufferedReader(java.io.BufferedReader) Runtime.getRuntime(java.lang.Runtime.getRuntime) NotNull(org.jetbrains.annotations.NotNull) AdminServerBuilder(com.hotels.styx.admin.AdminServerBuilder) ServerConnector(com.hotels.styx.server.netty.ServerConnector) PrometheusConfig(io.micrometer.prometheus.PrometheusConfig)

Aggregations

MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)3 StyxServerComponents (com.hotels.styx.startup.StyxServerComponents)3 CompositeMeterRegistry (io.micrometer.core.instrument.composite.CompositeMeterRegistry)3 AdminServerBuilder (com.hotels.styx.admin.AdminServerBuilder)2 MemoryBackedRegistry (com.hotels.styx.infrastructure.MemoryBackedRegistry)2 Stopwatch (com.hotels.styx.javaconvenience.Stopwatch)2 NettyServerBuilder (com.hotels.styx.server.netty.NettyServerBuilder)2 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)2 CharStreams (com.google.common.io.CharStreams)1 AbstractService (com.google.common.util.concurrent.AbstractService)1 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)1 Service (com.google.common.util.concurrent.Service)1 ServiceManager (com.google.common.util.concurrent.ServiceManager)1 StyxServers.toGuavaService (com.hotels.styx.StyxServers.toGuavaService)1 HttpHandler (com.hotels.styx.api.HttpHandler)1 MeterRegistry (com.hotels.styx.api.MeterRegistry)1 Resource (com.hotels.styx.api.Resource)1 BackendService (com.hotels.styx.api.extension.service.BackendService)1 AbstractStyxService (com.hotels.styx.api.extension.service.spi.AbstractStyxService)1 Registry (com.hotels.styx.api.extension.service.spi.Registry)1