Search in sources :

Example 1 with OkHttpMetricsInterceptor

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;
}
Also used : OkHttpClient(okhttp3.OkHttpClient) OkHttpMetricsInterceptor(com.netflix.titus.runtime.connector.kubernetes.okhttp.OkHttpMetricsInterceptor) IOException(java.io.IOException) DisableCompressionInterceptor(com.netflix.titus.runtime.connector.kubernetes.okhttp.DisableCompressionInterceptor) ApiClient(io.kubernetes.client.openapi.ApiClient)

Aggregations

DisableCompressionInterceptor (com.netflix.titus.runtime.connector.kubernetes.okhttp.DisableCompressionInterceptor)1 OkHttpMetricsInterceptor (com.netflix.titus.runtime.connector.kubernetes.okhttp.OkHttpMetricsInterceptor)1 ApiClient (io.kubernetes.client.openapi.ApiClient)1 IOException (java.io.IOException)1 OkHttpClient (okhttp3.OkHttpClient)1