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);
}
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();
}
Aggregations