Search in sources :

Example 1 with Scope

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;
}
Also used : DeferredSpan(org.apache.ignite.internal.processors.tracing.DeferredSpan) Scope(org.apache.ignite.spi.tracing.Scope)

Example 2 with Scope

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);
    }
}
Also used : GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) Scope(org.apache.ignite.spi.tracing.Scope) Collectors(java.util.stream.Collectors) GridKernalContext(org.apache.ignite.internal.GridKernalContext) Nullable(org.jetbrains.annotations.Nullable) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) TracingConfigurationManager(org.apache.ignite.spi.tracing.TracingConfigurationManager) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) HashMap(java.util.HashMap) IgniteException(org.apache.ignite.IgniteException) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Scope

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());
}
Also used : Arrays(java.util.Arrays) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) SpanType(org.apache.ignite.internal.processors.tracing.SpanType) Transaction(org.apache.ignite.transactions.Transaction) Set(java.util.Set) IgniteEx(org.apache.ignite.internal.IgniteEx) Scope(org.apache.ignite.spi.tracing.Scope) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SpanData(io.opencensus.trace.export.SpanData) OpenCensusTracingSpi(org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi) TX(org.apache.ignite.spi.tracing.Scope.TX) SAMPLING_RATE_ALWAYS(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) TracingSpi(org.apache.ignite.spi.tracing.TracingSpi) SpanId(io.opencensus.trace.SpanId) SAMPLING_RATE_NEVER(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_NEVER) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) Collections(java.util.Collections) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) Transaction(org.apache.ignite.transactions.Transaction) SpanData(io.opencensus.trace.export.SpanData) IgniteEx(org.apache.ignite.internal.IgniteEx) SpanId(io.opencensus.trace.SpanId) Test(org.junit.Test)

Example 4 with Scope

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());
}
Also used : Arrays(java.util.Arrays) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) SpanType(org.apache.ignite.internal.processors.tracing.SpanType) Transaction(org.apache.ignite.transactions.Transaction) Set(java.util.Set) IgniteEx(org.apache.ignite.internal.IgniteEx) Scope(org.apache.ignite.spi.tracing.Scope) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SpanData(io.opencensus.trace.export.SpanData) OpenCensusTracingSpi(org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi) TX(org.apache.ignite.spi.tracing.Scope.TX) SAMPLING_RATE_ALWAYS(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) TracingSpi(org.apache.ignite.spi.tracing.TracingSpi) SpanId(io.opencensus.trace.SpanId) SAMPLING_RATE_NEVER(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_NEVER) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) Collections(java.util.Collections) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) SpanData(io.opencensus.trace.export.SpanData) IgniteEx(org.apache.ignite.internal.IgniteEx) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) Test(org.junit.Test)

Example 5 with Scope

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());
}
Also used : Arrays(java.util.Arrays) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) SpanType(org.apache.ignite.internal.processors.tracing.SpanType) Transaction(org.apache.ignite.transactions.Transaction) Set(java.util.Set) IgniteEx(org.apache.ignite.internal.IgniteEx) Scope(org.apache.ignite.spi.tracing.Scope) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SpanData(io.opencensus.trace.export.SpanData) OpenCensusTracingSpi(org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi) TX(org.apache.ignite.spi.tracing.Scope.TX) SAMPLING_RATE_ALWAYS(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) TracingSpi(org.apache.ignite.spi.tracing.TracingSpi) SpanId(io.opencensus.trace.SpanId) SAMPLING_RATE_NEVER(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_NEVER) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) Collections(java.util.Collections) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) SpanData(io.opencensus.trace.export.SpanData) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test)

Aggregations

Scope (org.apache.ignite.spi.tracing.Scope)10 TracingConfigurationCoordinates (org.apache.ignite.spi.tracing.TracingConfigurationCoordinates)8 TracingConfigurationParameters (org.apache.ignite.spi.tracing.TracingConfigurationParameters)7 Collections (java.util.Collections)6 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 SpanType (org.apache.ignite.internal.processors.tracing.SpanType)6 SpanId (io.opencensus.trace.SpanId)5 SpanData (io.opencensus.trace.export.SpanData)5 Arrays (java.util.Arrays)5 IgniteEx (org.apache.ignite.internal.IgniteEx)5 TX (org.apache.ignite.spi.tracing.Scope.TX)5 SAMPLING_RATE_ALWAYS (org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS)5 SAMPLING_RATE_NEVER (org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_NEVER)5 TracingSpi (org.apache.ignite.spi.tracing.TracingSpi)5 OpenCensusTracingSpi (org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi)5 Transaction (org.apache.ignite.transactions.Transaction)5 PESSIMISTIC (org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC)5 SERIALIZABLE (org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE)5 Test (org.junit.Test)5