use of com.netflix.titus.runtime.connector.kubernetes.okhttp.OkHttpMetricsInterceptor in project titus-control-plane by Netflix.
the class StdKubeApiClients method createApiClient.
public static ApiClient createApiClient(String kubeApiServerUrl, String kubeConfigPath, String metricsNamePrefix, TitusRuntime titusRuntime, Function<Request, String> uriMapper, long readTimeoutMs, boolean enableCompressionForKubeApiClient) {
OkHttpMetricsInterceptor metricsInterceptor = new OkHttpMetricsInterceptor(metricsNamePrefix, titusRuntime.getRegistry(), titusRuntime.getClock(), uriMapper);
ApiClient client;
if (Strings.isNullOrEmpty(kubeApiServerUrl)) {
try {
if (Strings.isNullOrEmpty(kubeConfigPath)) {
client = Config.defaultClient();
} else {
client = Config.fromConfig(kubeConfigPath);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
client = Config.fromUrl(kubeApiServerUrl);
}
OkHttpClient.Builder newBuilder = client.getHttpClient().newBuilder();
// See: https://github.com/kubernetes-client/java/pull/960
newBuilder.protocols(Collections.singletonList(Protocol.HTTP_1_1)).addInterceptor(metricsInterceptor).readTimeout(readTimeoutMs, TimeUnit.SECONDS);
// By default compression is enabled in OkHttpClient
if (!enableCompressionForKubeApiClient) {
newBuilder.addInterceptor(new DisableCompressionInterceptor());
}
client.setHttpClient(newBuilder.build());
return client;
}
Aggregations