Skip to content

Commit

Permalink
x-pack/filebeat/input/cel: make http functions always available (#40912
Browse files Browse the repository at this point in the history
…) (#40933)

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.

(cherry picked from commit 14337dd)

Co-authored-by: Dan Kortschak <dan.kortschak@elastic.co>
  • Loading branch information
mergify[bot] and efd6 committed Sep 24, 2024
1 parent eac8157 commit 6114256
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
6 changes: 1 addition & 5 deletions x-pack/filebeat/input/cel/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 1 addition & 6 deletions x-pack/filebeat/input/cel/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit 6114256

Please sign in to comment.