use of org.apache.ignite.internal.processors.tracing.SpanType in project ignite by apache.
the class OpenCensusTxTracingConfigurationTest method testTxConfigurationSamplingRateNeverPreventsTxTracing.
/**
* Ensure that in case of sampling rate equals to 0.0 (Never) no transactions are traced.
*
* @throws Exception If Failed.
*/
@Test
public void testTxConfigurationSamplingRateNeverPreventsTxTracing() throws Exception {
IgniteEx client = startGrid("client");
client.tracingConfiguration().set(new TracingConfigurationCoordinates.Builder(TX).build(), new TracingConfigurationParameters.Builder().withSamplingRate(SAMPLING_RATE_NEVER).build());
client.transactions().txStart(PESSIMISTIC, SERIALIZABLE).commit();
handler().flush();
Set<String> unexpectedTxSpanNames = Arrays.stream(SpanType.values()).filter(spanType -> spanType.scope() == TX).map(SpanType::spanName).collect(Collectors.toSet());
java.util.List<SpanData> gotSpans = handler().allSpans().filter(span -> unexpectedTxSpanNames.contains(span.getName())).collect(Collectors.toList());
assertTrue(gotSpans.isEmpty());
}
use of org.apache.ignite.internal.processors.tracing.SpanType in project ignite by apache.
the class AbstractTracingTest method checkSpanExistences.
/**
* Checks that there's at least one span with given spanType and attributes.
*
* @param spanType Span type to be found.
* @param expAttrs Expected attributes.
* @return {@code true} if Span with given type and attributes was found, false otherwise.
*/
boolean checkSpanExistences(SpanType spanType, /* tagName: tagValue*/
Map<String, String> expAttrs) {
java.util.List<SpanData> gotSpans = hnd.allSpans().filter(span -> spanType.spanName().equals(span.getName())).collect(Collectors.toList());
for (SpanData specificTypeSpans : gotSpans) {
Map<String, AttributeValue> attrs = specificTypeSpans.getAttributes().getAttributeMap();
boolean matchFound = true;
for (Map.Entry<String, String> entry : expAttrs.entrySet()) {
if (!entry.getValue().equals(attributeValueToString(attrs.get(entry.getKey())))) {
matchFound = false;
break;
}
}
if (matchFound && expAttrs.size() == attrs.size())
return true;
}
return false;
}
use of org.apache.ignite.internal.processors.tracing.SpanType in project ignite by apache.
the class GridTracingManager method create.
/**
* {@inheritDoc}
*/
@Override
public Span create(@NotNull SpanType spanType, @Nullable byte[] serializedParentSpan) {
// Optimization for noop spi.
if (noop)
return NoopSpan.INSTANCE;
// Optimization for zero sampling rate == 0.
if ((serializedParentSpan.length == 0 || serializedParentSpan == null) && tracingConfiguration.get(new TracingConfigurationCoordinates.Builder(spanType.scope()).build()).samplingRate() == SAMPLING_RATE_NEVER)
return NoopSpan.INSTANCE;
// 1 byte: special flags;
// 1 bytes: spi type;
// 2 bytes: major protocol version;
// 2 bytes: minor protocol version;
// 4 bytes: spi specific serialized span length;
// n bytes: spi specific serialized span body;
// 4 bytes: span type
// 4 bytes included scopes size;
// 2 * included scopes size: included scopes items one by one;
Span span;
try {
if (serializedParentSpan == null || serializedParentSpan.length == 0)
return create(spanType, NoopSpan.INSTANCE);
// propagate serializedSpan as DeferredSpan.
if (serializedParentSpan[SPI_TYPE_OFF] != getSpi().type())
return new DeferredSpan(serializedParentSpan);
// propagate serializedSpan as DeferredSpan.
if (serializedParentSpan[MAJOR_PROTOCOL_VERSION_OFF] != MAJOR_PROTOCOL_VERSION)
return new DeferredSpan(serializedParentSpan);
// Deserialize and check minor protocol version.
// within the scope of the same major protocol version, protocol should be backwards compatible
byte minProtoVer = serializedParentSpan[MINOR_PROTOCOL_VERSION_OFF];
// Deserialize spi specific span size.
int spiSpecificSpanSize = bytesToInt(Arrays.copyOfRange(serializedParentSpan, SPI_SPECIFIC_SERIALIZED_SPAN_BYTES_LENGTH_OFF, SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF), 0);
SpanType parentSpanType = null;
Set<Scope> includedScopes = new HashSet<>();
// Fall through.
switch(minProtoVer) {
case 0:
{
// Deserialize parent span type.
parentSpanType = SpanType.fromIndex(bytesToInt(Arrays.copyOfRange(serializedParentSpan, SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF + spiSpecificSpanSize, SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF + PARENT_SPAN_TYPE_BYTES_LENGTH + spiSpecificSpanSize), 0));
// Deserialize included scopes size.
int includedScopesSize = bytesToInt(Arrays.copyOfRange(serializedParentSpan, SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF + PARENT_SPAN_TYPE_BYTES_LENGTH + spiSpecificSpanSize, SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF + PARENT_SPAN_TYPE_BYTES_LENGTH + INCLUDED_SCOPES_SIZE_BYTE_LENGTH + spiSpecificSpanSize), 0);
// Deserialize included scopes one by one.
for (int i = 0; i < includedScopesSize; i++) {
includedScopes.add(Scope.fromIndex(bytesToShort(Arrays.copyOfRange(serializedParentSpan, SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF + PARENT_SPAN_TYPE_BYTES_LENGTH + INCLUDED_SCOPES_SIZE_BYTE_LENGTH + spiSpecificSpanSize + i * SCOPE_INDEX_BYTE_LENGTH, SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF + PARENT_SPAN_TYPE_BYTES_LENGTH + INCLUDED_SCOPES_SIZE_BYTE_LENGTH + SCOPE_INDEX_BYTE_LENGTH + spiSpecificSpanSize + i * SCOPE_INDEX_BYTE_LENGTH), 0)));
}
}
}
assert parentSpanType != null;
// If there's is parent span and parent span supports given scope then...
if (parentSpanType.scope() == spanType.scope() || includedScopes.contains(spanType.scope())) {
// create new span as child span for parent span, using parents span included scopes.
Set<Scope> mergedIncludedScopes = new HashSet<>(includedScopes);
mergedIncludedScopes.add(parentSpanType.scope());
mergedIncludedScopes.remove(spanType.scope());
span = new SpanImpl(getSpi().create(spanType.spanName(), Arrays.copyOfRange(serializedParentSpan, SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF, SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF + spiSpecificSpanSize)), spanType, mergedIncludedScopes);
} else {
// do nothing;
return new DeferredSpan(serializedParentSpan);
// "suppress" parent span for a while, create new span as separate one.
// return spi.create(trace, null, includedScopes);
}
} catch (Exception e) {
LT.warn(log, "Failed to create span from serialized value " + "[serializedValue=" + Arrays.toString(serializedParentSpan) + "]");
span = NoopSpan.INSTANCE;
}
return enrichWithLocalNodeParameters(span);
}
Aggregations