Add metric for content-length header distribution
This commit is contained in:
parent
d1ada7f998
commit
3e01bc1174
|
@ -94,6 +94,7 @@ import org.whispersystems.textsecuregcm.currency.CurrencyConversionManager;
|
||||||
import org.whispersystems.textsecuregcm.currency.FixerClient;
|
import org.whispersystems.textsecuregcm.currency.FixerClient;
|
||||||
import org.whispersystems.textsecuregcm.currency.FtxClient;
|
import org.whispersystems.textsecuregcm.currency.FtxClient;
|
||||||
import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager;
|
import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager;
|
||||||
|
import org.whispersystems.textsecuregcm.filters.ContentLengthFilter;
|
||||||
import org.whispersystems.textsecuregcm.filters.RemoteDeprecationFilter;
|
import org.whispersystems.textsecuregcm.filters.RemoteDeprecationFilter;
|
||||||
import org.whispersystems.textsecuregcm.filters.TimestampResponseFilter;
|
import org.whispersystems.textsecuregcm.filters.TimestampResponseFilter;
|
||||||
import org.whispersystems.textsecuregcm.limits.PreKeyRateLimiter;
|
import org.whispersystems.textsecuregcm.limits.PreKeyRateLimiter;
|
||||||
|
@ -545,6 +546,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
|
||||||
environment.servlets().addFilter("RemoteDeprecationFilter", new RemoteDeprecationFilter(dynamicConfigurationManager))
|
environment.servlets().addFilter("RemoteDeprecationFilter", new RemoteDeprecationFilter(dynamicConfigurationManager))
|
||||||
.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
|
.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
|
||||||
|
|
||||||
|
environment.jersey().register(new ContentLengthFilter(TrafficSource.HTTP));
|
||||||
environment.jersey().register(MultiRecipientMessageProvider.class);
|
environment.jersey().register(MultiRecipientMessageProvider.class);
|
||||||
environment.jersey().register(new MetricsApplicationEventListener(TrafficSource.HTTP));
|
environment.jersey().register(new MetricsApplicationEventListener(TrafficSource.HTTP));
|
||||||
environment.jersey().register(new PolymorphicAuthDynamicFeature<>(ImmutableMap.of(Account.class, accountAuthFilter,
|
environment.jersey().register(new PolymorphicAuthDynamicFeature<>(ImmutableMap.of(Account.class, accountAuthFilter,
|
||||||
|
@ -556,7 +558,10 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
|
||||||
///
|
///
|
||||||
WebSocketEnvironment<Account> webSocketEnvironment = new WebSocketEnvironment<>(environment, config.getWebSocketConfiguration(), 90000);
|
WebSocketEnvironment<Account> webSocketEnvironment = new WebSocketEnvironment<>(environment, config.getWebSocketConfiguration(), 90000);
|
||||||
webSocketEnvironment.setAuthenticator(new WebSocketAccountAuthenticator(accountAuthenticator));
|
webSocketEnvironment.setAuthenticator(new WebSocketAccountAuthenticator(accountAuthenticator));
|
||||||
webSocketEnvironment.setConnectListener(new AuthenticatedConnectListener(receiptSender, messagesManager, messageSender, apnFallbackManager, clientPresenceManager, retrySchedulingExecutor));
|
webSocketEnvironment.setConnectListener(
|
||||||
|
new AuthenticatedConnectListener(receiptSender, messagesManager, messageSender, apnFallbackManager,
|
||||||
|
clientPresenceManager, retrySchedulingExecutor));
|
||||||
|
webSocketEnvironment.jersey().register(new ContentLengthFilter(TrafficSource.WEBSOCKET));
|
||||||
webSocketEnvironment.jersey().register(MultiRecipientMessageProvider.class);
|
webSocketEnvironment.jersey().register(MultiRecipientMessageProvider.class);
|
||||||
webSocketEnvironment.jersey().register(new MetricsApplicationEventListener(TrafficSource.WEBSOCKET));
|
webSocketEnvironment.jersey().register(new MetricsApplicationEventListener(TrafficSource.WEBSOCKET));
|
||||||
webSocketEnvironment.jersey().register(new KeepAliveController(clientPresenceManager));
|
webSocketEnvironment.jersey().register(new KeepAliveController(clientPresenceManager));
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2021 Signal Messenger, LLC
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.whispersystems.textsecuregcm.filters;
|
||||||
|
|
||||||
|
import static com.codahale.metrics.MetricRegistry.name;
|
||||||
|
|
||||||
|
import io.micrometer.core.instrument.Metrics;
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.ws.rs.container.ContainerRequestContext;
|
||||||
|
import javax.ws.rs.container.ContainerRequestFilter;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.whispersystems.textsecuregcm.metrics.TrafficSource;
|
||||||
|
|
||||||
|
public class ContentLengthFilter implements ContainerRequestFilter {
|
||||||
|
|
||||||
|
private static final String CONTENT_LENGTH_DISTRIBUTION_NAME = name(ContentLengthFilter.class, "contentLength");
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ContentLengthFilter.class);
|
||||||
|
private final TrafficSource trafficSource;
|
||||||
|
|
||||||
|
public ContentLengthFilter(final TrafficSource trafficeSource) {
|
||||||
|
this.trafficSource = trafficeSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void filter(final ContainerRequestContext requestContext) throws IOException {
|
||||||
|
try {
|
||||||
|
Metrics.summary(CONTENT_LENGTH_DISTRIBUTION_NAME, "trafficSource", trafficSource.name().toLowerCase()).record(requestContext.getLength());
|
||||||
|
} catch (final Exception e) {
|
||||||
|
logger.warn("Error recording content length", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2021 Signal Messenger, LLC
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.whispersystems.textsecuregcm.filters;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import javax.ws.rs.container.ContainerRequestContext;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.whispersystems.textsecuregcm.metrics.TrafficSource;
|
||||||
|
|
||||||
|
class ContentLengthFilterTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testFilter() throws Exception {
|
||||||
|
|
||||||
|
final ContentLengthFilter contentLengthFilter = new ContentLengthFilter(TrafficSource.WEBSOCKET);
|
||||||
|
|
||||||
|
final ContainerRequestContext requestContext = mock(ContainerRequestContext.class);
|
||||||
|
|
||||||
|
when(requestContext.getLength()).thenReturn(-1);
|
||||||
|
when(requestContext.getLength()).thenReturn(Integer.MAX_VALUE);
|
||||||
|
when(requestContext.getLength()).thenThrow(RuntimeException.class);
|
||||||
|
|
||||||
|
contentLengthFilter.filter(requestContext);
|
||||||
|
contentLengthFilter.filter(requestContext);
|
||||||
|
contentLengthFilter.filter(requestContext);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue