-
Notifications
You must be signed in to change notification settings - Fork 3.3k
refactor(error-logging): Improve kafka error logging #15204
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
Open
abedatahub
wants to merge
2
commits into
master
Choose a base branch
from
abe--improve-kafka-error-log
base: master
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.
+300
−116
Open
Changes from 1 commit
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
This file contains hidden or 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
207 changes: 180 additions & 27 deletions
207
metadata-service/services/src/main/java/com/linkedin/metadata/entity/MCLEmitResult.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,37 +1,190 @@ | ||
| package com.linkedin.metadata.entity; | ||
|
|
||
| import com.linkedin.mxe.MetadataChangeLog; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.Future; | ||
| import lombok.Builder; | ||
| import lombok.Value; | ||
|
|
||
| @Builder(toBuilder = true) | ||
| @Value | ||
| public class MCLEmitResult { | ||
| MetadataChangeLog metadataChangeLog; | ||
|
|
||
| // The result when written to MCL Topic | ||
| Future<?> mclFuture; | ||
|
|
||
| // Whether the mcl was successfully written to the destination topic | ||
| boolean isProduced() { | ||
| if (mclFuture != null) { | ||
| try { | ||
| mclFuture.get(); | ||
| } catch (InterruptedException | ExecutionException e) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } else { | ||
| return false; | ||
| import javax.annotation.Nonnull; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
|
|
||
| /** | ||
| * Result of attempting to emit a Metadata Change Log (MCL) to Kafka. | ||
| * | ||
| * <p>This class uses a state pattern to represent three distinct outcomes: | ||
| * | ||
| * <ol> | ||
| * <li><b>Not Emitted</b>: MCL was intentionally not sent (filtered, CDC mode, etc.) | ||
| * <li><b>Emitted & Pending</b>: MCL was sent to Kafka, async production in progress | ||
| * <li><b>Emitted & Resolved</b>: MCL production completed (successfully or with failure) | ||
| * </ol> | ||
| * | ||
| * <p>Use factory methods to construct instances in valid states: | ||
| * | ||
| * <ul> | ||
| * <li>{@link #notEmitted(MetadataChangeLog, boolean)} - MCL was filtered/skipped | ||
| * <li>{@link #emitted(MetadataChangeLog, Future, boolean)} - MCL sent to Kafka | ||
| * </ul> | ||
| */ | ||
| @Getter | ||
| @ToString | ||
| @EqualsAndHashCode | ||
| public final class MCLEmitResult { | ||
|
Collaborator
Author
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. I was trying to achieve a few different results with this refactoring:
|
||
|
|
||
| @Nonnull private final MetadataChangeLog metadataChangeLog; | ||
|
|
||
| private final Future<?> mclFuture; | ||
|
|
||
| /** Whether the MCL was preprocessed (e.g., synchronous index update triggered). */ | ||
| private final boolean processedMCL; | ||
|
|
||
| /** Whether this MCL was emitted to Kafka (regardless of production outcome). */ | ||
| private final boolean emitted; | ||
|
|
||
| private MCLEmitResult( | ||
| @Nonnull MetadataChangeLog metadataChangeLog, | ||
| Future<?> mclFuture, | ||
| boolean processedMCL, | ||
| boolean emitted) { | ||
| this.metadataChangeLog = metadataChangeLog; | ||
| this.mclFuture = mclFuture; | ||
| this.processedMCL = processedMCL; | ||
| this.emitted = emitted; | ||
|
|
||
| // Invariant: emitted=true implies mclFuture != null | ||
| if (emitted && mclFuture == null) { | ||
| throw new IllegalArgumentException( | ||
| "Invalid state: emitted=true but mclFuture is null. " | ||
| + "Use notEmitted() factory method for non-emitted MCLs."); | ||
| } | ||
|
|
||
| // Invariant: emitted=false implies mclFuture == null | ||
| if (!emitted && mclFuture != null) { | ||
| throw new IllegalArgumentException( | ||
| "Invalid state: emitted=false but mclFuture is not null. " | ||
| + "Use emitted() factory method for emitted MCLs."); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates a result for an MCL that was intentionally not emitted to Kafka. | ||
| * | ||
| * @param metadataChangeLog the MCL that was not emitted | ||
| * @param processedMCL whether the MCL was preprocessed (e.g., sync index update) | ||
| * @return result indicating the MCL was not emitted | ||
| */ | ||
| @Nonnull | ||
| public static MCLEmitResult notEmitted( | ||
| @Nonnull MetadataChangeLog metadataChangeLog, boolean processedMCL) { | ||
| return new MCLEmitResult(metadataChangeLog, null, processedMCL, false); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a result for an MCL that was emitted to Kafka. | ||
| * | ||
| * @param metadataChangeLog the MCL that was emitted | ||
| * @param mclFuture the future representing the async Kafka send operation | ||
| * @param processedMCL whether the MCL was preprocessed (e.g., sync index update) | ||
| * @return result indicating the MCL was emitted | ||
| * @throws IllegalArgumentException if mclFuture is null | ||
| */ | ||
| @Nonnull | ||
| public static MCLEmitResult emitted( | ||
| @Nonnull MetadataChangeLog metadataChangeLog, | ||
| @Nonnull Future<?> mclFuture, | ||
| boolean processedMCL) { | ||
| return new MCLEmitResult(metadataChangeLog, mclFuture, processedMCL, true); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the production result, providing detailed information about success or failure. | ||
| * | ||
| * <p>For non-emitted MCLs, returns {@link ProductionResult#notEmitted()}. For emitted MCLs, | ||
| * blocks until the Kafka send completes and returns the result. | ||
| * | ||
| * @return the production result with success/failure details | ||
| */ | ||
| @Nonnull | ||
| public ProductionResult getProductionResult() { | ||
| if (!emitted) { | ||
| return ProductionResult.notEmitted(); | ||
| } | ||
|
|
||
| try { | ||
| mclFuture.get(); | ||
| return ProductionResult.success(); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| return ProductionResult.failure(e); | ||
| } catch (ExecutionException e) { | ||
| // Unwrap the cause - ExecutionException is just boilerplate wrapper | ||
| Throwable cause = e.getCause(); | ||
| return ProductionResult.failure(cause != null ? cause : e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Attempts to determine if the MCL was successfully produced to Kafka. | ||
| * | ||
| * <p>This method blocks until the Kafka send operation completes or fails. For non-emitted MCLs, | ||
| * this always returns {@code false}. | ||
| * | ||
| * @return {@code true} if the MCL was successfully written to Kafka, {@code false} otherwise | ||
| */ | ||
| public boolean isProduced() { | ||
| return getProductionResult().isSuccess(); | ||
| } | ||
| ; | ||
|
|
||
| // Whether this was preprocessed before being emitted | ||
| boolean processedMCL; | ||
| /** Represents the outcome of attempting to produce an MCL to Kafka. */ | ||
| @Getter | ||
| @ToString | ||
| @EqualsAndHashCode | ||
| public static final class ProductionResult { | ||
| private final ProductionStatus status; | ||
| private final Throwable error; | ||
|
|
||
| private ProductionResult(ProductionStatus status, Throwable error) { | ||
| this.status = status; | ||
| this.error = error; | ||
| } | ||
|
|
||
| @Nonnull | ||
| public static ProductionResult notEmitted() { | ||
| return new ProductionResult(ProductionStatus.NOT_EMITTED, null); | ||
| } | ||
|
|
||
| @Nonnull | ||
| public static ProductionResult success() { | ||
| return new ProductionResult(ProductionStatus.SUCCESS, null); | ||
| } | ||
|
|
||
| // Set to true if the message was emitted, false if this was dropped due to some config. | ||
| boolean emitted; | ||
| @Nonnull | ||
| public static ProductionResult failure(@Nonnull Throwable error) { | ||
| return new ProductionResult(ProductionStatus.FAILURE, error); | ||
| } | ||
|
|
||
| public boolean isSuccess() { | ||
| return status == ProductionStatus.SUCCESS; | ||
| } | ||
|
|
||
| public boolean isFailure() { | ||
| return status == ProductionStatus.FAILURE; | ||
| } | ||
|
|
||
| public boolean wasNotEmitted() { | ||
| return status == ProductionStatus.NOT_EMITTED; | ||
| } | ||
|
|
||
| @Nonnull | ||
| public Optional<Throwable> getError() { | ||
| return Optional.ofNullable(error); | ||
| } | ||
| } | ||
|
|
||
| public enum ProductionStatus { | ||
| NOT_EMITTED, | ||
| SUCCESS, | ||
| FAILURE | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
@chakru-r The original exception seems to have been thrown from line 1384
The error message:
https://vpc-euc1-logs-prod-shared-es-01-be2dv7o6zdiraca5kzvm2znmb4.eu-central-1.es.amazonaws.com/_dashboards/app/data-explorer/discover#?_a=(discover:(columns:!(message,level),isDirty:!t,sort:!()),metadata:(indexPattern:'0f598ad0-b0f4-11ef-b003-2575690fe45c',view:discover))&_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:'2025-10-31T20:33:20.081Z',to:'2025-11-04T21:33:36.626Z'))&_q=(filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'0f598ad0-b0f4-11ef-b003-2575690fe45c',key:kubernetes.namespace_name,negate:!f,params:(query:bf94a93599-superbet),type:phrase),query:(match_phrase:(kubernetes.namespace_name:bf94a93599-superbet))),('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'0f598ad0-b0f4-11ef-b003-2575690fe45c',key:level,negate:!f,params:(query:ERROR),type:phrase),query:(match_phrase:(level:ERROR)))),query:(language:kuery,query:'%22Failed%20to%20produce%20MCLs%22'))
Not sure why we didn't see the preceding log statement however. What am I missing?
(And yes, I still haven't added a statement to log the kafka produce failure yet)
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.
Its about 0.5 seconds earlier -- there are quite a bit of logs in between, so filtered for ERROR