-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[filebeat][streaming] - Fixed a scenario where CEL would process invalid/empty messages in case of a websocket error #42036
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -116,6 +116,7 @@ func (s *websocketStream) FollowStream(ctx context.Context) error { | |||||||||||||||||||||||||||||||||||||||
return ctx.Err() | ||||||||||||||||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||||||||||||||||
_, message, err := c.ReadMessage() | ||||||||||||||||||||||||||||||||||||||||
s.metrics.receivedBytesTotal.Add(uint64(len(message))) | ||||||||||||||||||||||||||||||||||||||||
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 move this up? Is a message valid when 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. Shouldn't we still count the received bytes irrespective of whether it's a valid message or not, since this is a metric ? |
||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||
s.metrics.errorsTotal.Inc() | ||||||||||||||||||||||||||||||||||||||||
if isRetryableError(err) { | ||||||||||||||||||||||||||||||||||||||||
|
@@ -137,15 +138,15 @@ func (s *websocketStream) FollowStream(ctx context.Context) error { | |||||||||||||||||||||||||||||||||||||||
s.log.Errorw("failed to read websocket data", "error", err) | ||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
s.metrics.receivedBytesTotal.Add(uint64(len(message))) | ||||||||||||||||||||||||||||||||||||||||
state["response"] = message | ||||||||||||||||||||||||||||||||||||||||
s.log.Debugw("received websocket message", logp.Namespace("websocket"), "msg", string(message)) | ||||||||||||||||||||||||||||||||||||||||
err = s.process(ctx, state, s.cursor, s.now().In(time.UTC)) | ||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||
s.metrics.errorsTotal.Inc() | ||||||||||||||||||||||||||||||||||||||||
s.log.Errorw("failed to process and publish data", "error", err) | ||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||
state["response"] = message | ||||||||||||||||||||||||||||||||||||||||
s.log.Debugw("received websocket message", logp.Namespace("websocket"), "msg", string(message)) | ||||||||||||||||||||||||||||||||||||||||
err = s.process(ctx, state, s.cursor, s.now().In(time.UTC)) | ||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||
s.metrics.errorsTotal.Inc() | ||||||||||||||||||||||||||||||||||||||||
s.log.Errorw("failed to process and publish data", "error", err) | ||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+141
to
+149
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.
Suggested change
but why does the error case not return if 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. @efd6, It does return, the issue is when it is a RetryableError. In this scenario the message is still passed to CEL during the retry attempts. So if the 3rd attempt is successful the 1st 2 invalid messages are still processed by CEL leading to downstream errors in integration pipelines because the event itself might be malformed or not present. Also this is just unnecessary processing that can be avoided. 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. Also I felt that an else block had better readability in this case since we already have a bunch of returns within the "if". |
||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
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.