Skip to content

Commit

Permalink
Metrics idle timeout is now configurable (#2752)
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Bertone <bertone.giuseppe@gmail.com>
  • Loading branch information
Neurone authored Sep 12, 2021
1 parent 75324f3 commit ce1c8ef
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@

public class MetricsCLIOptions implements CLIOptions<MetricsConfiguration.Builder> {
private static final String TIMERS_ENABLED_FLAG = "--Xmetrics-timers-enabled";
private static final String IDLE_TIMEOUT_FLAG = "--Xmetrics-idle-timeout";

@CommandLine.Option(
names = TIMERS_ENABLED_FLAG,
hidden = true,
defaultValue = "true",
description = "Whether to enable timer metrics (default: ${DEFAULT-VALUE}).")
private Boolean timersEnabled = MetricsConfiguration.DEFAULT_TIMERS_ENABLED;
private Boolean timersEnabled = MetricsConfiguration.DEFAULT_METRICS_TIMERS_ENABLED;

@CommandLine.Option(
hidden = true,
names = {IDLE_TIMEOUT_FLAG},
paramLabel = "<INTEGER>",
description = "Timeout for metrics TCP connections, in seconds (default: ${DEFAULT-VALUE})",
arity = "1")
private int idleTimeout = MetricsConfiguration.DEFAULT_METRICS_IDLE_TIMEOUT_SECONDS;

private MetricsCLIOptions() {}

Expand All @@ -41,16 +50,19 @@ public static MetricsCLIOptions create() {
public static MetricsCLIOptions fromConfiguration(final MetricsConfiguration config) {
final MetricsCLIOptions metricsOptions = create();
metricsOptions.timersEnabled = config.isTimersEnabled();
metricsOptions.idleTimeout = config.getIdleTimeout();
return metricsOptions;
}

@Override
public MetricsConfiguration.Builder toDomainObject() {
return MetricsConfiguration.builder().timersEnabled(timersEnabled);
return MetricsConfiguration.builder().timersEnabled(timersEnabled).idleTimeout(idleTimeout);
}

@Override
public List<String> getCLIOptions() {
return Arrays.asList(TIMERS_ENABLED_FLAG + "=" + timersEnabled.toString());
return Arrays.asList(
TIMERS_ENABLED_FLAG + "=" + timersEnabled.toString(),
IDLE_TIMEOUT_FLAG + "=" + idleTimeout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ MetricsConfiguration.Builder createDefaultDomainObject() {
@Override
MetricsConfiguration.Builder createCustomizedDomainObject() {
return MetricsConfiguration.builder()
.timersEnabled(!MetricsConfiguration.DEFAULT_TIMERS_ENABLED);
.timersEnabled(!MetricsConfiguration.DEFAULT_METRICS_TIMERS_ENABLED)
.idleTimeout(MetricsConfiguration.DEFAULT_METRICS_IDLE_TIMEOUT_SECONDS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public class MetricsConfiguration {
private static final MetricsProtocol DEFAULT_METRICS_PROTOCOL = MetricsProtocol.PROMETHEUS;
private static final String DEFAULT_METRICS_PUSH_HOST = "127.0.0.1";
public static final int DEFAULT_METRICS_PUSH_PORT = 9001;
public static final Boolean DEFAULT_TIMERS_ENABLED = true;
public static final Boolean DEFAULT_METRICS_TIMERS_ENABLED = true;
public static final int DEFAULT_METRICS_IDLE_TIMEOUT_SECONDS = 60;

private final boolean enabled;
private final MetricsProtocol protocol;
Expand All @@ -49,6 +50,7 @@ public class MetricsConfiguration {
private final String prometheusJob;
private final List<String> hostsAllowlist;
private final boolean timersEnabled;
private final int idleTimeout;

public static Builder builder() {
return new Builder();
Expand All @@ -66,7 +68,8 @@ private MetricsConfiguration(
final int pushInterval,
final String prometheusJob,
final List<String> hostsAllowlist,
final boolean timersEnabled) {
final boolean timersEnabled,
final int idleTimeout) {
this.enabled = enabled;
this.port = port;
this.protocol = protocol;
Expand All @@ -79,6 +82,7 @@ private MetricsConfiguration(
this.prometheusJob = prometheusJob;
this.hostsAllowlist = hostsAllowlist;
this.timersEnabled = timersEnabled;
this.idleTimeout = idleTimeout;
}

public boolean isEnabled() {
Expand Down Expand Up @@ -143,6 +147,10 @@ public boolean isTimersEnabled() {
return timersEnabled;
}

public int getIdleTimeout() {
return idleTimeout;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
Expand All @@ -157,6 +165,8 @@ public String toString() {
.add("pushInterval", pushInterval)
.add("prometheusJob", prometheusJob)
.add("hostsAllowlist", hostsAllowlist)
.add("timersEnabled", timersEnabled)
.add("idleTimeout", idleTimeout)
.toString();
}

Expand All @@ -179,7 +189,9 @@ public boolean equals(final Object o) {
&& Objects.equals(metricCategories, that.metricCategories)
&& Objects.equals(pushHost, that.pushHost)
&& Objects.equals(prometheusJob, that.prometheusJob)
&& Objects.equals(hostsAllowlist, that.hostsAllowlist);
&& Objects.equals(hostsAllowlist, that.hostsAllowlist)
&& timersEnabled == that.timersEnabled
&& idleTimeout == that.idleTimeout;
}

@Override
Expand All @@ -195,7 +207,9 @@ public int hashCode() {
pushHost,
pushInterval,
prometheusJob,
hostsAllowlist);
hostsAllowlist,
timersEnabled,
idleTimeout);
}

public static class Builder {
Expand All @@ -210,7 +224,8 @@ public static class Builder {
private int pushInterval = 15;
private String prometheusJob = "besu-client";
private List<String> hostsAllowlist = Arrays.asList("localhost", "127.0.0.1");
private boolean timersEnabled = DEFAULT_TIMERS_ENABLED;
private boolean timersEnabled = DEFAULT_METRICS_TIMERS_ENABLED;
private int idleTimeout = DEFAULT_METRICS_IDLE_TIMEOUT_SECONDS;

private Builder() {}

Expand Down Expand Up @@ -281,6 +296,11 @@ public Builder timersEnabled(final boolean timersEnabled) {
return this;
}

public Builder idleTimeout(final int idleTimeout) {
this.idleTimeout = idleTimeout;
return this;
}

public MetricsConfiguration build() {
return new MetricsConfiguration(
enabled,
Expand All @@ -294,7 +314,8 @@ public MetricsConfiguration build() {
pushInterval,
prometheusJob,
hostsAllowlist,
timersEnabled);
timersEnabled,
idleTimeout);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public CompletableFuture<?> start() {
new HttpServerOptions()
.setHost(config.getHost())
.setPort(config.getPort())
.setIdleTimeout(60)
.setIdleTimeout(config.getIdleTimeout())
.setHandle100ContinueAutomatically(true)
.setCompressionSupported(true));

Expand Down

0 comments on commit ce1c8ef

Please sign in to comment.