Search in sources :

Example 16 with SpanId

use of io.opencensus.trace.SpanId in project ignite by apache.

the class OpenCensusSqlNativeTracingTest method checkDmlQuerySpans.

/**
 * Executes DML query and checks corresponding span tree.
 *
 * @param qry SQL query to execute.
 * @param fetchRequired Whether query need to fetch data before cache update.
 */
private void checkDmlQuerySpans(String qry, boolean fetchRequired, int expCacheUpdates) throws Exception {
    SpanId rootSpan = executeAndCheckRootSpan(qry, TEST_SCHEMA, false, false, false);
    checkChildSpan(SQL_QRY_PARSE, rootSpan);
    SpanId dmlExecSpan = checkChildSpan(SQL_DML_QRY_EXECUTE, rootSpan);
    if (fetchRequired) {
        checkChildSpan(SQL_ITER_OPEN, dmlExecSpan);
        int fetchedRows = findChildSpans(SQL_PAGE_FETCH, null).stream().mapToInt(span -> parseInt(getAttribute(span, SQL_PAGE_ROWS))).sum();
        assertEquals(expCacheUpdates, fetchedRows);
    }
    int cacheUpdates = findChildSpans(SQL_CACHE_UPDATE, dmlExecSpan).stream().mapToInt(span -> parseInt(getAttribute(span, SQL_CACHE_UPDATES))).sum();
    assertEquals(expCacheUpdates, cacheUpdates);
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) SQL_DML_QRY_RESP(org.apache.ignite.internal.processors.tracing.SpanType.SQL_DML_QRY_RESP) SQL_NEXT_PAGE_REQ(org.apache.ignite.internal.processors.tracing.SpanType.SQL_NEXT_PAGE_REQ) TestRecordingCommunicationSpi.spi(org.apache.ignite.internal.TestRecordingCommunicationSpi.spi) Arrays(java.util.Arrays) SQL_IDX_RANGE_ROWS(org.apache.ignite.internal.processors.tracing.SpanTags.SQL_IDX_RANGE_ROWS) SpanType(org.apache.ignite.internal.processors.tracing.SpanType) SQL_PAGE_ROWS(org.apache.ignite.internal.processors.tracing.SpanTags.SQL_PAGE_ROWS) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) SQL_QRY_ID(org.apache.ignite.internal.processors.tracing.SpanTags.SQL_QRY_ID) SQL_CMD_QRY_EXECUTE(org.apache.ignite.internal.processors.tracing.SpanType.SQL_CMD_QRY_EXECUTE) IgniteEx(org.apache.ignite.internal.IgniteEx) SQL_FAIL_RESP(org.apache.ignite.internal.processors.tracing.SpanType.SQL_FAIL_RESP) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) NoopSpan(org.apache.ignite.internal.processors.tracing.NoopSpan) Matcher(java.util.regex.Matcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SQL_PAGE_WAIT(org.apache.ignite.internal.processors.tracing.SpanType.SQL_PAGE_WAIT) SpanId(io.opencensus.trace.SpanId) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) NODE(org.apache.ignite.internal.processors.tracing.SpanTags.NODE) Tracing(io.opencensus.trace.Tracing) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) QuerySqlField(org.apache.ignite.cache.query.annotations.QuerySqlField) ImmutableMap(com.google.common.collect.ImmutableMap) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Set(java.util.Set) SQL_IDX_RANGE_RESP(org.apache.ignite.internal.processors.tracing.SpanType.SQL_IDX_RANGE_RESP) SQL_ITER_CLOSE(org.apache.ignite.internal.processors.tracing.SpanType.SQL_ITER_CLOSE) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) DFLT_SCHEMA(org.apache.ignite.internal.processors.query.QueryUtils.DFLT_SCHEMA) SQL_CURSOR_CANCEL(org.apache.ignite.internal.processors.tracing.SpanType.SQL_CURSOR_CANCEL) SAMPLING_RATE_ALWAYS(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS) MTC(org.apache.ignite.internal.processors.tracing.MTC) TracingSpi(org.apache.ignite.spi.tracing.TracingSpi) SQL_IDX_RANGE_REQ(org.apache.ignite.internal.processors.tracing.SpanType.SQL_IDX_RANGE_REQ) SQL_CURSOR_OPEN(org.apache.ignite.internal.processors.tracing.SpanType.SQL_CURSOR_OPEN) SQL(org.apache.ignite.spi.tracing.Scope.SQL) Pattern(java.util.regex.Pattern) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridQueryNextPageRequest(org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageRequest) SQL_QRY_EXEC_REQ(org.apache.ignite.internal.processors.tracing.SpanType.SQL_QRY_EXEC_REQ) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) SQL_CACHE_UPDATE(org.apache.ignite.internal.processors.tracing.SpanType.SQL_CACHE_UPDATE) SQL_SCHEMA(org.apache.ignite.internal.processors.tracing.SpanTags.SQL_SCHEMA) U(org.apache.ignite.internal.util.typedef.internal.U) SQL_PARTITIONS_RESERVE(org.apache.ignite.internal.processors.tracing.SpanType.SQL_PARTITIONS_RESERVE) SQL_QRY_CANCEL_REQ(org.apache.ignite.internal.processors.tracing.SpanType.SQL_QRY_CANCEL_REQ) SQL_DML_QRY_EXECUTE(org.apache.ignite.internal.processors.tracing.SpanType.SQL_DML_QRY_EXECUTE) OpenCensusTracingSpi(org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi) SQL_PAGE_RESP(org.apache.ignite.internal.processors.tracing.SpanType.SQL_PAGE_RESP) SQL_QRY_TEXT(org.apache.ignite.internal.processors.tracing.SpanTags.SQL_QRY_TEXT) SQL_CACHE_UPDATES(org.apache.ignite.internal.processors.tracing.SpanTags.SQL_CACHE_UPDATES) SpanTags.tag(org.apache.ignite.internal.processors.tracing.SpanTags.tag) SQL_ITER_OPEN(org.apache.ignite.internal.processors.tracing.SpanType.SQL_ITER_OPEN) Iterator(java.util.Iterator) Pattern.compile(java.util.regex.Pattern.compile) SQL_CURSOR_CLOSE(org.apache.ignite.internal.processors.tracing.SpanType.SQL_CURSOR_CLOSE) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) Test(org.junit.Test) SQL_PAGE_FETCH(org.apache.ignite.internal.processors.tracing.SpanType.SQL_PAGE_FETCH) Ignite(org.apache.ignite.Ignite) SQL_PARSER_CACHE_HIT(org.apache.ignite.internal.processors.tracing.SpanTags.SQL_PARSER_CACHE_HIT) SQL_DML_QRY_EXEC_REQ(org.apache.ignite.internal.processors.tracing.SpanType.SQL_DML_QRY_EXEC_REQ) NAME(org.apache.ignite.internal.processors.tracing.SpanTags.NAME) Integer.parseInt(java.lang.Integer.parseInt) SQL_QRY(org.apache.ignite.internal.processors.tracing.SpanType.SQL_QRY) SQL_PAGE_PREPARE(org.apache.ignite.internal.processors.tracing.SpanType.SQL_PAGE_PREPARE) CONSISTENT_ID(org.apache.ignite.internal.processors.tracing.SpanTags.CONSISTENT_ID) NODE_ID(org.apache.ignite.internal.processors.tracing.SpanTags.NODE_ID) Ignition(org.apache.ignite.Ignition) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) SQL_QRY_PARSE(org.apache.ignite.internal.processors.tracing.SpanType.SQL_QRY_PARSE) SQL_QRY_EXECUTE(org.apache.ignite.internal.processors.tracing.SpanType.SQL_QRY_EXECUTE) CacheMode(org.apache.ignite.cache.CacheMode) SpanId(io.opencensus.trace.SpanId)

Example 17 with SpanId

use of io.opencensus.trace.SpanId in project ignite by apache.

the class OpenCensusSqlNativeTracingTest method testNextPageRequestFailure.

/**
 * Tests tracing of the SQL query next page request failure.
 *
 * @throws Exception If failed.
 */
@Test
@SuppressWarnings("Convert2MethodRef")
public void testNextPageRequestFailure() throws Exception {
    String prsnTable = createTableAndPopulate(Person.class, PARTITIONED, 1);
    IgniteEx qryInitiator = reducer();
    spi(qryInitiator).blockMessages((node, msg) -> msg instanceof GridQueryNextPageRequest);
    IgniteInternalFuture<?> iterFut = runAsync(() -> executeQuery("SELECT * FROM " + prsnTable, TEST_SCHEMA, false, false, true));
    spi(qryInitiator).waitForBlocked(mapNodesCount());
    qryInitiator.context().query().runningQueries(-1).iterator().next().cancel();
    spi(qryInitiator).stopBlock();
    GridTestUtils.assertThrowsWithCause(() -> iterFut.get(), IgniteCheckedException.class);
    handler().flush();
    checkDroppedSpans();
    SpanId rootSpan = checkChildSpan(SQL_QRY, null);
    SpanId cursorCancelSpan = checkChildSpan(SQL_CURSOR_CANCEL, rootSpan);
    SpanId cursorCloseSpan = checkChildSpan(SQL_CURSOR_CLOSE, cursorCancelSpan);
    SpanId iterCloseSpan = checkChildSpan(SQL_ITER_CLOSE, cursorCloseSpan);
    checkSpan(SQL_QRY_CANCEL_REQ, iterCloseSpan, mapNodesCount(), null);
    List<SpanId> pageFetchSpans = findChildSpans(SQL_PAGE_FETCH, rootSpan);
    for (SpanId pageFetchSpan : pageFetchSpans) {
        List<SpanId> nextPageReqSpans = findChildSpans(SQL_NEXT_PAGE_REQ, pageFetchSpan);
        if (!nextPageReqSpans.isEmpty()) {
            assertEquals(1, nextPageReqSpans.size());
            checkChildSpan(SQL_FAIL_RESP, nextPageReqSpans.get(0));
        }
    }
}
Also used : GridQueryNextPageRequest(org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageRequest) IgniteEx(org.apache.ignite.internal.IgniteEx) SpanId(io.opencensus.trace.SpanId) Test(org.junit.Test)

Example 18 with SpanId

use of io.opencensus.trace.SpanId in project ignite by apache.

the class OpenCensusSqlNativeTracingTest method testSelectWithParallelism.

/**
 * Tests tracing of SELECT query with parallelism.
 *
 * @throws Exception If failed.
 */
@Test
public void testSelectWithParallelism() throws Exception {
    int qryParallelism = 2;
    String prsnTable = createTableAndPopulate(Person.class, PARTITIONED, qryParallelism);
    SpanId rootSpan = executeAndCheckRootSpan("SELECT * FROM " + prsnTable, TEST_SCHEMA, false, false, true);
    SpanId iterOpenSpan = checkChildSpan(SQL_ITER_OPEN, rootSpan);
    List<SpanId> qryExecSpans = findChildSpans(SQL_QRY_EXEC_REQ, iterOpenSpan);
    assertEquals(GRID_CNT * qryParallelism, qryExecSpans.size());
}
Also used : SpanId(io.opencensus.trace.SpanId) Test(org.junit.Test)

Example 19 with SpanId

use of io.opencensus.trace.SpanId in project ignite by apache.

the class OpenCensusTxTracingConfigurationTest method testTxTraceDoesNotIncludeCommunicationTracesInCaseOfEmptyIncludedScopes.

/**
 * Ensure that TX traces doesn't include COMMUNICATION sub-traces in case of empty set of included scopes.
 *
 * @throws Exception If Failed.
 */
@Test
public void testTxTraceDoesNotIncludeCommunicationTracesInCaseOfEmptyIncludedScopes() throws Exception {
    IgniteEx client = startGrid("client");
    client.tracingConfiguration().set(new TracingConfigurationCoordinates.Builder(TX).build(), new TracingConfigurationParameters.Builder().withSamplingRate(SAMPLING_RATE_ALWAYS).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());
    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) 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 20 with SpanId

use of io.opencensus.trace.SpanId in project ignite by apache.

the class OpenCensusTxTracingTest method testRollbackTransaction.

/**
 * <ol>
 *     <li>Run some transaction with some label.</li>
 *     <li>Call two puts inside the transaction.</li>
 *     <li>Rollback given transaction.</li>
 * </ol>
 *
 * Check that got trace is equal to:
 *  transaction
 *      transactions.near.enlist.write
 *      transactions.rollback
 *
 *   <p>
 *   Also check that root transaction span contains following tags:
 *   <ol>
 *       <li>node.id</li>
 *       <li>node.consistent.id</li>
 *       <li>node.name</li>
 *       <li>concurrency</li>
 *       <li>isolation</li>
 *       <li>timeout</li>
 *       <li>label</li>
 *   </ol>
 */
@Test
public void testRollbackTransaction() throws Exception {
    IgniteEx client = startGrid("client");
    Transaction tx = client.transactions().withLabel("label1").txStart(OPTIMISTIC, REPEATABLE_READ);
    client.cache(DEFAULT_CACHE_NAME).put(1, 1);
    tx.rollback();
    handler().flush();
    List<SpanId> txSpanIds = checkSpan(TX, null, 1, ImmutableMap.<String, String>builder().put("node.id", client.localNode().id().toString()).put("node.consistent.id", client.localNode().consistentId().toString()).put("node.name", client.name()).put("concurrency", OPTIMISTIC.name()).put("isolation", REPEATABLE_READ.name()).put("timeout", String.valueOf(0)).put("label", "label1").build());
    checkSpan(TX_NEAR_ENLIST_WRITE, txSpanIds.get(0), 1, null);
    checkSpan(TX_ROLLBACK, txSpanIds.get(0), 1, null);
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) SpanId(io.opencensus.trace.SpanId) Test(org.junit.Test)

Aggregations

SpanId (io.opencensus.trace.SpanId)31 Test (org.junit.Test)21 IgniteEx (org.apache.ignite.internal.IgniteEx)14 Transaction (org.apache.ignite.transactions.Transaction)10 TraceId (io.opencensus.trace.TraceId)6 TracingConfigurationParameters (org.apache.ignite.spi.tracing.TracingConfigurationParameters)6 TraceOptions (io.opencensus.trace.TraceOptions)5 TracingConfigurationCoordinates (org.apache.ignite.spi.tracing.TracingConfigurationCoordinates)5 SAMPLING_RATE_ALWAYS (org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS)5 SpanData (io.opencensus.trace.export.SpanData)4 SpanContextParseException (io.opencensus.trace.propagation.SpanContextParseException)4 Arrays (java.util.Arrays)4 List (java.util.List)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 SpanType (org.apache.ignite.internal.processors.tracing.SpanType)4 TracingSpi (org.apache.ignite.spi.tracing.TracingSpi)4 OpenCensusTracingSpi (org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi)4 Timestamp (io.opencensus.common.Timestamp)3 SpanContext (io.opencensus.trace.SpanContext)3