Skip to content

Commit

Permalink
Cache-Control on Prometheus endpoint
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tpbrown authored Feb 26, 2019
1 parent a74e3a5 commit 6a20917
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -25,4 +27,4 @@ public void generateResponse(StaplerRequest request, StaplerResponse response, O
}
};
}
}
}

0 comments on commit 6a20917

Please sign in to comment.