Search in sources :

Example 1 with SpanType

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());
}
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) Test(org.junit.Test)

Example 2 with SpanType

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;
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) EXCHANGE(org.apache.ignite.spi.tracing.Scope.EXCHANGE) SpanType(org.apache.ignite.internal.processors.tracing.SpanType) BeforeClass(org.junit.BeforeClass) AttributeValue(io.opencensus.trace.AttributeValue) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) SpanData(io.opencensus.trace.export.SpanData) Samplers(io.opencensus.trace.samplers.Samplers) ArrayList(java.util.ArrayList) Map(java.util.Map) After(org.junit.After) SpanId(io.opencensus.trace.SpanId) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) LinkedList(java.util.LinkedList) Tracing(io.opencensus.trace.Tracing) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) COMMUNICATION(org.apache.ignite.spi.tracing.Scope.COMMUNICATION) Before(org.junit.Before) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Scope(org.apache.ignite.spi.tracing.Scope) OpenCensusTraceExporter(org.apache.ignite.spi.tracing.opencensus.OpenCensusTraceExporter) Collectors(java.util.stream.Collectors) Span(io.opencensus.trace.Span) SpanExporter(io.opencensus.trace.export.SpanExporter) TX(org.apache.ignite.spi.tracing.Scope.TX) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) TracingSpi(org.apache.ignite.spi.tracing.TracingSpi) Functions(io.opencensus.common.Functions) Collections(java.util.Collections) AttributeValue.stringAttributeValue(io.opencensus.trace.AttributeValue.stringAttributeValue) TracingConfigurationManager(org.apache.ignite.spi.tracing.TracingConfigurationManager) AttributeValue(io.opencensus.trace.AttributeValue) AttributeValue.stringAttributeValue(io.opencensus.trace.AttributeValue.stringAttributeValue) SpanData(io.opencensus.trace.export.SpanData) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with SpanType

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);
}
Also used : DeferredSpan(org.apache.ignite.internal.processors.tracing.DeferredSpan) SpanType(org.apache.ignite.internal.processors.tracing.SpanType) Scope(org.apache.ignite.spi.tracing.Scope) SpanImpl(org.apache.ignite.internal.processors.tracing.SpanImpl) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) Span(org.apache.ignite.internal.processors.tracing.Span) NoopSpan(org.apache.ignite.internal.processors.tracing.NoopSpan) SpiSpecificSpan(org.apache.ignite.spi.tracing.SpiSpecificSpan) DeferredSpan(org.apache.ignite.internal.processors.tracing.DeferredSpan) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HashSet(java.util.HashSet)

Aggregations

SpanType (org.apache.ignite.internal.processors.tracing.SpanType)3 Scope (org.apache.ignite.spi.tracing.Scope)3 TracingConfigurationCoordinates (org.apache.ignite.spi.tracing.TracingConfigurationCoordinates)3 SpanId (io.opencensus.trace.SpanId)2 SpanData (io.opencensus.trace.export.SpanData)2 Collections (java.util.Collections)2 Collectors (java.util.stream.Collectors)2 TX (org.apache.ignite.spi.tracing.Scope.TX)2 TracingConfigurationParameters (org.apache.ignite.spi.tracing.TracingConfigurationParameters)2 TracingSpi (org.apache.ignite.spi.tracing.TracingSpi)2 Functions (io.opencensus.common.Functions)1 AttributeValue (io.opencensus.trace.AttributeValue)1 AttributeValue.stringAttributeValue (io.opencensus.trace.AttributeValue.stringAttributeValue)1 Span (io.opencensus.trace.Span)1 Tracing (io.opencensus.trace.Tracing)1 SpanExporter (io.opencensus.trace.export.SpanExporter)1 Samplers (io.opencensus.trace.samplers.Samplers)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1