use of com.google.gerrit.metrics.Description in project gerrit by GerritCodeReview.
the class PerformanceLogContextTest method timerMetricsOutsidePerformanceLogContextDoNotCreatePerformanceLog.
@Test
public void timerMetricsOutsidePerformanceLogContextDoNotCreatePerformanceLog() {
assertThat(LoggingContext.getInstance().isPerformanceLogging()).isFalse();
assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).isEmpty();
Timer0 timer0 = metricMaker.newTimer("test1/latency", new Description("Latency metric for testing"));
timer0.start().close();
Timer1<Integer> timer1 = metricMaker.newTimer("test2/latency", new Description("Latency metric for testing"), Field.ofInteger("account", Metadata.Builder::accountId).build());
timer1.start(1000000).close();
Timer2<Integer, Integer> timer2 = metricMaker.newTimer("test3/latency", new Description("Latency metric for testing"), Field.ofInteger("account", Metadata.Builder::accountId).build(), Field.ofInteger("change", Metadata.Builder::changeId).build());
timer2.start(1000000, 123).close();
Timer3<Integer, Integer, String> timer3 = metricMaker.newTimer("test4/latency", new Description("Latency metric for testing"), Field.ofInteger("account", Metadata.Builder::accountId).build(), Field.ofInteger("change", Metadata.Builder::changeId).build(), Field.ofString("project", Metadata.Builder::projectName).build());
timer3.start(1000000, 123, "value3").close();
assertThat(LoggingContext.getInstance().isPerformanceLogging()).isFalse();
assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).isEmpty();
assertThat(testPerformanceLogger.logEntries()).isEmpty();
}
use of com.google.gerrit.metrics.Description in project gerrit by GerritCodeReview.
the class PerformanceLogContextTest method timerMetricsInsidePerformanceLogContextCreatePerformanceLog.
@Test
public void timerMetricsInsidePerformanceLogContextCreatePerformanceLog() {
assertThat(LoggingContext.getInstance().isPerformanceLogging()).isFalse();
assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).isEmpty();
try (PerformanceLogContext traceContext = new PerformanceLogContext(config, performanceLoggers)) {
assertThat(LoggingContext.getInstance().isPerformanceLogging()).isTrue();
Timer0 timer0 = metricMaker.newTimer("test1/latency", new Description("Latency metric for testing"));
timer0.start().close();
Timer1<Integer> timer1 = metricMaker.newTimer("test2/latency", new Description("Latency metric for testing"), Field.ofInteger("account", Metadata.Builder::accountId).build());
timer1.start(1000000).close();
Timer2<Integer, Integer> timer2 = metricMaker.newTimer("test3/latency", new Description("Latency metric for testing"), Field.ofInteger("account", Metadata.Builder::accountId).build(), Field.ofInteger("change", Metadata.Builder::changeId).build());
timer2.start(1000000, 123).close();
Timer3<Integer, Integer, String> timer3 = metricMaker.newTimer("test4/latency", new Description("Latency metric for testing"), Field.ofInteger("account", Metadata.Builder::accountId).build(), Field.ofInteger("change", Metadata.Builder::changeId).build(), Field.ofString("project", Metadata.Builder::projectName).build());
timer3.start(1000000, 123, "foo/bar").close();
assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).hasSize(4);
}
assertThat(testPerformanceLogger.logEntries()).containsExactly(PerformanceLogEntry.create("test1/latency", Metadata.empty()), PerformanceLogEntry.create("test2/latency", Metadata.builder().accountId(1000000).build()), PerformanceLogEntry.create("test3/latency", Metadata.builder().accountId(1000000).changeId(123).build()), PerformanceLogEntry.create("test4/latency", Metadata.builder().accountId(1000000).changeId(123).projectName("foo/bar").build())).inOrder();
assertThat(LoggingContext.getInstance().isPerformanceLogging()).isFalse();
assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).isEmpty();
}
Aggregations