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();
}
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();
}
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));
}
}
Aggregations