PrometheusMetric implements Metric { @Override public void stopTiming(Object timerObj) { if (timerObj == null) { return; } Summary.Timer timer = (Summary.Timer) timerObj; timer.observeDuration(); } PrometheusMetric(CollectorRegistry registry, ConcurrentMap<String, Collector> namesToCollectors, PrometheusExporter exporter, String namespace);  PrometheusMetric(CollectorRegistry registry,
                            ConcurrentMap<String, Collector> namesToCollectors,
                            PrometheusExporter exporter,
                            String namespace,
                            boolean isLabelRequestDomainNameEnable,
                            boolean isLabelPrincipalDomainNameEnable,
                            boolean isLabelHttpMethodNameEnable,
                            boolean isLabelHttpStatusNameEnable,
                            boolean isLabelApiNameEnable); @Override void increment(String metricName); @Override void increment(String metricName, String requestDomainName); @Override void increment(String metricName, String requestDomainName, String principalDomainName); @Override void increment(String metricName, String requestDomainName, int count); @Override void increment(String metricName, String requestDomainName, String principalDomainName, int count); @Override void increment(String metricName, String requestDomainName, String principalDomainName, String httpMethod, int httpStatus, String apiName); @Override Object startTiming(String metricName, String requestDomainName); @Override Object startTiming(String metricName, String requestDomainName, String principalDomainName); @Override Object startTiming(String metricName, String requestDomainName, String principalDomainName, String httpMethod, String apiName); @Override void stopTiming(Object timerObj); @Override void stopTiming(Object timerObj, String requestDomainName, String principalDomainName); @Override void flush(); @Override void quit(); static final String REQUEST_DOMAIN_LABEL_NAME; static final String PRINCIPAL_DOMAIN_LABEL_NAME; static final String REQUEST_HTTP_METHOD_LABEL_NAME; static final String REQUEST_HTTP_STATUS_LABEL_NAME; static final String REQUEST_API_LABEL_NAME; static final String METRIC_NAME_DELIMITER; static final String COUNTER_SUFFIX; static final String TIMER_UNIT; }
@Test public void testStopTiming() { Summary.Timer timer = mock(Summary.Timer.class); PrometheusMetric metric = new PrometheusMetric(null, null, null, "", false, false, false, false, false); metric.stopTiming(timer); verify(timer, times(1)).observeDuration(); metric.stopTiming(timer, "request_domain", "principal_domain"); verify(timer, times(2)).observeDuration(); }
@Test public void testStopTimingOnNull() { PrometheusMetric metric = new PrometheusMetric(null, null, null, "", false, false, false, false, false); metric.stopTiming(null); }