Search in sources :

Example 56 with Histogram

use of com.codahale.metrics.Histogram in project riposte by Nike-Inc.

the class SignalFxAwareCodahaleMetricsCollectorTest method kitchen_sink_constructor_throws_IllegalArgumentException_when_passed_null_arguments.

@DataProvider(value = { "NULL_METRIC_REGISTRY", "NULL_METRIC_METADATA", "NULL_TIMER_BUILDER", "NULL_HISTORGRAM_BUILDER" })
@Test
public void kitchen_sink_constructor_throws_IllegalArgumentException_when_passed_null_arguments(NullArgScenario scenario) {
    // given
    MetricRegistry registry = scenario.metricRegistryIsNull ? null : metricRegistryMock;
    MetricMetadata metadata = scenario.metricMetadataIsNull ? null : metricMetadataMock;
    MetricBuilder<Timer> timerBuilder = scenario.timerBuilderIsNull ? null : timerBuilderMock;
    MetricBuilder<Histogram> histogramBuilder = scenario.histogramBuilderIsNull ? null : histogramBuilderMock;
    // when
    Throwable ex = catchThrowable(() -> new SignalFxAwareCodahaleMetricsCollector(registry, metadata, timerBuilder, histogramBuilder));
    // then
    assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage(scenario.expectedExceptionMessage);
}
Also used : Histogram(com.codahale.metrics.Histogram) MetricMetadata(com.signalfx.codahale.reporter.MetricMetadata) Timer(com.codahale.metrics.Timer) MetricRegistry(com.codahale.metrics.MetricRegistry) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 57 with Histogram

use of com.codahale.metrics.Histogram in project Singularity by HubSpot.

the class SingularityTaskReconciliation method startReconciliation.

public ReconciliationState startReconciliation() {
    if (statusUpdateHandler.getQueueFullness() >= configuration.getStatusQueueNearlyFull()) {
        LOG.info("Queue is nearly full, not starting reconciliation");
        return isRunningReconciliation.get() ? ReconciliationState.ALREADY_RUNNING : ReconciliationState.NO_DRIVER;
    }
    final long taskReconciliationStartedAt = System.currentTimeMillis();
    if (!isRunningReconciliation.compareAndSet(false, true)) {
        LOG.info("Reconciliation is already running, NOT starting a new reconciliation process");
        return ReconciliationState.ALREADY_RUNNING;
    }
    if (!schedulerClient.isRunning()) {
        LOG.trace("Not running reconciliation - no active scheduler present");
        isRunningReconciliation.set(false);
        return ReconciliationState.NO_DRIVER;
    }
    final List<SingularityTaskId> activeTaskIds = taskManager.getActiveTaskIds();
    LOG.info("Starting a reconciliation cycle - {} current active tasks", activeTaskIds.size());
    schedulerClient.reconcile(Collections.emptyList());
    scheduleReconciliationCheck(taskReconciliationStartedAt, activeTaskIds, 0, new Histogram(new UniformReservoir()));
    return ReconciliationState.STARTED;
}
Also used : Histogram(com.codahale.metrics.Histogram) UniformReservoir(com.codahale.metrics.UniformReservoir) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 58 with Histogram

use of com.codahale.metrics.Histogram in project torodb by torodb.

the class ConcurrentOplogBatchExecutorTest method testExecute.

@Test
public void testExecute() throws Exception {
    int batchSize = 100;
    int opsPerJob = 20;
    int subBatchSize = 11;
    int subBatchesPerJob = opsPerJob / subBatchSize + (opsPerJob % subBatchSize != 0 ? 1 : 0);
    int expectedSize = batchSize * subBatchesPerJob;
    //GIVEN
    CudAnalyzedOplogBatch batch = mock(CudAnalyzedOplogBatch.class);
    List<NamespaceJob> jobs = new ArrayList<>();
    for (int i = 0; i < batchSize; i++) {
        jobs.add(new NamespaceJob("db", "col", Lists.newArrayList(Stream.iterate(createAnalyzedOp(null), this::createAnalyzedOp).limit(opsPerJob).iterator())));
    }
    AtomicInteger callablesCounter = new AtomicInteger(0);
    ApplierContext context = new ApplierContext.Builder().setReapplying(true).setUpdatesAsUpserts(true).build();
    Histogram mockHistogram = mock(Histogram.class);
    Meter mockMeter = mock(Meter.class);
    given(batch.streamNamespaceJobs()).willReturn(jobs.stream());
    given(subBatchHeuristic.getSubBatchSize(any())).willReturn(subBatchSize);
    given(metrics.getSubBatchSizeHistogram()).willReturn(mockHistogram);
    given(metrics.getSubBatchSizeMeter()).willReturn(mockMeter);
    given(streamExecutor.execute(any())).willAnswer(new Answer<CompletableFuture<?>>() {

        @Override
        public CompletableFuture<?> answer(InvocationOnMock invocation) throws Throwable {
            CompletableFuture<Object> completableFuture = new CompletableFuture<>();
            completableFuture.complete(new Object());
            Stream<Callable<?>> callables = invocation.getArgument(0);
            callablesCounter.addAndGet((int) callables.count());
            return completableFuture;
        }
    });
    //WHEN
    executor.execute(batch, context);
    //THEN
    then(mockHistogram).should().update(expectedSize);
    then(mockMeter).should().mark(expectedSize);
    assertEquals(expectedSize, callablesCounter.get());
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) ArrayList(java.util.ArrayList) ApplierContext(com.torodb.mongodb.repl.oplogreplier.ApplierContext) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Stream(java.util.stream.Stream) Test(org.junit.Test)

Example 59 with Histogram

use of com.codahale.metrics.Histogram in project graylog2-server by Graylog2.

the class SearchesTest method fieldStatsRecordsMetrics.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void fieldStatsRecordsMetrics() throws Exception {
    FieldStatsResult result = searches.fieldStats("n", "*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    assertThat(metricRegistry.getTimers()).containsKey(REQUEST_TIMER_NAME);
    assertThat(metricRegistry.getHistograms()).containsKey(RANGES_HISTOGRAM_NAME);
    Timer timer = metricRegistry.timer(REQUEST_TIMER_NAME);
    assertThat(timer.getCount()).isEqualTo(1L);
    Histogram histogram = metricRegistry.histogram(RANGES_HISTOGRAM_NAME);
    assertThat(histogram.getCount()).isEqualTo(1L);
    assertThat(histogram.getSnapshot().getValues()).containsExactly(86400L);
}
Also used : FieldStatsResult(org.graylog2.indexer.results.FieldStatsResult) Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 60 with Histogram

use of com.codahale.metrics.Histogram in project graylog2-server by Graylog2.

the class SearchesTest method termsRecordsMetrics.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void termsRecordsMetrics() throws Exception {
    TermsResult result = searches.terms("n", 25, "*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    assertThat(metricRegistry.getTimers()).containsKey(REQUEST_TIMER_NAME);
    assertThat(metricRegistry.getHistograms()).containsKey(RANGES_HISTOGRAM_NAME);
    Timer timer = metricRegistry.timer(REQUEST_TIMER_NAME);
    assertThat(timer.getCount()).isEqualTo(1L);
    Histogram histogram = metricRegistry.histogram(RANGES_HISTOGRAM_NAME);
    assertThat(histogram.getCount()).isEqualTo(1L);
    assertThat(histogram.getSnapshot().getValues()).containsExactly(86400L);
}
Also used : Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) TermsResult(org.graylog2.indexer.results.TermsResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Aggregations

Histogram (com.codahale.metrics.Histogram)97 Test (org.junit.Test)39 Timer (com.codahale.metrics.Timer)34 Counter (com.codahale.metrics.Counter)30 Meter (com.codahale.metrics.Meter)29 Gauge (com.codahale.metrics.Gauge)17 Snapshot (com.codahale.metrics.Snapshot)12 Map (java.util.Map)11 Test (org.testng.annotations.Test)11 MetricRegistry (com.codahale.metrics.MetricRegistry)9 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 Metric (com.codahale.metrics.Metric)6 Reservoir (com.codahale.metrics.Reservoir)6 ZonedDateTime (java.time.ZonedDateTime)6 Properties (java.util.Properties)6 SortedMap (java.util.SortedMap)6 DateTime (org.joda.time.DateTime)6 UniformReservoir (com.codahale.metrics.UniformReservoir)5