-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KSQL-12194, KSQL-12195 | Classify missing schema exception and record…
… too large exceptions as user errors.
- Loading branch information
Showing
7 changed files
with
217 additions
and
3 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
ksqldb-engine/src/main/java/io/confluent/ksql/query/MissingSchemaClassifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2022 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"; you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.query; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Objects; | ||
|
||
import io.confluent.ksql.query.QueryError.Type; | ||
import io.confluent.ksql.schema.registry.SchemaRegistryUtil; | ||
|
||
/** | ||
* {@code MissingSchemaClassifier} classifies missing SR schema exceptions as user error | ||
*/ | ||
public class MissingSchemaClassifier implements QueryErrorClassifier { | ||
private static final Logger LOG = LoggerFactory.getLogger(MissingSchemaClassifier.class); | ||
|
||
private final String queryId; | ||
|
||
public MissingSchemaClassifier(final String queryId) { | ||
this.queryId = Objects.requireNonNull(queryId, "queryId"); | ||
} | ||
|
||
@Override | ||
public Type classify(final Throwable e) { | ||
final Type type = SchemaRegistryUtil.isSchemaNotFoundErrorCode(e) ? Type.USER : Type.UNKNOWN; | ||
|
||
if (type == Type.USER) { | ||
LOG.info( | ||
"Classified error as USER error based on missing SR schema. Query ID: {} Exception: {}", | ||
queryId, | ||
e.getMessage()); | ||
} | ||
|
||
return type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
ksqldb-engine/src/main/java/io/confluent/ksql/query/RecordTooLargeClassifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2022 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"; you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.query; | ||
|
||
import io.confluent.ksql.query.QueryError.Type; | ||
import java.util.Objects; | ||
import org.apache.commons.lang3.exception.ExceptionUtils; | ||
import org.apache.kafka.common.errors.RecordTooLargeException; | ||
import org.apache.kafka.streams.errors.StreamsException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* {@code RecordTooLargeClassifier} classifies records too large to be produced as user exception. | ||
*/ | ||
public class RecordTooLargeClassifier implements QueryErrorClassifier { | ||
private static final Logger LOG = LoggerFactory.getLogger(RecordTooLargeClassifier.class); | ||
|
||
private final String queryId; | ||
|
||
public RecordTooLargeClassifier(final String queryId) { | ||
this.queryId = Objects.requireNonNull(queryId, "queryId"); | ||
} | ||
|
||
@Override | ||
public Type classify(final Throwable e) { | ||
final Type type = e instanceof StreamsException | ||
&& ExceptionUtils.getRootCause(e) instanceof RecordTooLargeException | ||
? Type.USER | ||
: Type.UNKNOWN; | ||
|
||
if (type == Type.USER) { | ||
LOG.info( | ||
"Classified RecordTooLargeException error as USER error. Query ID: {} Exception: {}. " | ||
+ "Consider setting ksql.streams.max.request.size property to a higher value.", | ||
queryId, | ||
e.getMessage() | ||
); | ||
} | ||
|
||
return type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
ksqldb-engine/src/test/java/io/confluent/ksql/query/MissingSchemaClassifierTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2022 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"; you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.query; | ||
|
||
import org.junit.Test; | ||
|
||
import io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class MissingSchemaClassifierTest { | ||
@Test | ||
public void shouldClassifyMissingSchemaAsUserError() { | ||
// Given: | ||
final Exception e = new RestClientException("foo", 404, 40403); | ||
|
||
// When: | ||
final QueryError.Type type = new MissingSchemaClassifier("").classify(e); | ||
|
||
// Then: | ||
assertThat(type, is(QueryError.Type.USER)); | ||
} | ||
|
||
@Test | ||
public void shouldClassifyOtherExceptionAsUnknownException() { | ||
// Given: | ||
final Exception e = new Exception("foo"); | ||
|
||
// When: | ||
final QueryError.Type type = new MissingSchemaClassifier("").classify(e); | ||
|
||
// Then: | ||
assertThat(type, is(QueryError.Type.UNKNOWN)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
ksqldb-engine/src/test/java/io/confluent/ksql/query/RecordTooLargeClassifierTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2022 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"; you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.query; | ||
|
||
import org.apache.kafka.common.KafkaException; | ||
import org.apache.kafka.common.errors.RecordTooLargeException; | ||
import org.apache.kafka.streams.errors.StreamsException; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class RecordTooLargeClassifierTest { | ||
|
||
@Test | ||
public void shouldClassifyRecordTooLargeExceptionAsUserError() { | ||
// Given: | ||
final Exception e = new StreamsException( | ||
"Error encountered trying to send record to topic foo", | ||
new KafkaException( | ||
"Cannot execute transactional method because we are in an error state", | ||
new RecordTooLargeException( | ||
"The message is 1084728 bytes when serialized which is larger than 1048576, which" | ||
+ " is the value of the max.request.size configuration.") | ||
) | ||
); | ||
|
||
// When: | ||
final QueryError.Type type = new RecordTooLargeClassifier("").classify(e); | ||
|
||
// Then: | ||
assertThat(type, is(QueryError.Type.USER)); | ||
} | ||
|
||
} |