Search in sources :

Example 6 with QueryError

use of io.confluent.ksql.query.QueryError in project ksql by confluentinc.

the class QueryMetadataTest method shouldEvictBasedOnTime.

@Test
public void shouldEvictBasedOnTime() {
    // Given:
    final QueryMetadataImpl.TimeBoundedQueue queue = new QueryMetadataImpl.TimeBoundedQueue(Duration.ZERO, 1);
    queue.add(new QueryError(System.currentTimeMillis(), "test", Type.SYSTEM));
    // Then:
    assertThat(queue.toImmutableList().size(), is(0));
}
Also used : QueryError(io.confluent.ksql.query.QueryError) Test(org.junit.Test)

Example 7 with QueryError

use of io.confluent.ksql.query.QueryError in project ksql by confluentinc.

the class SharedKafkaStreamsRuntimeImpl method uncaughtHandler.

public StreamsUncaughtExceptionHandler.StreamThreadExceptionResponse uncaughtHandler(final Throwable e) {
    QueryError.Type errorType = QueryError.Type.UNKNOWN;
    try {
        errorType = errorClassifier.classify(e);
        if (e.getCause() != null && errorType == QueryError.Type.UNKNOWN) {
            errorType = errorClassifier.classify(e.getCause());
        }
    } catch (final Exception classificationException) {
        log.error("Error classifying unhandled exception", classificationException);
    } finally {
        // If error classification throws then we consider the error to be an UNKNOWN error.
        // We notify listeners and add the error to the errors queue in the finally block to ensure
        // all listeners and consumers of the error queue (eg the API) can see the error. Similarly,
        // log in finally block to make sure that if there's ever an error in the classification
        // we still get this in our logs.
        final QueryError queryError = new QueryError(System.currentTimeMillis(), Throwables.getStackTraceAsString(e), errorType);
        final BinPackedPersistentQueryMetadataImpl queryInError = parseException(e);
        if (queryInError != null) {
            queryInError.setQueryError(queryError);
            log.error(String.format("Unhandled query exception caught in streams thread %s for query %s. (%s)", Thread.currentThread().getName(), queryInError.getQueryId(), errorType), e);
        } else {
            for (BinPackedPersistentQueryMetadataImpl query : collocatedQueries.values()) {
                query.setQueryError(queryError);
            }
            log.error(String.format("Unhandled runtime exception caught in streams thread %s. (%s)", Thread.currentThread().getName(), errorType), e);
        }
    }
    return StreamsUncaughtExceptionHandler.StreamThreadExceptionResponse.REPLACE_THREAD;
}
Also used : QueryError(io.confluent.ksql.query.QueryError) StreamsException(org.apache.kafka.streams.errors.StreamsException) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with QueryError

use of io.confluent.ksql.query.QueryError in project ksql by confluentinc.

the class SecureIntegrationTest method assertQueryFailsWithUserError.

private void assertQueryFailsWithUserError(final String query, final String errorMsg) {
    final QueryMetadata queryMetadata = KsqlEngineTestUtil.execute(serviceContext, ksqlEngine, query, ksqlConfig, Collections.emptyMap()).get(0);
    queryMetadata.start();
    assertThatEventually("Wait for query to fail", () -> queryMetadata.getQueryErrors().size() > 0, is(true));
    for (final QueryError error : queryMetadata.getQueryErrors()) {
        assertThat(error.getType(), is(Type.USER));
        assertThat(error.getErrorMessage().split("\n")[0], containsString(String.format(errorMsg, queryMetadata.getQueryId())));
    }
}
Also used : QueryMetadata(io.confluent.ksql.util.QueryMetadata) QueryError(io.confluent.ksql.query.QueryError)

Example 9 with QueryError

use of io.confluent.ksql.query.QueryError in project ksql by confluentinc.

the class QueryStateMetricsReportingListenerTest method shouldGracefullyHandleErrorCallbackAfterDeregister.

@Test
public void shouldGracefullyHandleErrorCallbackAfterDeregister() {
    // Given:
    listener.onCreate(serviceContext, metaStore, query);
    listener.onDeregister(query);
    // When/Then(don't throw)
    listener.onError(query, new QueryError(123, "foo", Type.USER));
}
Also used : QueryError(io.confluent.ksql.query.QueryError) Test(org.junit.Test)

Example 10 with QueryError

use of io.confluent.ksql.query.QueryError in project ksql by confluentinc.

the class Console method printQueryError.

private void printQueryError(final QueryDescription query) {
    writer().println();
    final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss,SSS (z)");
    for (final QueryError error : query.getQueryErrors()) {
        final Instant ts = Instant.ofEpochMilli(error.getTimestamp());
        final String errorDate = ts.atZone(ZoneId.systemDefault()).format(dateFormatter);
        writer().println(String.format("%-20s : %s", "Error Date", errorDate));
        writer().println(String.format("%-20s : %s", "Error Details", error.getErrorMessage()));
        writer().println(String.format("%-20s : %s", "Error Type", error.getType()));
    }
}
Also used : Instant(java.time.Instant) QueryError(io.confluent.ksql.query.QueryError) DateTimeFormatter(java.time.format.DateTimeFormatter)

Aggregations

QueryError (io.confluent.ksql.query.QueryError)10 Test (org.junit.Test)4 StreamsException (org.apache.kafka.streams.errors.StreamsException)2 Type (io.confluent.ksql.query.QueryError.Type)1 QueryId (io.confluent.ksql.query.QueryId)1 FieldInfo (io.confluent.ksql.rest.entity.FieldInfo)1 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)1 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)1 QueryDescription (io.confluent.ksql.rest.entity.QueryDescription)1 QueryDescriptionEntity (io.confluent.ksql.rest.entity.QueryDescriptionEntity)1 SchemaInfo (io.confluent.ksql.rest.entity.SchemaInfo)1 StreamsTaskMetadata (io.confluent.ksql.rest.entity.StreamsTaskMetadata)1 QueryMetadata (io.confluent.ksql.util.QueryMetadata)1 Instant (java.time.Instant)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ExecutionException (java.util.concurrent.ExecutionException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1