From ecc255b507573c7bb14318ecdd67a7d7786396fa Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Fri, 20 Sep 2024 12:41:19 +0930 Subject: [PATCH] x-pack/filebeat/input/cel: make http functions always available HTTP functions were previously conditional on the resource URL being an HTTP/HTTPS URL. In hindsight, this offers no benefits and can result in confusing errors when the end user enters an invalid URL for an HTTP-based integration. Instead of a URL-related or HTTP-related error, the user is given a compilation error indicating that the HTTP-related function that are being called (and they may not be aware of in any way) are not valid references. So let's just always make them available. --- CHANGELOG.next.asciidoc | 1 + x-pack/filebeat/input/cel/config.go | 6 +----- x-pack/filebeat/input/cel/input.go | 7 +------ 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index e36ea3396a9e..15a6bc29c45f 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -301,6 +301,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Allow attribute selection in the Active Directory entity analytics provider. {issue}40482[40482] {pull}40662[40662] - Improve error quality when CEL program does not correctly return an events array. {pull}40580[40580] - Add `use_kubeadm` config option for filebeat (both filbeat.input and autodiscovery) in order to toggle kubeadm-config api requests {pull}40301[40301] +- Make HTTP library function inclusion non-conditional in CEL input. {pull}[] *Auditbeat* diff --git a/x-pack/filebeat/input/cel/config.go b/x-pack/filebeat/input/cel/config.go index 7469120f8f21..992f97e43624 100644 --- a/x-pack/filebeat/input/cel/config.go +++ b/x-pack/filebeat/input/cel/config.go @@ -81,15 +81,11 @@ func (c config) Validate() error { return fmt.Errorf("failed to check regular expressions: %w", err) } // TODO: Consider just building the program here to avoid this wasted work. - var client *http.Client - if wantClient(c) { - client = &http.Client{} - } var patterns map[string]*regexp.Regexp if len(c.Regexps) != 0 { patterns = map[string]*regexp.Regexp{".": nil} } - _, _, err = newProgram(context.Background(), c.Program, root, client, nil, nil, patterns, c.XSDs, logp.L().Named("input.cel"), nil) + _, _, err = newProgram(context.Background(), c.Program, root, &http.Client{}, nil, nil, patterns, c.XSDs, logp.L().Named("input.cel"), nil) if err != nil { return fmt.Errorf("failed to check program: %w", err) } diff --git a/x-pack/filebeat/input/cel/input.go b/x-pack/filebeat/input/cel/input.go index 2096383de392..466950836eee 100644 --- a/x-pack/filebeat/input/cel/input.go +++ b/x-pack/filebeat/input/cel/input.go @@ -727,9 +727,6 @@ func getLimit(which string, rateLimit map[string]interface{}, log *logp.Logger) const lumberjackTimestamp = "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]-[0-9][0-9]-[0-9][0-9].[0-9][0-9][0-9]" func newClient(ctx context.Context, cfg config, log *logp.Logger, reg *monitoring.Registry) (*http.Client, *httplog.LoggingRoundTripper, error) { - if !wantClient(cfg) { - return nil, nil, nil - } c, err := cfg.Resource.Transport.Client(clientOptions(cfg.Resource.URL.URL, cfg.Resource.KeepAlive.settings())...) if err != nil { return nil, nil, err @@ -1012,14 +1009,12 @@ func newProgram(ctx context.Context, src, root string, client *http.Client, limi lib.Debug(debug(log, trace)), lib.File(mimetypes), lib.MIME(mimetypes), + lib.HTTPWithContext(ctx, client, limiter, auth), lib.Limit(limitPolicies), lib.Globals(map[string]interface{}{ "useragent": userAgent, }), } - if client != nil { - opts = append(opts, lib.HTTPWithContext(ctx, client, limiter, auth)) - } if len(patterns) != 0 { opts = append(opts, lib.Regexp(patterns)) }