use of org.apache.ignite.spi.tracing.Scope in project ignite by apache.
the class GridTracingManager method serialize.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public byte[] serialize(@NotNull Span span) {
// Optimization for noop spi.
if (noop)
return NoopTracing.NOOP_SERIALIZED_SPAN;
// Optimization for NoopSpan.
if (span == NoopSpan.INSTANCE)
return NoopTracing.NOOP_SERIALIZED_SPAN;
if (span instanceof DeferredSpan)
return ((DeferredSpan) span).serializedSpan();
// Spi specific serialized span.
byte[] spiSpecificSerializedSpan = getSpi().serialize(((SpanImpl) span).spiSpecificSpan());
int serializedSpanLen = SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF + PARENT_SPAN_TYPE_BYTES_LENGTH + INCLUDED_SCOPES_SIZE_BYTE_LENGTH + spiSpecificSerializedSpan.length + SCOPE_INDEX_BYTE_LENGTH * span.includedScopes().size();
byte[] serializedSpanBytes = new byte[serializedSpanLen];
// Skip special flags bytes.
// Spi type idx.
serializedSpanBytes[SPI_TYPE_OFF] = getSpi().type();
// Major protocol version;
serializedSpanBytes[MAJOR_PROTOCOL_VERSION_OFF] = MAJOR_PROTOCOL_VERSION;
// Minor protocol version;
serializedSpanBytes[MINOR_PROTOCOL_VERSION_OFF] = MINOR_PROTOCOL_VERSION;
// Spi specific serialized span length.
System.arraycopy(intToBytes(spiSpecificSerializedSpan.length), 0, serializedSpanBytes, SPI_SPECIFIC_SERIALIZED_SPAN_BYTES_LENGTH_OFF, SPI_SPECIFIC_SERIALIZED_SPAN_BYTES_LENGTH);
// Spi specific span.
System.arraycopy(spiSpecificSerializedSpan, 0, serializedSpanBytes, SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF, spiSpecificSerializedSpan.length);
// Span type.
System.arraycopy(intToBytes(span.type().index()), 0, serializedSpanBytes, SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF + spiSpecificSerializedSpan.length, PARENT_SPAN_TYPE_BYTES_LENGTH);
assert span.includedScopes() != null;
// Included scope size
System.arraycopy(intToBytes(span.includedScopes().size()), 0, serializedSpanBytes, SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF + PARENT_SPAN_TYPE_BYTES_LENGTH + spiSpecificSerializedSpan.length, INCLUDED_SCOPES_SIZE_BYTE_LENGTH);
int includedScopesCnt = 0;
if (!span.includedScopes().isEmpty()) {
for (Scope includedScope : span.includedScopes()) {
System.arraycopy(shortToBytes(includedScope.idx()), 0, serializedSpanBytes, SPI_SPECIFIC_SERIALIZED_SPAN_BODY_OFF + PARENT_SPAN_TYPE_BYTES_LENGTH + INCLUDED_SCOPES_SIZE_BYTE_LENGTH + spiSpecificSerializedSpan.length + SCOPE_INDEX_BYTE_LENGTH * includedScopesCnt++, SCOPE_INDEX_BYTE_LENGTH);
}
}
return serializedSpanBytes;
}
use of org.apache.ignite.spi.tracing.Scope in project ignite by apache.
the class GridTracingConfigurationManager method resetAll.
/**
* {@inheritDoc}
*/
@Override
public void resetAll(@Nullable Scope scope) throws IgniteException {
HashMap<TracingConfigurationCoordinates, TracingConfigurationParameters> newTracingConfiguration;
if (scope != null) {
newTracingConfiguration = new HashMap<>(tracingConfiguration.entrySet().stream().filter(e -> e.getKey().scope() != scope).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
TracingConfigurationCoordinates scopeSpecificCoordinates = new TracingConfigurationCoordinates.Builder(scope).build();
newTracingConfiguration.put(scopeSpecificCoordinates, DEFAULT_CONFIGURATION_MAP.get(scopeSpecificCoordinates));
} else
newTracingConfiguration = new HashMap<>(DEFAULT_CONFIGURATION_MAP);
try {
distributedTracingConfiguration.propagate(newTracingConfiguration);
} catch (IgniteCheckedException e) {
String warningMsg = String.format(WARNING_MSG_TRACING_CONFIG_UPDATE_FAILED_SCOPE, scope);
log.warning(warningMsg, e);
throw new IgniteException(warningMsg, e);
}
}
use of org.apache.ignite.spi.tracing.Scope in project ignite by apache.
the class OpenCensusTxTracingConfigurationTest method testTxTraceIncludesCommunicationTracesInCaseOfCommunicationScopeInTxIncludedScopes.
/**
* Ensure that TX trace does include COMMUNICATION sub-traces in case of COMMUNICATION scope within the set
* of included scopes of the corresponding TX tracing configuration.
*
* @throws Exception If Failed.
*/
@Test
public void testTxTraceIncludesCommunicationTracesInCaseOfCommunicationScopeInTxIncludedScopes() throws Exception {
IgniteEx client = startGrid("client");
client.tracingConfiguration().set(new TracingConfigurationCoordinates.Builder(TX).build(), new TracingConfigurationParameters.Builder().withSamplingRate(SAMPLING_RATE_ALWAYS).withIncludedScopes(Collections.singleton(Scope.COMMUNICATION)).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());
assertFalse(gotSpans.isEmpty());
}
use of org.apache.ignite.spi.tracing.Scope in project ignite by apache.
the class OpenCensusTxTracingConfigurationTest method testThatLabelSpecificConfigurationIsUsedWheneverPossible.
/**
* Ensure that label specific configuration is used instead of scope specific if it's possible.
*
* @throws Exception If Failed.
*/
@Test
public void testThatLabelSpecificConfigurationIsUsedWheneverPossible() throws Exception {
IgniteEx client = startGrid("client");
final String txLbToBeTraced = "label1";
final String txLbNotToBeTraced = "label2";
client.tracingConfiguration().set(new TracingConfigurationCoordinates.Builder(TX).withLabel(txLbToBeTraced).build(), new TracingConfigurationParameters.Builder().withSamplingRate(SAMPLING_RATE_ALWAYS).build());
client.transactions().withLabel(txLbToBeTraced).txStart(PESSIMISTIC, SERIALIZABLE).commit();
handler().flush();
java.util.List<SpanData> gotSpans = handler().allSpans().filter(span -> SpanType.TX.spanName().equals(span.getName())).collect(Collectors.toList());
assertEquals(1, gotSpans.size());
// Not to be traced, cause there's neither tracing configuration with given label
// nor scope specific tx configuration. In that case default tx tracing configuration will be used that
// actually disables tracing.
client.transactions().withLabel(txLbNotToBeTraced).txStart(PESSIMISTIC, SERIALIZABLE).commit();
handler().flush();
gotSpans = handler().allSpans().filter(span -> SpanType.TX.spanName().equals(span.getName())).collect(Collectors.toList());
// Still only one, previously detected, span is expected.
assertEquals(1, gotSpans.size());
}
use of org.apache.ignite.spi.tracing.Scope in project ignite by apache.
the class OpenCensusTxTracingConfigurationTest method testThatDefaultConfigurationIsUsedIfScopeSpecificNotFoundAndThatByDefaultTxTracingIsDisabled.
/**
* Ensure that default scope specific configuration is used if there's no neither label specif not custom scope specific ones.
* Also ensure that by default TX tracing is disabled.
*
* @throws Exception If Failed.
*/
@Test
public void testThatDefaultConfigurationIsUsedIfScopeSpecificNotFoundAndThatByDefaultTxTracingIsDisabled() throws Exception {
IgniteEx client = startGrid("client");
client.transactions().withLabel("label1").txStart(PESSIMISTIC, SERIALIZABLE).commit();
handler().flush();
java.util.List<SpanData> gotSpans = handler().allSpans().filter(span -> SpanType.TX.spanName().equals(span.getName())).collect(Collectors.toList());
assertTrue(gotSpans.isEmpty());
}
Aggregations