Skip to content

Commit 3e79fed

Browse files
mergify[bot]efd6
andauthored
x-pack/filebeat/input/httpjson: allow empty cursor template values to be ignored by health status updates (#45361) (#45398)
Health status changes are evaluated in CI for integrations and in some cases (aws.guardduty is the provocation here), there is a failed/empty evaluation. So allow ignore_empty_value configurations for cursor entries to also be ignored for health status updates, instead of being noted as a health degradation. (cherry picked from commit 0257f0c) Co-authored-by: Dan Kortschak <dan.kortschak@elastic.co>
1 parent 44d9c30 commit 3e79fed

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ otherwise no tag is added. {issue}42208[42208] {pull}42403[42403]
474474
- Add support for relationship expansion to EntraID entity analytics provider. {issue}43324[43324] {pull}44761[44761]
475475
- Update CEL mito extensions to v1.21.0. {issue}40762[40762] {pull}45107[45107]
476476
- Update CEL mito extensions to v1.22.0. {pull}45245[45245]
477+
- Allow empty HTTPJSON cursor template value evaluations to be ignored by Fleet health status updates. {pull}45361[45361]
477478

478479
*Auditbeat*
479480

x-pack/filebeat/input/httpjson/cursor.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,25 @@ func (c *cursor) update(trCtx *transformContext) {
5353
}
5454

5555
for k, cfg := range c.cfg {
56-
v, _ := cfg.Value.Execute(trCtx, transformable{}, k, cfg.Default, c.status, c.log)
56+
stat := c.status
57+
if cfg.mustIgnoreEmptyValue() {
58+
stat = ignoreEmptyValueReporter{stat}
59+
}
60+
v, _ := cfg.Value.Execute(trCtx, transformable{}, k, cfg.Default, stat, c.log)
5761
if v != "" || !cfg.mustIgnoreEmptyValue() {
5862
_, _ = c.state.Put(k, v)
5963
c.log.Debugf("cursor.%s stored with %s", k, v)
6064
}
6165
}
6266
}
6367

68+
// ignoreEmptyValueReporter is an abuse of the type system to allow the cursor
69+
// update mechanism to signal to valueTpl.Execute not to report empty values
70+
// as health degraded.
71+
type ignoreEmptyValueReporter struct {
72+
status.StatusReporter
73+
}
74+
6475
func (c *cursor) clone() mapstr.M {
6576
if c == nil || c.state == nil {
6677
return mapstr.M{}

x-pack/filebeat/input/httpjson/value_tpl.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ func (t *valueTpl) Execute(trCtx *transformContext, tr transformable, targetName
111111
val, err = fallback(errExecutingTemplate)
112112
}
113113
if err != nil {
114-
stat.UpdateStatus(status.Degraded, fmt.Sprintf("failed to execute template %s: %v", targetName, err))
114+
if _, ignoreEmpty := stat.(ignoreEmptyValueReporter); !ignoreEmpty || !errors.Is(err, errEmptyTemplateResult) {
115+
stat.UpdateStatus(status.Degraded, fmt.Sprintf("failed to execute template %s: %v", targetName, err))
116+
}
115117
log.Debugw("template execution failed", "target", targetName, "error", err)
116118
}
117119
tryDebugTemplateValue(targetName, val, log)

0 commit comments

Comments
 (0)