@Test public void testWriterFiltersBasedOnParameter() throws IOException, ServletException { CollectorRegistry registry = new CollectorRegistry(); Gauge.build("a", "a help").register(registry); Gauge.build("b", "a help").register(registry); Gauge.build("c", "a help").register(registry); HttpServletRequest req = mock(HttpServletRequest.class); when(req.getParameterValues("name[]")).thenReturn(new String[]{"a", "b", "oneTheDoesntExist", ""}); HttpServletResponse resp = mock(HttpServletResponse.class); StringWriter stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter); when(resp.getWriter()).thenReturn(writer); new MetricsServlet(registry).doGet(req, resp); assertThat(stringWriter.toString()).contains("a 0.0"); assertThat(stringWriter.toString()).contains("b 0.0"); assertThat(stringWriter.toString()).doesNotContain("c 0.0"); }
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType(TextFormat.CONTENT_TYPE_004); Writer writer = new BufferedWriter(resp.getWriter()); try { TextFormat.write004(writer, registry.filteredMetricFamilySamples(parse(req))); writer.flush(); } finally { writer.close(); } }
MetricsServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType(TextFormat.CONTENT_TYPE_004); Writer writer = new BufferedWriter(resp.getWriter()); try { TextFormat.write004(writer, registry.filteredMetricFamilySamples(parse(req))); writer.flush(); } finally { writer.close(); } } }
MetricsServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType(TextFormat.CONTENT_TYPE_004); Writer writer = new BufferedWriter(resp.getWriter()); try { TextFormat.write004(writer, registry.filteredMetricFamilySamples(parse(req))); writer.flush(); } finally { writer.close(); } } MetricsServlet();  MetricsServlet(CollectorRegistry registry); }
MetricsServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType(TextFormat.CONTENT_TYPE_004); Writer writer = new BufferedWriter(resp.getWriter()); try { TextFormat.write004(writer, registry.filteredMetricFamilySamples(parse(req))); writer.flush(); } finally { writer.close(); } } MetricsServlet();  MetricsServlet(CollectorRegistry registry);  }
MetricsServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType(TextFormat.CONTENT_TYPE_004); Writer writer = new BufferedWriter(resp.getWriter()); try { TextFormat.write004(writer, registry.filteredMetricFamilySamples(parse(req))); writer.flush(); } finally { writer.close(); } } MetricsServlet();  MetricsServlet(CollectorRegistry registry);   }