fix(logger): Improve error handling to return errors when creating Kafka topics #640
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.
Description
It appears that calling
CreateTopics
here inNewKafkaSink
sometimes doesn't return errors within theerr
return value, but instead in each of the individualtopicResults
(this is a slice) elements returned.This happens in certain scenarios, e.g. when there are authorisation problems creating new topics, which causes errors to be returned within each element of the
topicResults
slice instead (leavingerr
asnil
instead):This is problematic because it means that even though there were problems creating the topic, a
nil
error gets returned, with anil
sink value.Tracing this back to where
NewKafkaSink
gets called ingetLogSink
, https://github.com/caraml-dev/merlin/blob/main/api/cmd/inference-logger/main.go#L362, and to wheregetLogSink
gets called, https://github.com/caraml-dev/merlin/blob/main/api/cmd/inference-logger/main.go#L130, it's easy to see that the error isn't properly caught (since the error returned isnil
) at any part of the call stack.To make things worse, because
logSink
isnil
, it continues getting passed around the entire logger code as if it were non-nil, creating huge problems downstream, like null pointer exceptions (and crashes) becauselogSink
is not at all expected to benil
.This PR simply refactors the error handling of the Kafka sink initialisation step, so that any errors are properly returned and subsequently caught by the upstream callers.
Modifications
api/pkg/inference-logger/logger/kafka_sink.go
- Improve error handlingTests
Checklist
Release Notes