Search in sources :

Example 46 with MetricDescriptor

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

the class DynamicMetricsCollectionTest method testDirectDoubleProveLevelFilters.

@Test
public void testDirectDoubleProveLevelFilters() {
    MetricsCollector collectorMock = mock(MetricsCollector.class);
    MetricsRegistry metricsRegistry = new MetricsRegistryImpl(Logger.getLogger(MetricsRegistryImpl.class), MANDATORY);
    metricsRegistry.registerDynamicMetricsProvider((descriptor, context) -> context.collect(descriptor.withPrefix("test"), "someMetric", INFO, BYTES, 42.42D));
    metricsRegistry.collect(collectorMock);
    MetricDescriptor expectedDescriptor = metricsRegistry.newMetricDescriptor().withPrefix("test").withUnit(BYTES).withMetric("someMetric");
    verify(collectorMock, never()).collectDouble(expectedDescriptor, 42.42D);
}
Also used : MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) 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 47 with MetricDescriptor

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

the class DynamicMetricsCollectionTest method testDirectDouble.

@Test
public void testDirectDouble() {
    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.42D));
    metricsRegistry.collect(capturingCollector);
    MetricDescriptor expectedDescriptor = metricsRegistry.newMetricDescriptor().withPrefix("test").withUnit(BYTES).withMetric("someMetric");
    Number number = capturingCollector.captures().get(expectedDescriptor).singleCapturedValue();
    assertInstanceOf(Double.class, number);
    assertEquals(42.42D, number.doubleValue(), 10E-6);
}
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 48 with MetricDescriptor

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

the class MetricsCompatibilityFileGenerator method generateBlob.

private static byte[] generateBlob() {
    DefaultMetricDescriptorSupplier supplier = new DefaultMetricDescriptorSupplier();
    MetricsCompressor compressor = new MetricsCompressor();
    MetricDescriptor metric1 = supplier.get().withPrefix("prefix").withMetric("deltaMetric1").withDiscriminator("ds", "dsName1").withUnit(COUNT);
    compressor.addLong(metric1, 42);
    MetricDescriptor metric2 = metric1.copy().withMetric("deltaMetric2");
    compressor.addDouble(metric2, -4.2);
    // use a 254 byte string to test long words in the dictionary
    String longPrefix = Stream.generate(() -> "a").limit(MetricsDictionary.MAX_WORD_LENGTH - 1).collect(Collectors.joining());
    MetricDescriptor metric3 = supplier.get().withPrefix(longPrefix).withMetric("longPrefixMetric").withUnit(BYTES);
    compressor.addLong(metric3, Integer.MAX_VALUE);
    return compressor.getBlobAndReset();
}
Also used : MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor)

Example 49 with MetricDescriptor

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

the class MetricsCompressorTest method testTwoMetrics_differentExcludedTargets.

@Test
public void testTwoMetrics_differentExcludedTargets() {
    DefaultMetricDescriptorSupplier supplier = new DefaultMetricDescriptorSupplier();
    MetricsCompressor compressor = new MetricsCompressor();
    MetricDescriptor metric1 = supplier.get().withPrefix("prefix").withMetric("metricName").withExcludedTarget(JMX);
    MetricDescriptor metric2 = metric1.copy().withExcludedTarget(MANAGEMENT_CENTER);
    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 50 with MetricDescriptor

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

the class MetricsCompressorTest method testSingleMetricWithoutPrefix.

@Test
public void testSingleMetricWithoutPrefix() {
    DefaultMetricDescriptorSupplier supplier = new DefaultMetricDescriptorSupplier();
    MetricsCompressor compressor = new MetricsCompressor();
    MetricDescriptor originalMetric = supplier.get().withMetric("metricName").withDiscriminator("ds", "dsName1").withUnit(COUNT).withTag("tag0", "tag0Value");
    compressor.addLong(originalMetric, 42L);
    byte[] blob = compressor.getBlobAndReset();
    MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
    MetricsCompressor.extractMetrics(blob, metricConsumerMock, supplierSpy);
    verify(metricConsumerMock).consumeLong(originalMetric, 42L);
    verifyNoMoreInteractions(metricConsumerMock);
    verify(supplierSpy, only()).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)

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