-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KSQL-12194, KSQL-12195 | Classify MissingSchemaException and RecordTooLargeException as user errors. #10361
Open
pbadani
wants to merge
2
commits into
7.6.x
Choose a base branch
from
pbadani/KSQL-12194-KSQL-12194
base: 7.6.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
KSQL-12194, KSQL-12195 | Classify MissingSchemaException and RecordTooLargeException as user errors. #10361
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
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,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 io.confluent.ksql.query.QueryError.Type; | ||
import io.confluent.ksql.schema.registry.SchemaRegistryUtil; | ||
import java.util.Objects; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* {@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)); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -131,7 +131,7 @@ | |
<wiremock.version>2.24.0</wiremock.version> | ||
<clearspring-analytics.version>2.9.5</clearspring-analytics.version> | ||
<icu.version>67.1</icu.version> | ||
<vertx.version>4.4.6</vertx.version> | ||
<vertx.version>4.4.8</vertx.version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this change required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is a mistake, I will revert it. |
||
<reactive-streams.version>1.0.3</reactive-streams.version> | ||
<skip.docker.build>true</skip.docker.build> | ||
<skip.docker.test>true</skip.docker.test> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious question how was the code
40403
determined?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error codes are from the SR code repo