forked from Aiven-Open/karapace
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Aiven-Open#936 from Aiven-Open/nosahama/abort-serv…
…ice-on-corrupt-schema schema-reader: Shutdown service if corrupt entries in `_schemas` topic
- Loading branch information
Showing
11 changed files
with
237 additions
and
42 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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,47 @@ | ||
""" | ||
Copyright (c) 2024 Aiven Ltd | ||
See LICENSE for details | ||
""" | ||
|
||
from karapace.config import Config | ||
from karapace.errors import CorruptKafkaRecordException | ||
from karapace.typing import StrEnum | ||
|
||
import aiokafka.errors as Errors | ||
import enum | ||
import logging | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class KafkaErrorLocation(StrEnum): | ||
SCHEMA_COORDINATOR = "SCHEMA_COORDINATOR" | ||
SCHEMA_READER = "SCHEMA_READER" | ||
|
||
|
||
class KafkaRetriableErrors(enum.Enum): | ||
SCHEMA_COORDINATOR = (Errors.NodeNotReadyError,) | ||
|
||
|
||
class KafkaErrorHandler: | ||
def __init__(self, config: Config) -> None: | ||
self.schema_reader_strict_mode: bool = config["kafka_schema_reader_strict_mode"] | ||
self.retriable_errors_silenced: bool = config["kafka_retriable_errors_silenced"] | ||
|
||
def log(self, location: KafkaErrorLocation, error: BaseException) -> None: | ||
LOG.warning("%s encountered error - %s", location, error) | ||
|
||
def handle_schema_coordinator_error(self, error: BaseException) -> None: | ||
if getattr(error, "retriable", False) or ( | ||
error in KafkaRetriableErrors[KafkaErrorLocation.SCHEMA_COORDINATOR].value | ||
): | ||
self.log(location=KafkaErrorLocation.SCHEMA_COORDINATOR, error=error) | ||
if not self.retriable_errors_silenced: | ||
raise error | ||
|
||
def handle_schema_reader_error(self, error: BaseException) -> None: | ||
if self.schema_reader_strict_mode: | ||
raise CorruptKafkaRecordException from error | ||
|
||
def handle_error(self, location: KafkaErrorLocation, error: BaseException) -> None: | ||
return getattr(self, f"handle_{location.lower()}_error")(error=error) |
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
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
Oops, something went wrong.