From 6a2091796c31203031c8b79593cd0a0cc7959763 Mon Sep 17 00:00:00 2001 From: Tim Brown Date: Tue, 26 Feb 2019 12:06:57 -0800 Subject: [PATCH] Cache-Control on Prometheus endpoint This change adds a `Cache-Control` header on the endpoint so that reverse proxies and load balancers in front of Jenkins do not cache metrics. --- .../java/org/jenkinsci/plugins/prometheus/MetricsRequest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/MetricsRequest.java b/src/main/java/org/jenkinsci/plugins/prometheus/MetricsRequest.java index dba89d37c..dec733d98 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/MetricsRequest.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/MetricsRequest.java @@ -17,6 +17,8 @@ public static HttpResponse prometheusResponse(final CollectorRegistry collectorR public void generateResponse(StaplerRequest request, StaplerResponse response, Object node) throws IOException, ServletException { response.setStatus(StaplerResponse.SC_OK); response.setContentType(TextFormat.CONTENT_TYPE_004); + response.addHeader("Cache-Control","must-revalidate,no-cache,no-store"); + StringWriter buffer = new StringWriter(); TextFormat.write004(buffer, collectorRegistry.metricFamilySamples()); @@ -25,4 +27,4 @@ public void generateResponse(StaplerRequest request, StaplerResponse response, O } }; } -} \ No newline at end of file +}