use of io.opencensus.trace.export.SpanData in project ignite by apache.
the class OpenCensusTracingSpiTest method testPartitionsMapExchangeTracing.
/**
* Test checks that PME process in case of node left discovery event is traced correctly in positive case.
*/
@Test
public void testPartitionsMapExchangeTracing() throws Exception {
long curTopVer = grid(0).cluster().topologyVersion();
String leftNodeId = grid(GRID_CNT - 1).localNode().id().toString();
stopGrid(GRID_CNT - 1);
awaitPartitionMapExchange();
handler().flush();
// Check PME for NODE_LEFT event on remaining nodes:
for (int i = 0; i < GRID_CNT - 1; i++) {
List<SpanData> exchFutSpans = handler().spansReportedByNode(getTestIgniteInstanceName(i)).filter(span -> EXCHANGE_FUTURE.spanName().equals(span.getName())).filter(span -> span.getStatus() == Status.OK).filter(span -> AttributeValue.stringAttributeValue(String.valueOf(EventType.EVT_NODE_LEFT)).equals(span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT, SpanTags.TYPE)))).filter(span -> stringAttributeValue(leftNodeId).equals(span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)))).collect(Collectors.toList());
Assert.assertTrue(String.format("%s span not found (or more than 1), nodeId=%d, exchFutSpans=%s", EXCHANGE_FUTURE, i, exchFutSpans), exchFutSpans.size() == 1);
exchFutSpans.forEach(span -> {
SpanData parentSpan = handler().spanById(span.getParentSpanId());
Assert.assertNotNull("Parent span doesn't exist for " + span, parentSpan);
Assert.assertEquals("Parent span name is invalid " + parentSpan, DISCOVERY_NODE_LEFT.spanName(), parentSpan.getName());
Assert.assertEquals("Parent span is not related to joined node " + parentSpan, stringAttributeValue(leftNodeId), parentSpan.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)));
Assert.assertEquals("Exchange future major topology version is invalid " + span, AttributeValue.stringAttributeValue(String.valueOf(curTopVer + 1)), span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.RESULT, SpanTags.TOPOLOGY_VERSION, SpanTags.MAJOR)));
Assert.assertEquals("Exchange future minor version is invalid " + span, AttributeValue.stringAttributeValue("0"), span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.RESULT, SpanTags.TOPOLOGY_VERSION, SpanTags.MINOR)));
});
}
}
use of io.opencensus.trace.export.SpanData in project ignite by apache.
the class OpenCensusTracingSpiTest method testCommunicationMessages.
/**
* @throws Exception if failed.
*/
@Test
public void testCommunicationMessages() throws Exception {
IgniteEx ignite = grid(0);
IgniteEx ignite1 = grid(1);
try (MTC.TraceSurroundings ignore = MTC.support(ignite.context().tracing().create(CUSTOM_JOB_CALL))) {
ignite.compute(ignite.cluster().forNode(ignite1.localNode())).withNoFailover().call(() -> "");
}
handler().flush();
SpanData jobSpan = handler().spanByName(CUSTOM_JOB_CALL.spanName());
List<SpanData> data = handler().unrollByParent(jobSpan);
List<AttributeValue> nodejobMsgTags = data.stream().filter(it -> it.getAttributes().getAttributeMap().containsKey(SpanTags.MESSAGE)).map(it -> it.getAttributes().getAttributeMap().get(SpanTags.MESSAGE)).collect(Collectors.toList());
List<String> nodejobTraces = data.stream().map(SpanData::getName).collect(Collectors.toList());
assertEquals(nodejobTraces.toString(), 7, nodejobTraces.size());
assertEquals(1, nodejobTraces.stream().filter(it -> it.contains(CUSTOM_JOB_CALL.spanName())).count());
List<SpanData> sockWriteTraces = data.stream().filter(span -> span.getName().contains(COMMUNICATION_SOCKET_WRITE.spanName())).collect(Collectors.toList());
// request + response
assertEquals(2, sockWriteTraces.size());
sockWriteTraces.forEach(span -> assertTrue(parseInt(attributeValueToString(span.getAttributes().getAttributeMap().get(SOCKET_WRITE_BYTES))) > 0));
// request + response
assertEquals(2, nodejobTraces.stream().filter(it -> it.contains(COMMUNICATION_SOCKET_READ.spanName())).count());
// request + response
assertEquals(2, nodejobTraces.stream().filter(it -> it.contains(COMMUNICATION_REGULAR_PROCESS.spanName())).count());
assertTrue(nodejobMsgTags.stream().anyMatch(it -> it.equals(stringAttributeValue(COMMUNICATION_JOB_EXECUTE_REQUEST.spanName()))));
assertTrue(nodejobMsgTags.stream().anyMatch(it -> it.equals(stringAttributeValue(COMMUNICATION_JOB_EXECUTE_RESPONSE.spanName()))));
}
use of io.opencensus.trace.export.SpanData in project ignite by apache.
the class OpenCensusTracingSpiTest method testCustomEventContainsMessageClassTag.
/**
* Ensure that root discovery.custom.event have message.class with corresponding value.
*
* @throws Exception If failed.
*/
@Test
public void testCustomEventContainsMessageClassTag() throws Exception {
IgniteEx ignite = grid(0);
startGrid(GRID_CNT).createCache("New cache");
handler().flush();
// Only root discovery.custom.event spans have message.class tag.
List<SpanData> rootCustomEvtSpans = handler().allSpans().filter(spanData -> DISCOVERY_CUSTOM_EVENT.spanName().equals(spanData.getName()) && spanData.getParentSpanId() == null).collect(Collectors.toList());
// Check that there's at least one discovery.custom.event span with tag "message.class"
// and value "CacheAffinityChangeMessage"
assertTrue(rootCustomEvtSpans.stream().anyMatch(span -> "CacheAffinityChangeMessage".equals(attributeValueToString(span.getAttributes().getAttributeMap().get(SpanTags.MESSAGE_CLASS)))));
}
use of io.opencensus.trace.export.SpanData in project ignite by apache.
the class OpenCensusTxTracingConfigurationTest method testTxTraceDoesNotIncludeCommunicationTracesInCaseOfEmptyIncludedScopes.
/**
* Ensure that TX traces doesn't include COMMUNICATION sub-traces in case of empty set of included scopes.
*
* @throws Exception If Failed.
*/
@Test
public void testTxTraceDoesNotIncludeCommunicationTracesInCaseOfEmptyIncludedScopes() throws Exception {
IgniteEx client = startGrid("client");
client.tracingConfiguration().set(new TracingConfigurationCoordinates.Builder(TX).build(), new TracingConfigurationParameters.Builder().withSamplingRate(SAMPLING_RATE_ALWAYS).build());
Transaction tx = client.transactions().txStart(PESSIMISTIC, SERIALIZABLE);
client.cache(DEFAULT_CACHE_NAME).put(1, 1);
tx.commit();
handler().flush();
SpanId parentSpanId = handler().allSpans().filter(span -> SpanType.TX_NEAR_PREPARE.spanName().equals(span.getName())).collect(Collectors.toList()).get(0).getContext().getSpanId();
java.util.List<SpanData> gotSpans = handler().allSpans().filter(span -> parentSpanId.equals(span.getParentSpanId()) && SpanType.COMMUNICATION_SOCKET_WRITE.spanName().equals(span.getName())).collect(Collectors.toList());
assertTrue(gotSpans.isEmpty());
}
use of io.opencensus.trace.export.SpanData in project ignite by apache.
the class OpenCensusTxTracingConfigurationTest method testTxConfigurationSamplingRateHalfSamplesSomethingAboutHalfTransactions.
/**
* Ensure that specifying 0 < sapling rate < 1 within TX scope will trace some but not all transactions.
* Cause of probability nature of sampling, it's not possible to check that 0.5 sampling rate
* will result in exactly half of the transactions being traced.
*
* @throws Exception If Failed.
*/
@Test
public void testTxConfigurationSamplingRateHalfSamplesSomethingAboutHalfTransactions() throws Exception {
IgniteEx client = startGrid("client");
client.tracingConfiguration().set(new TracingConfigurationCoordinates.Builder(TX).build(), new TracingConfigurationParameters.Builder().withSamplingRate(0.5).build());
final int txAmount = 100;
for (int i = 0; i < txAmount; i++) client.transactions().txStart(PESSIMISTIC, SERIALIZABLE).commit();
handler().flush();
java.util.List<SpanData> gotSpans = handler().allSpans().filter(span -> SpanType.TX.spanName().equals(span.getName())).collect(Collectors.toList());
// Cause of probability nature of sampling, it's not possible to check that 0.5 sampling rate will end with
// 5 sampling transactions out of {@code txAmount},
// so we just check that some and not all transactions were traced.
assertTrue(!gotSpans.isEmpty() && gotSpans.size() < txAmount);
}
Aggregations