Search in sources :

Example 16 with MetricDescriptor

use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.

the class MetricsServiceTest method testUpdatesRenderedInOrder.

@Test
public void testUpdatesRenderedInOrder() {
    MetricsService metricsService = prepareMetricsService();
    testProbeSource.update(1, 1.5D);
    metricsService.collectMetrics(metricsCollectorMock);
    testProbeSource.update(2, 5.5D);
    metricsService.collectMetrics(metricsCollectorMock);
    InOrder inOrderLong = inOrder(metricsCollectorMock);
    InOrder inOrderDouble = inOrder(metricsCollectorMock);
    MetricDescriptor descRoot = metricsRegistry.newMetricDescriptor().withPrefix("test").withUnit(COUNT);
    MetricDescriptor descLongValue = descRoot.copy().withMetric("longValue");
    inOrderLong.verify(metricsCollectorMock).collectLong(descLongValue, 1);
    inOrderLong.verify(metricsCollectorMock).collectLong(descLongValue, 2);
    inOrderLong.verify(metricsCollectorMock, never()).collectLong(eq(descLongValue), anyLong());
    MetricDescriptor descDoubleValue = descRoot.copy().withMetric("doubleValue");
    inOrderDouble.verify(metricsCollectorMock).collectDouble(descDoubleValue, 1.5D);
    inOrderDouble.verify(metricsCollectorMock).collectDouble(descDoubleValue, 5.5D);
    inOrderDouble.verify(metricsCollectorMock, never()).collectDouble(eq(descDoubleValue), anyDouble());
}
Also used : MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) InOrder(org.mockito.InOrder) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with MetricDescriptor

use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.

the class MetricsServiceTest method testExclusion.

@Test
public void testExclusion() throws Exception {
    // configure metrics to keep the result only of the last collection cycle
    config.getMetricsConfig().setCollectionFrequencySeconds(5).getManagementCenterConfig().setRetentionSeconds(1);
    ExclusionProbeSource metricsSource = new ExclusionProbeSource();
    metricsRegistry.registerStaticMetrics(metricsSource, "testExclusion");
    MetricsService metricsService = prepareMetricsService();
    metricsSource.update(1, 2, 1.5D, 2.5D);
    metricsService.collectMetrics();
    MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
    readMetrics(metricsService, 0, metricConsumerMock);
    MetricDescriptor longRoot = DEFAULT_DESCRIPTOR_SUPPLIER.get().withPrefix("testExclusion").withUnit(COUNT);
    verify(metricConsumerMock).consumeLong(longRoot.copy().withMetric("notExcludedLong"), 1);
    verify(metricConsumerMock, never()).consumeLong(eq(longRoot.copy().withMetric("excludedLong")), anyLong());
    MetricDescriptor doubleRoot = DEFAULT_DESCRIPTOR_SUPPLIER.get().withPrefix("testExclusion").withUnit(COUNT);
    verify(metricConsumerMock).consumeDouble(doubleRoot.copy().withMetric("notExcludedDouble"), 1.5D);
    verify(metricConsumerMock, never()).consumeDouble(eq(doubleRoot.copy().withMetric("excludedDouble")), anyDouble());
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with MetricDescriptor

use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.

the class MetricsCompressorTest method testTwoMetrics_secondWithoutTags.

@Test
public void testTwoMetrics_secondWithoutTags() {
    DefaultMetricDescriptorSupplier supplier = new DefaultMetricDescriptorSupplier();
    MetricsCompressor compressor = new MetricsCompressor();
    MetricDescriptor metric1 = supplier.get().withPrefix("prefix").withMetric("metricName").withDiscriminator("ds", "dsName1").withUnit(COUNT);
    MetricDescriptor metric2 = metric1.copy().withMetric("metricName2");
    metric1.withTag("tag0", "tag0Value");
    compressor.addLong(metric1, 42L);
    compressor.addLong(metric2, 43L);
    byte[] blob = compressor.getBlobAndReset();
    MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
    MetricsCompressor.extractMetrics(blob, metricConsumerMock, supplierSpy);
    verify(metricConsumerMock).consumeLong(metric1, 42L);
    verify(metricConsumerMock).consumeLong(metric2, 43L);
    verifyNoMoreInteractions(metricConsumerMock);
    verify(supplierSpy, times(2)).get();
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with MetricDescriptor

use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.

the class DynamicMetricsCollectionTest method testDirectLong.

@Test
public void testDirectLong() {
    CapturingCollector capturingCollector = new CapturingCollector();
    MetricsRegistry metricsRegistry = new MetricsRegistryImpl(Logger.getLogger(MetricsRegistryImpl.class), INFO);
    metricsRegistry.registerDynamicMetricsProvider((descriptor, context) -> context.collect(descriptor.withPrefix("test"), "someMetric", INFO, BYTES, 42));
    metricsRegistry.collect(capturingCollector);
    MetricDescriptor expectedDescriptor = metricsRegistry.newMetricDescriptor().withPrefix("test").withUnit(BYTES).withMetric("someMetric");
    Number number = capturingCollector.captures().get(expectedDescriptor).singleCapturedValue();
    assertInstanceOf(Long.class, number);
    assertEquals(42, number.longValue());
}
Also used : MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with MetricDescriptor

use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.

the class MetricsServiceTest method testReadMetricsReadsLastTwoCollections.

@Test
public void testReadMetricsReadsLastTwoCollections() throws Exception {
    // configure metrics to keep the result of the last 2 collection cycles
    config.getMetricsConfig().setCollectionFrequencySeconds(1).getManagementCenterConfig().setRetentionSeconds(2);
    MetricsService metricsService = prepareMetricsService();
    testProbeSource.update(1, 1.5D);
    metricsService.collectMetrics();
    testProbeSource.update(2, 5.5D);
    metricsService.collectMetrics();
    MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
    InOrder inOrderLong = inOrder(metricConsumerMock);
    InOrder inOrderDouble = inOrder(metricConsumerMock);
    readMetrics(metricsService, 0, metricConsumerMock);
    MetricDescriptor longDescriptor = DEFAULT_DESCRIPTOR_SUPPLIER.get().withPrefix("test").withMetric("longValue").withUnit(COUNT);
    inOrderLong.verify(metricConsumerMock).consumeLong(longDescriptor, 1);
    inOrderLong.verify(metricConsumerMock).consumeLong(longDescriptor, 2);
    inOrderLong.verify(metricConsumerMock, never()).consumeLong(eq(longDescriptor), anyLong());
    MetricDescriptor doubleDescriptor = DEFAULT_DESCRIPTOR_SUPPLIER.get().withPrefix("test").withMetric("doubleValue").withUnit(COUNT);
    inOrderDouble.verify(metricConsumerMock).consumeDouble(doubleDescriptor, 1.5D);
    inOrderDouble.verify(metricConsumerMock).consumeDouble(doubleDescriptor, 5.5D);
    inOrderDouble.verify(metricConsumerMock, never()).consumeDouble(eq(doubleDescriptor), anyDouble());
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) InOrder(org.mockito.InOrder) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)58 QuickTest (com.hazelcast.test.annotation.QuickTest)27 Test (org.junit.Test)27 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)21 MetricConsumer (com.hazelcast.internal.metrics.MetricConsumer)19 CPGroupId (com.hazelcast.cp.CPGroupId)7 MetricsRegistry (com.hazelcast.internal.metrics.MetricsRegistry)6 Map (java.util.Map)4 MetricsCollector (com.hazelcast.internal.metrics.collectors.MetricsCollector)3 InOrder (org.mockito.InOrder)3 ClientStatistics (com.hazelcast.client.impl.statistics.ClientStatistics)2 DynamicMetricsProvider (com.hazelcast.internal.metrics.DynamicMetricsProvider)2 ProbeUnit (com.hazelcast.internal.metrics.ProbeUnit)2 UUID (java.util.UUID)2 Client (com.hazelcast.client.Client)1 ClientEngine (com.hazelcast.client.impl.ClientEngine)1 ClientContext (com.hazelcast.client.impl.spi.ClientContext)1 ProxyManager (com.hazelcast.client.impl.spi.ProxyManager)1 Member (com.hazelcast.cluster.Member)1 IAtomicLong (com.hazelcast.cp.IAtomicLong)1