Skip to content
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 @@ -230,6 +230,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Add Fleet status updating to HTTP JSON input. {issue}44282[44282] {pull}44365[44365]
- Added input metrics to Azure Blob Storage input. {issue}36641[36641] {pull}43954[43954]
- Added support for websocket keep_alive heartbeat in the streaming input. {issue}42277[42277] {pull}44204[44204]
- Allow empty HTTPJSON cursor template value evaluations to be ignored by Fleet health status updates. {pull}45361[45361]

*Auditbeat*

Expand Down
13 changes: 12 additions & 1 deletion x-pack/filebeat/input/httpjson/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,25 @@ func (c *cursor) update(trCtx *transformContext) {
}

for k, cfg := range c.cfg {
v, _ := cfg.Value.Execute(trCtx, transformable{}, k, cfg.Default, c.status, c.log)
stat := c.status
if cfg.mustIgnoreEmptyValue() {
stat = ignoreEmptyValueReporter{stat}
}
v, _ := cfg.Value.Execute(trCtx, transformable{}, k, cfg.Default, stat, c.log)
if v != "" || !cfg.mustIgnoreEmptyValue() {
_, _ = c.state.Put(k, v)
c.log.Debugf("cursor.%s stored with %s", k, v)
}
}
}

// ignoreEmptyValueReporter is an abuse of the type system to allow the cursor
// update mechanism to signal to valueTpl.Execute not to report empty values
// as health degraded.
type ignoreEmptyValueReporter struct {
status.StatusReporter
}

func (c *cursor) clone() mapstr.M {
if c == nil || c.state == nil {
return mapstr.M{}
Expand Down
4 changes: 3 additions & 1 deletion x-pack/filebeat/input/httpjson/value_tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@
val, err = fallback(errExecutingTemplate)
}
if err != nil {
stat.UpdateStatus(status.Degraded, fmt.Sprintf("failed to execute template %s: %v", targetName, err))
if _, ignoreEmpty := stat.(ignoreEmptyValueReporter); !ignoreEmpty || !errors.Is(err, errEmptyTemplateResult) {
stat.UpdateStatus(status.Degraded, fmt.Sprintf("failed to execute template %s: %v", targetName, err))
}
log.Debugw("template execution failed", "target", targetName, "error", err)
}
tryDebugTemplateValue(targetName, val, log)
Expand Down Expand Up @@ -329,7 +331,7 @@
case reflect.Float32, reflect.Float64:
return int64(vv.Float())
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
return int64(vv.Uint())

Check failure on line 334 in x-pack/filebeat/input/httpjson/value_tpl.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

G115: integer overflow conversion uint64 -> int64 (gosec)
case reflect.String:
f, _ := strconv.ParseFloat(vv.String(), 64)
return int64(f)
Expand Down
Loading