Skip to content
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

x-pack/filebeat/input/cel: fix handling of cancellation #33968

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]
- Fix Google workspace pagination and document ID generation. {pull}33666[33666]
- Fix PANW handling of messages with event.original already set. {issue}33829[33829] {pull}33830[33830]
- Rename identity as identity_name when the value is a string in Azure Platform Logs. {pull}33654[33654]
- Fix input cancellation handling when HTTP client does not support contexts. {issue}33962[33962] {pull}33968[33968]

*Heartbeat*
- Fix broken zip URL monitors. NOTE: Zip URL Monitors will be removed in version 8.7 and replaced with project monitors. {pull}33723[33723]
Expand Down
23 changes: 12 additions & 11 deletions x-pack/filebeat/input/cel/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,21 @@ func (input) run(env v2.Context, src *source, cursor map[string]interface{}, pub
log.Info("process repeated request")
var waitUntil time.Time
for {
// We have a special-case wait for when we have a zero limit.
// x/time/rate allow a burst through even when the limit is zero
// so in order to ensure that we don't try until we are out of
// purgatory we calculate how long we should wait according to
// the retry after for a 429 and rate limit headers if we have
// a zero rate quota. See handleResponse below.
if wait := time.Until(waitUntil); wait > 0 {
// We have a special-case wait for when we have a zero limit.
// x/time/rate allow a burst through even when the limit is zero
// so in order to ensure that we don't try until we are out of
// purgatory we calculate how long we should wait according to
// the retry after for a 429 and rate limit headers if we have
// a zero rate quota. See handleResponse below.
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(wait):
}
} else if err = ctx.Err(); err != nil {
// Otherwise exit if we have been cancelled.
return err
}

// Process a set of event requests.
Expand Down Expand Up @@ -846,15 +849,13 @@ func newProgram(src, root string, client *http.Client, limiter *rate.Limiter, pa

func evalWith(ctx context.Context, prg cel.Program, input map[string]interface{}) (map[string]interface{}, error) {
out, _, err := prg.ContextEval(ctx, input)
if e := ctx.Err(); e != nil {
err = e
}
if err != nil {
input["events"] = map[string]interface{}{"error.message": fmt.Sprintf("failed eval: %v", err)}
return input, fmt.Errorf("failed eval: %w", err)
}
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}

v, err := out.ConvertToNative(reflect.TypeOf(&structpb.Value{}))
if err != nil {
Expand Down