Search in sources :

Example 1 with HostEventsSink

use of com.palantir.conjure.java.client.config.HostEventsSink in project dialogue by palantir.

the class AugmentClientConfig method getClientConf.

static ClientConfiguration getClientConf(ServiceConfiguration serviceConfig, AugmentClientConfig augment) {
    ClientConfiguration.Builder builder = ClientConfiguration.builder().from(ClientConfigurations.of(serviceConfig));
    SSLContext context = augment.securityProvider().map(provider -> SslSocketFactories.createSslContext(serviceConfig.security(), provider)).orElseGet(() -> SslSocketFactories.createSslContext(serviceConfig.security()));
    // Reduce the session cache size for clients. We expect TLS connections to be reused, thus the cache isn't
    // terribly important.
    context.getClientSessionContext().setSessionCacheSize(100);
    builder.sslSocketFactory(context.getSocketFactory());
    if (!serviceConfig.maxNumRetries().isPresent()) {
        augment.maxNumRetries().ifPresent(builder::maxNumRetries);
    }
    if (augment.securityProvider().isPresent()) {
        // Opt into GCM when custom providers (Conscrypt) is used.
        builder.enableGcmCipherSuites(true);
    }
    builder.userAgent(augment.userAgent());
    builder.taggedMetricRegistry(augment.taggedMetrics());
    augment.nodeSelectionStrategy().ifPresent(builder::nodeSelectionStrategy);
    augment.clientQoS().ifPresent(builder::clientQoS);
    augment.serverQoS().ifPresent(builder::serverQoS);
    augment.retryOnTimeout().ifPresent(builder::retryOnTimeout);
    augment.hostEventsSink().ifPresent(builder::hostEventsSink);
    return builder.build();
}
Also used : SSLContext(javax.net.ssl.SSLContext) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) Provider(java.security.Provider) HostEventsSink(com.palantir.conjure.java.client.config.HostEventsSink) SslSocketFactories(com.palantir.conjure.java.config.ssl.SslSocketFactories) NodeSelectionStrategy(com.palantir.conjure.java.client.config.NodeSelectionStrategy) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) Value(org.immutables.value.Value) Optional(java.util.Optional) ServiceConfiguration(com.palantir.conjure.java.api.config.service.ServiceConfiguration) SharedTaggedMetricRegistries(com.palantir.tritium.metrics.registry.SharedTaggedMetricRegistries) ClientConfigurations(com.palantir.conjure.java.client.config.ClientConfigurations) SSLContext(javax.net.ssl.SSLContext) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration)

Example 2 with HostEventsSink

use of com.palantir.conjure.java.client.config.HostEventsSink in project dialogue by palantir.

the class HostMetricsChannelTest method calls_sink_when_response_comes_back.

@Test
void calls_sink_when_response_comes_back() {
    AtomicBoolean recorded = new AtomicBoolean();
    Channel channel = HostMetricsChannel.create(config(ClientConfiguration.builder().from(TestConfigurations.create("https://unused", "https://unused2")).hostEventsSink(new HostEventsSink() {

        @Override
        public void record(String serviceName, String hostname, int port, int statusCode, long micros) {
            assertThat(serviceName).isEqualTo("channelName");
            assertThat(hostname).isEqualTo("foo");
            assertThat(port).isEqualTo(1001);
            assertThat(statusCode).isEqualTo(200);
            assertThat(micros).isEqualTo(TimeUnit.SECONDS.toMicros(3));
            recorded.set(true);
        }

        @Override
        public void recordIoException(String _serviceName, String _hostname, int _port) {
            Assertions.fail("no IOExceptions expected");
        }
    }).build()), mockChannel, "https://foo:1001");
    SettableFuture<Response> settable = SettableFuture.create();
    when(mockChannel.execute(any(), any())).thenReturn(settable);
    ListenableFuture<Response> future = channel.execute(TestEndpoint.GET, Request.builder().build());
    when(ticker.read()).thenReturn(Duration.ofSeconds(3).toNanos());
    settable.set(new TestResponse().code(200));
    assertThat(recorded).isTrue();
    assertThat(future).isDone();
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HostEventsSink(com.palantir.conjure.java.client.config.HostEventsSink) TestResponse(com.palantir.dialogue.TestResponse) Channel(com.palantir.dialogue.Channel) Test(org.junit.jupiter.api.Test)

Example 3 with HostEventsSink

use of com.palantir.conjure.java.client.config.HostEventsSink in project dialogue by palantir.

the class HostMetricsChannel method create.

static Channel create(Config cf, Channel channel, String uri) {
    Optional<HostEventsSink> hostEventsSink = cf.clientConf().hostEventsSink();
    if (!hostEventsSink.isPresent()) {
        return channel;
    }
    if (hostEventsSink.get().getClass().getSimpleName().equals("NoOpHostEventsSink")) {
        // special-casing for the implementation in conjure-java-runtime
        return channel;
    }
    try {
        URL parsed = new URL(uri);
        String host = parsed.getHost();
        int port = parsed.getPort() != -1 ? parsed.getPort() : parsed.getDefaultPort();
        return new HostMetricsChannel(channel, hostEventsSink.get(), cf.ticker(), cf.channelName(), host, port);
    } catch (MalformedURLException e) {
        throw new SafeIllegalArgumentException("Failed to parse URI", UnsafeArg.of("uri", uri));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HostEventsSink(com.palantir.conjure.java.client.config.HostEventsSink) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) URL(java.net.URL) Endpoint(com.palantir.dialogue.Endpoint)

Aggregations

HostEventsSink (com.palantir.conjure.java.client.config.HostEventsSink)3 ServiceConfiguration (com.palantir.conjure.java.api.config.service.ServiceConfiguration)1 UserAgent (com.palantir.conjure.java.api.config.service.UserAgent)1 ClientConfiguration (com.palantir.conjure.java.client.config.ClientConfiguration)1 ClientConfigurations (com.palantir.conjure.java.client.config.ClientConfigurations)1 NodeSelectionStrategy (com.palantir.conjure.java.client.config.NodeSelectionStrategy)1 SslSocketFactories (com.palantir.conjure.java.config.ssl.SslSocketFactories)1 Channel (com.palantir.dialogue.Channel)1 Endpoint (com.palantir.dialogue.Endpoint)1 Response (com.palantir.dialogue.Response)1 TestResponse (com.palantir.dialogue.TestResponse)1 SafeIllegalArgumentException (com.palantir.logsafe.exceptions.SafeIllegalArgumentException)1 SharedTaggedMetricRegistries (com.palantir.tritium.metrics.registry.SharedTaggedMetricRegistries)1 TaggedMetricRegistry (com.palantir.tritium.metrics.registry.TaggedMetricRegistry)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Provider (java.security.Provider)1 Optional (java.util.Optional)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 SSLContext (javax.net.ssl.SSLContext)1