Add metric for closed connection age to KeepAliveController
This commit is contained in:
parent
1faa1a5abc
commit
584fd06b88
|
@ -10,7 +10,10 @@ import static com.codahale.metrics.MetricRegistry.name;
|
||||||
import io.dropwizard.auth.Auth;
|
import io.dropwizard.auth.Auth;
|
||||||
import io.micrometer.core.instrument.Metrics;
|
import io.micrometer.core.instrument.Metrics;
|
||||||
import io.micrometer.core.instrument.Tags;
|
import io.micrometer.core.instrument.Tags;
|
||||||
|
import io.micrometer.core.instrument.Timer;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
|
@ -33,8 +36,9 @@ public class KeepAliveController {
|
||||||
|
|
||||||
private final ClientPresenceManager clientPresenceManager;
|
private final ClientPresenceManager clientPresenceManager;
|
||||||
|
|
||||||
private static final String NO_LOCAL_SUBSCRIPTION_COUNTER_NAME = name(KeepAliveController.class,
|
private static final String CLOSED_CONNECTION_AGE_DISTRIBUTION_NAME = name(KeepAliveController.class,
|
||||||
"noLocalSubscription");
|
"closedConnectionAge");
|
||||||
|
|
||||||
|
|
||||||
public KeepAliveController(final ClientPresenceManager clientPresenceManager) {
|
public KeepAliveController(final ClientPresenceManager clientPresenceManager) {
|
||||||
this.clientPresenceManager = clientPresenceManager;
|
this.clientPresenceManager = clientPresenceManager;
|
||||||
|
@ -46,16 +50,20 @@ public class KeepAliveController {
|
||||||
|
|
||||||
maybeAuth.ifPresent(auth -> {
|
maybeAuth.ifPresent(auth -> {
|
||||||
if (!clientPresenceManager.isLocallyPresent(auth.getAccount().getUuid(), auth.getAuthenticatedDevice().getId())) {
|
if (!clientPresenceManager.isLocallyPresent(auth.getAccount().getUuid(), auth.getAuthenticatedDevice().getId())) {
|
||||||
|
|
||||||
|
final Duration age = Duration.between(context.getClient().getCreated(), Instant.now());
|
||||||
|
|
||||||
logger.debug("***** No local subscription found for {}::{}; age = {}ms, User-Agent = {}",
|
logger.debug("***** No local subscription found for {}::{}; age = {}ms, User-Agent = {}",
|
||||||
auth.getAccount().getUuid(), auth.getAuthenticatedDevice().getId(),
|
auth.getAccount().getUuid(), auth.getAuthenticatedDevice().getId(), age.toMillis(),
|
||||||
System.currentTimeMillis() - context.getClient().getCreatedTimestamp(),
|
|
||||||
context.getClient().getUserAgent());
|
context.getClient().getUserAgent());
|
||||||
|
|
||||||
context.getClient().close(1000, "OK");
|
context.getClient().close(1000, "OK");
|
||||||
|
|
||||||
Metrics.counter(NO_LOCAL_SUBSCRIPTION_COUNTER_NAME,
|
Timer.builder(CLOSED_CONNECTION_AGE_DISTRIBUTION_NAME)
|
||||||
Tags.of(UserAgentTagUtil.getPlatformTag(context.getClient().getUserAgent())))
|
.tags(Tags.of(UserAgentTagUtil.getPlatformTag(context.getClient().getUserAgent())))
|
||||||
.increment();
|
.publishPercentileHistogram(true)
|
||||||
|
.register(Metrics.globalRegistry)
|
||||||
|
.record(age);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ package org.whispersystems.websocket;
|
||||||
import com.google.common.net.HttpHeaders;
|
import com.google.common.net.HttpHeaders;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -31,7 +32,7 @@ public class WebSocketClient {
|
||||||
private final RemoteEndpoint remoteEndpoint;
|
private final RemoteEndpoint remoteEndpoint;
|
||||||
private final WebSocketMessageFactory messageFactory;
|
private final WebSocketMessageFactory messageFactory;
|
||||||
private final Map<Long, CompletableFuture<WebSocketResponseMessage>> pendingRequestMapper;
|
private final Map<Long, CompletableFuture<WebSocketResponseMessage>> pendingRequestMapper;
|
||||||
private final long created;
|
private final Instant created;
|
||||||
|
|
||||||
public WebSocketClient(Session session, RemoteEndpoint remoteEndpoint, WebSocketMessageFactory messageFactory,
|
public WebSocketClient(Session session, RemoteEndpoint remoteEndpoint, WebSocketMessageFactory messageFactory,
|
||||||
Map<Long, CompletableFuture<WebSocketResponseMessage>> pendingRequestMapper) {
|
Map<Long, CompletableFuture<WebSocketResponseMessage>> pendingRequestMapper) {
|
||||||
|
@ -39,7 +40,7 @@ public class WebSocketClient {
|
||||||
this.remoteEndpoint = remoteEndpoint;
|
this.remoteEndpoint = remoteEndpoint;
|
||||||
this.messageFactory = messageFactory;
|
this.messageFactory = messageFactory;
|
||||||
this.pendingRequestMapper = pendingRequestMapper;
|
this.pendingRequestMapper = pendingRequestMapper;
|
||||||
this.created = System.currentTimeMillis();
|
this.created = Instant.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<WebSocketResponseMessage> sendRequest(String verb, String path,
|
public CompletableFuture<WebSocketResponseMessage> sendRequest(String verb, String path,
|
||||||
|
@ -78,7 +79,7 @@ public class WebSocketClient {
|
||||||
return session.getUpgradeRequest().getHeader(HttpHeaders.USER_AGENT);
|
return session.getUpgradeRequest().getHeader(HttpHeaders.USER_AGENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getCreatedTimestamp() {
|
public Instant getCreated() {
|
||||||
return this.created;
|
return this.created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue