use of org.apache.ignite.internal.processors.tracing.SpanType.DISCOVERY_NODE_JOIN_FINISH in project ignite by apache.
the class OpenCensusTracingSpiTest method testNodeJoinTracing.
/**
* Test checks that node join process is traced correctly in positive case.
*/
@Test
public void testNodeJoinTracing() throws Exception {
IgniteEx joinedNode = startGrid(GRID_CNT);
awaitPartitionMapExchange();
// Consistent id is the same with node name.
List<String> clusterNodeNames = grid(0).cluster().nodes().stream().map(node -> (String) node.consistentId()).collect(Collectors.toList());
handler().flush();
String joinedNodeId = joinedNode.localNode().id().toString();
// Check existence of Traces.Discovery.NODE_JOIN_REQUEST spans with OK status on all nodes:
Map<AttributeValue, SpanData> nodeJoinReqSpans = handler().allSpans().filter(span -> DISCOVERY_NODE_JOIN_REQUEST.spanName().equals(span.getName())).filter(span -> span.getStatus() == Status.OK).filter(span -> stringAttributeValue(joinedNodeId).equals(span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)))).collect(Collectors.toMap(span -> span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.NODE, SpanTags.NAME)), span -> span));
// NODE_JOIN_REQUEST must be processed at least on coordinator node.
// For other nodes there is no such guarantee.
int CRD_IDX = 0;
clusterNodeNames.stream().filter(node -> node.endsWith(String.valueOf(CRD_IDX))).forEach(nodeName -> Assert.assertTrue(String.format("%s not found on node with name=%s, nodeJoinReqSpans=%s", DISCOVERY_NODE_JOIN_REQUEST, nodeName, nodeJoinReqSpans), nodeJoinReqSpans.containsKey(stringAttributeValue(nodeName))));
// Check existence of Traces.Discovery.NODE_JOIN_ADD spans with OK status on all nodes:
for (int i = 0; i <= GRID_CNT; i++) {
List<SpanData> nodeJoinAddSpans = handler().spansReportedByNode(getTestIgniteInstanceName(i)).filter(span -> DISCOVERY_NODE_JOIN_ADD.spanName().equals(span.getName())).filter(span -> span.getStatus() == Status.OK).filter(span -> stringAttributeValue(joinedNodeId).equals(span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)))).collect(Collectors.toList());
Assert.assertTrue(String.format("%s span not found, nodeId=%d", DISCOVERY_NODE_JOIN_ADD, i), !nodeJoinReqSpans.isEmpty());
nodeJoinAddSpans.forEach(spanData -> {
SpanData parentSpan = handler().spanById(spanData.getParentSpanId());
Assert.assertNotNull("Parent span doesn't exist for " + spanData, parentSpan);
Assert.assertEquals("Parent span name is invalid, parentSpan=" + parentSpan, DISCOVERY_NODE_JOIN_REQUEST.spanName(), parentSpan.getName());
Assert.assertEquals("Parent span is not related to joined node, parentSpan=" + parentSpan, stringAttributeValue(joinedNodeId), parentSpan.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)));
});
}
// Check existence of Traces.Discovery.NODE_JOIN_FINISH spans with OK status on all nodes:
for (int i = 0; i <= GRID_CNT; i++) {
List<SpanData> nodeJoinAddSpans = handler().spansReportedByNode(getTestIgniteInstanceName(i)).filter(span -> DISCOVERY_NODE_JOIN_FINISH.spanName().equals(span.getName())).filter(span -> span.getStatus() == Status.OK).filter(span -> stringAttributeValue(joinedNodeId).equals(span.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)))).collect(Collectors.toList());
Assert.assertTrue(String.format("%s span not found, nodeId=%d", DISCOVERY_NODE_JOIN_FINISH, i), !nodeJoinReqSpans.isEmpty());
nodeJoinAddSpans.forEach(spanData -> {
SpanData parentSpan = handler().spanById(spanData.getParentSpanId());
Assert.assertNotNull("Parent span doesn't exist for " + spanData, parentSpan);
Assert.assertEquals("Parent span name is invalid " + parentSpan, DISCOVERY_NODE_JOIN_ADD.spanName(), parentSpan.getName());
Assert.assertEquals("Parent span is not related to joined node " + parentSpan, stringAttributeValue(joinedNodeId), parentSpan.getAttributes().getAttributeMap().get(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID)));
});
}
}
Aggregations