Search in sources :

Example 1 with ProbeUnit

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

the class MetricsCompressor method writeDescriptor.

@SuppressWarnings({ "checkstyle:CyclomaticComplexity", "checkstyle:NPathComplexity" })
private void writeDescriptor(MetricDescriptor originalDescriptor) throws IOException, LongWordException {
    MetricDescriptor descriptor = prepareDescriptor(originalDescriptor);
    int mask = calculateDescriptorMask(descriptor);
    tmpDos.writeByte(mask);
    if ((mask & MASK_PREFIX) == 0) {
        tmpDos.writeInt(getDictionaryId(descriptor.prefix()));
    }
    if ((mask & MASK_METRIC) == 0) {
        tmpDos.writeInt(getDictionaryId(descriptor.metric()));
    }
    if ((mask & MASK_DISCRIMINATOR) == 0) {
        tmpDos.writeInt(getDictionaryId(descriptor.discriminator()));
    }
    if ((mask & MASK_DISCRIMINATOR_VALUE) == 0) {
        tmpDos.writeInt(getDictionaryId(descriptor.discriminatorValue()));
    }
    if ((mask & MASK_UNIT) == 0) {
        ProbeUnit unit = descriptor.unit();
        if (unit != null) {
            tmpDos.writeByte(unit.ordinal());
        } else {
            tmpDos.writeByte(NULL_UNIT);
        }
    }
    if ((mask & MASK_EXCLUDED_TARGETS) == 0) {
        tmpDos.writeByte(MetricTarget.bitset(descriptor.excludedTargets()));
    }
    if ((mask & MASK_TAG_COUNT) == 0) {
        tmpDos.writeByte(descriptor.tagCount());
    }
    // further compression is possible by writing only the different tags
    for (int i = 0; i < descriptor.tagCount(); i++) {
        String tag = descriptor.tag(i);
        String tagValue = descriptor.tagValue(i);
        tmpDos.writeInt(getDictionaryId(tag));
        tmpDos.writeInt(getDictionaryId(tagValue));
    }
    count++;
    lastDescriptor = copyDescriptor(descriptor, lastDescriptor);
}
Also used : MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ProbeUnit(com.hazelcast.internal.metrics.ProbeUnit)

Example 2 with ProbeUnit

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

the class MetricsCompressorTest method testNewUnitIsConvertedToTag.

@Test
public void testNewUnitIsConvertedToTag() {
    boolean isNewUnitIntroduced = false;
    ProbeUnit aNewUnit = null;
    for (ProbeUnit unit : ProbeUnit.values()) {
        if (unit.isNewUnit()) {
            isNewUnitIntroduced = true;
            aNewUnit = unit;
        }
    }
    assumeTrue(isNewUnitIntroduced);
    MetricDescriptor originalMetric = supplier.get().withPrefix("prefix").withMetric("metricName").withDiscriminator("ds", "dsName1").withUnit(aNewUnit).withTag("tag0", "tag0Value");
    compressor.addLong(originalMetric, 42L);
    byte[] blob = compressor.getBlobAndReset();
    MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
    MetricsCompressor.extractMetrics(blob, metricConsumerMock, supplierSpy);
    MetricDescriptor expectedMetric = supplier.get().withPrefix("prefix").withMetric("metricName").withDiscriminator("ds", "dsName1").withUnit(null).withTag("tag0", "tag0Value").withTag("metric-unit", aNewUnit.name());
    verify(metricConsumerMock).consumeLong(expectedMetric, 42L);
    verifyNoMoreInteractions(metricConsumerMock);
    verify(supplierSpy, only()).get();
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ProbeUnit(com.hazelcast.internal.metrics.ProbeUnit) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)2 ProbeUnit (com.hazelcast.internal.metrics.ProbeUnit)2 MetricConsumer (com.hazelcast.internal.metrics.MetricConsumer)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1