Search in sources :

Example 1 with HealthCheckedEndpointGroup

use of com.linecorp.armeria.client.endpoint.healthcheck.HealthCheckedEndpointGroup in project curiostack by curioswitch.

the class ClientBuilderFactory method create.

public ClientBuilder create(String name, String url) {
    URI uri = URI.create(url);
    EndpointGroup endpoint = Endpoint.parse(uri.getAuthority());
    if (((Endpoint) endpoint).authority().endsWith("cluster.local")) {
        DnsAddressEndpointGroup dnsEndpointGroup = DnsAddressEndpointGroup.builder(uri.getHost()).port(uri.getPort()).ttl(1, 10).build();
        dnsEndpointGroup.addListener(endpoints -> logger.info("Resolved new endpoints for {} : [ {} ]", name, endpoints.stream().map(e -> MoreObjects.firstNonNull(e.ipAddr(), e.authority())).collect(Collectors.joining(","))));
        HealthCheckedEndpointGroup endpointGroup = HealthCheckedEndpointGroup.builder(dnsEndpointGroup, "/internal/health").clientFactory(clientFactory).protocol(SessionProtocol.HTTPS).retryInterval(Duration.ofSeconds(3)).build();
        endpoint = endpointGroup;
    }
    ClientBuilder builder = Clients.builder(uri.getScheme(), endpoint, uri.getPath()).factory(clientFactory);
    return builder.decorator(MetricCollectingClient.newDecorator(RpcMetricLabels.grpcRequestLabeler("grpc_clients"))).decorator(BraveClient.newDecorator(tracing)).decorator(loggingClient);
}
Also used : HealthCheckedEndpointGroup(com.linecorp.armeria.client.endpoint.healthcheck.HealthCheckedEndpointGroup) SessionProtocol(com.linecorp.armeria.common.SessionProtocol) DnsNameResolverBuilder(io.netty.resolver.dns.DnsNameResolverBuilder) ResourceUtil(org.curioswitch.common.server.framework.util.ResourceUtil) BraveClient(com.linecorp.armeria.client.brave.BraveClient) Singleton(javax.inject.Singleton) Function(java.util.function.Function) Inject(javax.inject.Inject) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) EventLoopGroups(com.linecorp.armeria.common.util.EventLoopGroups) RpcMetricLabels(org.curioswitch.common.server.framework.monitoring.RpcMetricLabels) Duration(java.time.Duration) Clients(com.linecorp.armeria.client.Clients) ClientBuilder(com.linecorp.armeria.client.ClientBuilder) URI(java.net.URI) ClientFactoryBuilder(com.linecorp.armeria.client.ClientFactoryBuilder) Tracing(brave.Tracing) DnsAddressEndpointGroup(com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroup) ClientFactory(com.linecorp.armeria.client.ClientFactory) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) MetricCollectingClient(com.linecorp.armeria.client.metric.MetricCollectingClient) MoreObjects(com.google.common.base.MoreObjects) EndpointGroup(com.linecorp.armeria.client.endpoint.EndpointGroup) Endpoint(com.linecorp.armeria.client.Endpoint) DnsServerAddressStreamProviders(io.netty.resolver.dns.DnsServerAddressStreamProviders) Collectors(java.util.stream.Collectors) LoggingClient(com.linecorp.armeria.client.logging.LoggingClient) Consumer(java.util.function.Consumer) Logger(org.apache.logging.log4j.Logger) ServerConfig(org.curioswitch.common.server.framework.config.ServerConfig) HttpClient(com.linecorp.armeria.client.HttpClient) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) Optional(java.util.Optional) DnsAddressResolverGroup(io.netty.resolver.dns.DnsAddressResolverGroup) LogManager(org.apache.logging.log4j.LogManager) HealthCheckedEndpointGroup(com.linecorp.armeria.client.endpoint.healthcheck.HealthCheckedEndpointGroup) HealthCheckedEndpointGroup(com.linecorp.armeria.client.endpoint.healthcheck.HealthCheckedEndpointGroup) DnsAddressEndpointGroup(com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroup) EndpointGroup(com.linecorp.armeria.client.endpoint.EndpointGroup) URI(java.net.URI) DnsAddressEndpointGroup(com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroup) ClientBuilder(com.linecorp.armeria.client.ClientBuilder)

Example 2 with HealthCheckedEndpointGroup

use of com.linecorp.armeria.client.endpoint.healthcheck.HealthCheckedEndpointGroup in project zipkin by openzipkin.

the class LazyHttpClientImpl method decorateHealthCheck.

// Enables health-checking of an endpoint group, so we only send requests to endpoints that are up
HealthCheckedEndpointGroup decorateHealthCheck(EndpointGroup endpointGroup) {
    HealthCheckedEndpointGroup healthChecked = HealthCheckedEndpointGroup.builder(endpointGroup, "/_cluster/health").protocol(protocol).useGet(true).clientFactory(factory.clientFactory).withClientOptions(options -> {
        factory.configureHttpLogging(healthCheck.getHttpLogging(), options);
        factory.configureOptionsExceptHttpLogging(options);
        options.decorator(MetricCollectingClient.newDecorator(MeterIdPrefixFunction.ofDefault("elasticsearch-healthcheck")));
        options.decorator((delegate, ctx, req) -> {
            ctx.logBuilder().name("health-check");
            return delegate.execute(ctx, req);
        });
        return options;
    }).retryInterval(healthCheck.getInterval()).build();
    healthChecked.newMeterBinder("elasticsearch").bindTo(meterRegistry);
    return healthChecked;
}
Also used : HealthCheckedEndpointGroup(com.linecorp.armeria.client.endpoint.healthcheck.HealthCheckedEndpointGroup)

Aggregations

HealthCheckedEndpointGroup (com.linecorp.armeria.client.endpoint.healthcheck.HealthCheckedEndpointGroup)2 Tracing (brave.Tracing)1 MoreObjects (com.google.common.base.MoreObjects)1 ClientBuilder (com.linecorp.armeria.client.ClientBuilder)1 ClientFactory (com.linecorp.armeria.client.ClientFactory)1 ClientFactoryBuilder (com.linecorp.armeria.client.ClientFactoryBuilder)1 Clients (com.linecorp.armeria.client.Clients)1 Endpoint (com.linecorp.armeria.client.Endpoint)1 HttpClient (com.linecorp.armeria.client.HttpClient)1 BraveClient (com.linecorp.armeria.client.brave.BraveClient)1 EndpointGroup (com.linecorp.armeria.client.endpoint.EndpointGroup)1 DnsAddressEndpointGroup (com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroup)1 LoggingClient (com.linecorp.armeria.client.logging.LoggingClient)1 MetricCollectingClient (com.linecorp.armeria.client.metric.MetricCollectingClient)1 SessionProtocol (com.linecorp.armeria.common.SessionProtocol)1 EventLoopGroups (com.linecorp.armeria.common.util.EventLoopGroups)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)1 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)1 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)1