Provide metrics of k8s API execution (#15207)
* Provide metrics of k8s API execution Signed-off-by: Sergii Kabashniuk <skabashniuk@redhat.com>7.20.x
parent
bcc597ccb4
commit
29aa04cb2f
|
|
@ -261,6 +261,8 @@ public class WsMasterModule extends AbstractModule {
|
|||
if (Boolean.valueOf(System.getenv("CHE_METRICS_ENABLED"))) {
|
||||
install(new org.eclipse.che.core.metrics.MetricsModule());
|
||||
install(new WsMasterMetricsModule());
|
||||
} else {
|
||||
install(new org.eclipse.che.core.metrics.NoopMetricsModule());
|
||||
}
|
||||
if (Boolean.valueOf(System.getenv("CHE_TRACING_ENABLED"))
|
||||
&& Boolean.valueOf(System.getenv("CHE_METRICS_ENABLED"))) {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@
|
|||
<groupId>com.google.inject.extensions</groupId>
|
||||
<artifactId>guice-servlet</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.mweirauch</groupId>
|
||||
<artifactId>micrometer-jvm-extras</artifactId>
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
|
|||
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
|
||||
import io.micrometer.prometheus.PrometheusMeterRegistry;
|
||||
import io.prometheus.client.CollectorRegistry;
|
||||
import okhttp3.EventListener;
|
||||
|
||||
@Beta
|
||||
public class MetricsModule extends AbstractModule {
|
||||
|
|
@ -55,5 +56,7 @@ public class MetricsModule extends AbstractModule {
|
|||
meterMultibinder.addBinding().to(ApiResponseCounter.class);
|
||||
meterMultibinder.addBinding().to(ProcessMemoryMetrics.class);
|
||||
meterMultibinder.addBinding().to(ProcessThreadMetrics.class);
|
||||
|
||||
bind(EventListener.class).toProvider(OkHttpMetricsEventListenerProvider.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
|
@ -30,6 +30,7 @@ import okhttp3.Authenticator;
|
|||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.Credentials;
|
||||
import okhttp3.Dispatcher;
|
||||
import okhttp3.EventListener;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
|
@ -61,7 +62,8 @@ public class KubernetesClientFactory {
|
|||
int maxConcurrentRequestsPerHost,
|
||||
@Named("che.infra.kubernetes.client.http.connection_pool.max_idle") int maxIdleConnections,
|
||||
@Named("che.infra.kubernetes.client.http.connection_pool.keep_alive_min")
|
||||
int connectionPoolKeepAlive) {
|
||||
int connectionPoolKeepAlive,
|
||||
EventListener eventListener) {
|
||||
this.defaultConfig = buildDefaultConfig(masterUrl, doTrustCerts);
|
||||
OkHttpClient temporary = HttpClientUtils.createHttpClient(defaultConfig);
|
||||
OkHttpClient.Builder builder = temporary.newBuilder();
|
||||
|
|
@ -69,7 +71,7 @@ public class KubernetesClientFactory {
|
|||
builder.connectionPool(
|
||||
new ConnectionPool(maxIdleConnections, connectionPoolKeepAlive, TimeUnit.MINUTES));
|
||||
oldPool.evictAll();
|
||||
this.httpClient = builder.build();
|
||||
this.httpClient = builder.eventListener(eventListener).build();
|
||||
httpClient.dispatcher().setMaxRequests(maxConcurrentRequests);
|
||||
httpClient.dispatcher().setMaxRequestsPerHost(maxConcurrentRequestsPerHost);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import javax.inject.Named;
|
|||
import javax.inject.Singleton;
|
||||
import okhttp3.Authenticator;
|
||||
import okhttp3.Credentials;
|
||||
import okhttp3.EventListener;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
|
@ -66,14 +67,16 @@ public class OpenShiftClientFactory extends KubernetesClientFactory {
|
|||
int maxConcurrentRequestsPerHost,
|
||||
@Named("che.infra.kubernetes.client.http.connection_pool.max_idle") int maxIdleConnections,
|
||||
@Named("che.infra.kubernetes.client.http.connection_pool.keep_alive_min")
|
||||
int connectionPoolKeepAlive) {
|
||||
int connectionPoolKeepAlive,
|
||||
EventListener eventListener) {
|
||||
super(
|
||||
masterUrl,
|
||||
doTrustCerts,
|
||||
maxConcurrentRequests,
|
||||
maxConcurrentRequestsPerHost,
|
||||
maxIdleConnections,
|
||||
connectionPoolKeepAlive);
|
||||
connectionPoolKeepAlive,
|
||||
eventListener);
|
||||
this.configBuilder = configBuilder;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue