Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable response code meters #6692

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/manual/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ maxThreads 1024
minThreads 8 The minimum number of threads to keep alive in the thread pool. Note that each Jetty connector consumes threads from the pool. See :ref:`HTTP connector <man-configuration-http>` how the thread counts are calculated.
maxQueuedRequests 1024 The maximum number of requests to queue before blocking
the acceptors.
responseMeteredLevel COARSE The response metered level to decide what response code meters are included
metricPrefix (none) The metricPrefix to use in the metric name for jetty metrics
idleThreadTimeout 1 minute The amount of time a worker thread can be idle before
being stopped.
nofileSoftLimit (none) The number of open file descriptors before a soft error is issued.
Expand Down
4 changes: 4 additions & 0 deletions dropwizard-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-annotation</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-jetty9</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.dropwizard.server;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.annotation.ResponseMeteredLevel;
import com.codahale.metrics.health.HealthCheckRegistry;
import com.codahale.metrics.jetty9.InstrumentedHandler;
import com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool;
Expand Down Expand Up @@ -56,6 +57,8 @@
import java.util.concurrent.BlockingQueue;
import java.util.stream.Collectors;

import static com.codahale.metrics.annotation.ResponseMeteredLevel.COARSE;

/**
* A base class for {@link ServerFactory} implementations.
* <p/>
Expand All @@ -82,6 +85,16 @@
* <td>The {@link ServerPushFilterFactory} configuration.</td>
* </tr>
* <tr>
* <td>{@code responseMeteredLevel}</td>
* <td>COARSE</td>
* <td>The response metered level to decide what response code meters are included.</td>
* </tr>
* <tr>
* <td>{@code metricPrefix}</td>
* <td></td>
* <td>The metricPrefix to use in the metric name for jetty metrics.</td>
* </tr>
* <tr>
* <td>{@code maxThreads}</td>
* <td>1024</td>
* <td>The maximum number of threads to use for requests.</td>
Expand Down Expand Up @@ -238,6 +251,13 @@ public abstract class AbstractServerFactory implements ServerFactory {
@NotNull
private ServerPushFilterFactory serverPush = new ServerPushFilterFactory();

@Valid
@NotNull
private ResponseMeteredLevel responseMeteredLevel = COARSE;

@Nullable
private String metricPrefix;

@Min(4)
private int maxThreads = 1024;

Expand Down Expand Up @@ -332,6 +352,17 @@ public void setServerPush(ServerPushFilterFactory serverPush) {
this.serverPush = serverPush;
}

@JsonProperty("responseMeteredLevel")
public ResponseMeteredLevel getResponseMeteredLevel() {
return responseMeteredLevel;
}

@JsonProperty("metricPrefix")
@Nullable
public String getMetricPrefix() {
return metricPrefix;
}

@JsonProperty
public int getMaxThreads() {
return maxThreads;
Expand Down Expand Up @@ -601,7 +632,7 @@ protected Handler createAppServlet(Server server,
}
handler.addServlet(new ServletHolder("jersey", jerseyContainer), jersey.getUrlPattern());
}
final InstrumentedHandler instrumented = new InstrumentedHandler(metricRegistry);
final InstrumentedHandler instrumented = new InstrumentedHandler(metricRegistry, metricPrefix, responseMeteredLevel);
instrumented.setServer(server);
instrumented.setHandler(handler);
return instrumented;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.dropwizard.server;

import com.codahale.metrics.annotation.ResponseMeteredLevel;
import io.dropwizard.Configuration;
import io.dropwizard.jersey.DropwizardResourceConfig;
import io.dropwizard.jersey.setup.JerseyContainerHolder;
Expand Down Expand Up @@ -68,6 +69,16 @@ void usesDefaultPatternWhenNoneSet() {
assertThat(jerseyEnvironment.getUrlPattern()).isEqualTo(DEFAULT_PATTERN);
}

@Test
void usesDefaultResponseMeteredLevelWhenNotSet() {
assertThat(serverFactory.getResponseMeteredLevel()).isEqualTo(ResponseMeteredLevel.COARSE);
}

@Test
void usesDefaultMetricPrefixWhenNotSet() {
assertThat(serverFactory.getMetricPrefix()).isNull();
}

/**
* Test implementation of {@link AbstractServerFactory} used to run {@link #createAppServlet}, which triggers the
* setting of {@link JerseyEnvironment#setUrlPattern(String)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import static com.codahale.metrics.annotation.ResponseMeteredLevel.ALL;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

Expand Down Expand Up @@ -87,6 +88,18 @@ void hasAMinimumNumberOfThreads() {
.isEqualTo(89);
}

@Test
void hasResponseMeteredLevel() {
assertThat(http.getResponseMeteredLevel())
.isEqualTo(ALL);
}

@Test
void hasMetricPrefix() {
assertThat(http.getMetricPrefix())
.isEqualTo("jetty");
}

@Test
void hasApplicationContextPath() {
assertThat(http.getApplicationContextPath()).isEqualTo("/app");
Expand Down
2 changes: 2 additions & 0 deletions dropwizard-core/src/test/resources/yaml/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ requestLog:
currentLogFilename: ./logs/requests.log
archivedLogFilenamePattern: ./logs/requests-%d.log.gz
archivedFileCount: 5
responseMeteredLevel: ALL
metricPrefix: jetty
gzip:
enabled: false
serverPush:
Expand Down