Search in sources :

Example 16 with Description

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();
}
Also used : Description(com.google.gerrit.metrics.Description) Timer0(com.google.gerrit.metrics.Timer0) Test(org.junit.Test)

Example 17 with Description

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();
}
Also used : Description(com.google.gerrit.metrics.Description) Timer0(com.google.gerrit.metrics.Timer0) Test(org.junit.Test)

Aggregations

Description (com.google.gerrit.metrics.Description)17 Test (org.junit.Test)10 Counter (com.codahale.metrics.Counter)3 Timer0 (com.google.gerrit.metrics.Timer0)3 MemoryUsage (java.lang.management.MemoryUsage)2 Counter0 (com.google.gerrit.metrics.Counter0)1 Metadata (com.google.gerrit.server.logging.Metadata)1 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)1 MemoryMXBean (java.lang.management.MemoryMXBean)1 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1