Skip to content

Commit

Permalink
Introduce metrics servlet timeout setting (apache#10886)
Browse files Browse the repository at this point in the history
*Motivation*

Generating metrics is an expensive task and it can take more than 30 seconds
if you have close to or more than a million topics.

*Modification*

This change provides a setting to adjust the async context timeout.

(cherry picked from commit c75d45b)
  • Loading branch information
sijie authored and eolivelli committed Nov 4, 2021
1 parent 59f4e3a commit 28cdad0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions conf/broker.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,11 @@ exposeManagedCursorMetricsInPrometheus=false
# Classname of Pluggable JVM GC metrics logger that can log GC specific metrics
# jvmGCMetricsLoggerClassName=

# Time in milliseconds that metrics endpoint would time out. Default is 30s.
# Increase it if there are a lot of topics to expose topic-level metrics.
# Set it to 0 to disable timeout.
metricsServletTimeoutMs=30000

### --- Functions --- ###

# Enable Functions Worker Service in Broker
Expand Down
5 changes: 5 additions & 0 deletions conf/standalone.conf
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,11 @@ webSocketMaxTextFrameSize=1048576
# Enable topic level metrics
exposeTopicLevelMetricsInPrometheus=true

# Time in milliseconds that metrics endpoint would time out. Default is 30s.
# Increase it if there are a lot of topics to expose topic-level metrics.
# Set it to 0 to disable timeout.
metricsServletTimeoutMs=30000

# Classname of Pluggable JVM GC metrics logger that can log GC specific metrics
# jvmGCMetricsLoggerClassName=

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,14 @@ public class ServiceConfiguration implements PulsarConfiguration {
)
private boolean exposePreciseBacklogInPrometheus = false;

@FieldContext(
category = CATEGORY_METRICS,
doc = "Time in milliseconds that metrics endpoint would time out. Default is 30s.\n" +
" Increase it if there are a lot of topics to expose topic-level metrics.\n" +
" Set it to 0 to disable timeout."
)
private long metricsServletTimeoutMs = 30000;

@FieldContext(
category = CATEGORY_METRICS,
doc = "Enable expose the backlog size for each subscription when generating stats.\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class PrometheusMetricsServlet extends HttpServlet {
private final PulsarService pulsar;
private final boolean shouldExportTopicMetrics;
private final boolean shouldExportConsumerMetrics;
private final long metricsServletTimeoutMs;
private List<PrometheusRawMetricsProvider> metricsProviders;

private ExecutorService executor = null;
Expand All @@ -54,6 +55,7 @@ public PrometheusMetricsServlet(PulsarService pulsar, boolean includeTopicMetric
this.pulsar = pulsar;
this.shouldExportTopicMetrics = includeTopicMetrics;
this.shouldExportConsumerMetrics = includeConsumerMetrics;
this.metricsServletTimeoutMs = pulsar.getConfiguration().getMetricsServletTimeoutMs();
}

@Override
Expand All @@ -65,6 +67,7 @@ public void init() throws ServletException {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
AsyncContext context = request.startAsync();
context.setTimeout(metricsServletTimeoutMs);
executor.execute(safeRun(() -> {
HttpServletResponse res = (HttpServletResponse) context.getResponse();
try {
Expand Down

0 comments on commit 28cdad0

Please sign in to comment.