Provide metrics of k8s API execution (#15207)

* Provide metrics of k8s API execution
Signed-off-by: Sergii Kabashniuk <skabashniuk@redhat.com>
7.20.x
Sergii Kabashniuk 2019-11-20 08:17:04 +01:00 committed by GitHub
parent bcc597ccb4
commit 29aa04cb2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1493 additions and 1227 deletions

View File

@ -261,6 +261,8 @@ public class WsMasterModule extends AbstractModule {
if (Boolean.valueOf(System.getenv("CHE_METRICS_ENABLED"))) { if (Boolean.valueOf(System.getenv("CHE_METRICS_ENABLED"))) {
install(new org.eclipse.che.core.metrics.MetricsModule()); install(new org.eclipse.che.core.metrics.MetricsModule());
install(new WsMasterMetricsModule()); install(new WsMasterMetricsModule());
} else {
install(new org.eclipse.che.core.metrics.NoopMetricsModule());
} }
if (Boolean.valueOf(System.getenv("CHE_TRACING_ENABLED")) if (Boolean.valueOf(System.getenv("CHE_TRACING_ENABLED"))
&& Boolean.valueOf(System.getenv("CHE_METRICS_ENABLED"))) { && Boolean.valueOf(System.getenv("CHE_METRICS_ENABLED"))) {

View File

@ -34,6 +34,10 @@
<groupId>com.google.inject.extensions</groupId> <groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId> <artifactId>guice-servlet</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency> <dependency>
<groupId>io.github.mweirauch</groupId> <groupId>io.github.mweirauch</groupId>
<artifactId>micrometer-jvm-extras</artifactId> <artifactId>micrometer-jvm-extras</artifactId>

View File

@ -28,6 +28,7 @@ import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.binder.system.UptimeMetrics; import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import io.micrometer.prometheus.PrometheusMeterRegistry; import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.CollectorRegistry; import io.prometheus.client.CollectorRegistry;
import okhttp3.EventListener;
@Beta @Beta
public class MetricsModule extends AbstractModule { public class MetricsModule extends AbstractModule {
@ -55,5 +56,7 @@ public class MetricsModule extends AbstractModule {
meterMultibinder.addBinding().to(ApiResponseCounter.class); meterMultibinder.addBinding().to(ApiResponseCounter.class);
meterMultibinder.addBinding().to(ProcessMemoryMetrics.class); meterMultibinder.addBinding().to(ProcessMemoryMetrics.class);
meterMultibinder.addBinding().to(ProcessThreadMetrics.class); meterMultibinder.addBinding().to(ProcessThreadMetrics.class);
bind(EventListener.class).toProvider(OkHttpMetricsEventListenerProvider.class);
} }
} }

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.core.metrics;
import com.google.inject.AbstractModule;
import okhttp3.EventListener;
/** Provides dummy implementations of some classes in case if monitoring is turned off. */
public class NoopMetricsModule extends AbstractModule {
@Override
protected void configure() {
bind(EventListener.class).toInstance(EventListener.NONE);
}
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.core.metrics;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.okhttp3.OkHttpMetricsEventListener;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import okhttp3.OkHttpClient;
/**
* Provider of {@link OkHttpMetricsEventListener} class instances that collect metrics from {@link
* OkHttpClient}.
*/
@Singleton
public class OkHttpMetricsEventListenerProvider implements Provider<OkHttpMetricsEventListener> {
private final OkHttpMetricsEventListener listener;
@Inject
public OkHttpMetricsEventListenerProvider(MeterRegistry registry) {
this.listener = OkHttpMetricsEventListener.builder(registry, "okhttp.requests").build();
}
@Override
public OkHttpMetricsEventListener get() {
return listener;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,7 @@ import okhttp3.Authenticator;
import okhttp3.ConnectionPool; import okhttp3.ConnectionPool;
import okhttp3.Credentials; import okhttp3.Credentials;
import okhttp3.Dispatcher; import okhttp3.Dispatcher;
import okhttp3.EventListener;
import okhttp3.Interceptor; import okhttp3.Interceptor;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
@ -61,7 +62,8 @@ public class KubernetesClientFactory {
int maxConcurrentRequestsPerHost, int maxConcurrentRequestsPerHost,
@Named("che.infra.kubernetes.client.http.connection_pool.max_idle") int maxIdleConnections, @Named("che.infra.kubernetes.client.http.connection_pool.max_idle") int maxIdleConnections,
@Named("che.infra.kubernetes.client.http.connection_pool.keep_alive_min") @Named("che.infra.kubernetes.client.http.connection_pool.keep_alive_min")
int connectionPoolKeepAlive) { int connectionPoolKeepAlive,
EventListener eventListener) {
this.defaultConfig = buildDefaultConfig(masterUrl, doTrustCerts); this.defaultConfig = buildDefaultConfig(masterUrl, doTrustCerts);
OkHttpClient temporary = HttpClientUtils.createHttpClient(defaultConfig); OkHttpClient temporary = HttpClientUtils.createHttpClient(defaultConfig);
OkHttpClient.Builder builder = temporary.newBuilder(); OkHttpClient.Builder builder = temporary.newBuilder();
@ -69,7 +71,7 @@ public class KubernetesClientFactory {
builder.connectionPool( builder.connectionPool(
new ConnectionPool(maxIdleConnections, connectionPoolKeepAlive, TimeUnit.MINUTES)); new ConnectionPool(maxIdleConnections, connectionPoolKeepAlive, TimeUnit.MINUTES));
oldPool.evictAll(); oldPool.evictAll();
this.httpClient = builder.build(); this.httpClient = builder.eventListener(eventListener).build();
httpClient.dispatcher().setMaxRequests(maxConcurrentRequests); httpClient.dispatcher().setMaxRequests(maxConcurrentRequests);
httpClient.dispatcher().setMaxRequestsPerHost(maxConcurrentRequestsPerHost); httpClient.dispatcher().setMaxRequestsPerHost(maxConcurrentRequestsPerHost);
} }

View File

@ -31,6 +31,7 @@ import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import okhttp3.Authenticator; import okhttp3.Authenticator;
import okhttp3.Credentials; import okhttp3.Credentials;
import okhttp3.EventListener;
import okhttp3.Interceptor; import okhttp3.Interceptor;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
@ -66,14 +67,16 @@ public class OpenShiftClientFactory extends KubernetesClientFactory {
int maxConcurrentRequestsPerHost, int maxConcurrentRequestsPerHost,
@Named("che.infra.kubernetes.client.http.connection_pool.max_idle") int maxIdleConnections, @Named("che.infra.kubernetes.client.http.connection_pool.max_idle") int maxIdleConnections,
@Named("che.infra.kubernetes.client.http.connection_pool.keep_alive_min") @Named("che.infra.kubernetes.client.http.connection_pool.keep_alive_min")
int connectionPoolKeepAlive) { int connectionPoolKeepAlive,
EventListener eventListener) {
super( super(
masterUrl, masterUrl,
doTrustCerts, doTrustCerts,
maxConcurrentRequests, maxConcurrentRequests,
maxConcurrentRequestsPerHost, maxConcurrentRequestsPerHost,
maxIdleConnections, maxIdleConnections,
connectionPoolKeepAlive); connectionPoolKeepAlive,
eventListener);
this.configBuilder = configBuilder; this.configBuilder = configBuilder;
} }