-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Heartbeat] Fix run from location in states loader #35336
Changes from all commits
e021784
c8d6d8d
2225937
bd58130
6477ba1
4241c48
0f21c5f
6ff8c3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,12 @@ func MakeESLoader(esc *eslegclient.Connection, indexPattern string, beatLocation | |
logp.L().Warn("ES state loader initialized with no index pattern, will not load states from ES") | ||
return NilStateLoader | ||
} | ||
|
||
return func(sf stdfields.StdMonitorFields) (*State, error) { | ||
var runFromID string | ||
if sf.RunFrom != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldnt we default to using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The purpose of this is that we want the fleet integration to set the location correctly, however the fleet integration can only set monitor fields, not root fields. Hence the precedence |
||
runFromID = sf.RunFrom.ID | ||
} | ||
queryMustClauses := []mapstr.M{ | ||
{ | ||
"match": mapstr.M{"monitor.id": sf.ID}, | ||
|
@@ -54,9 +59,9 @@ func MakeESLoader(esc *eslegclient.Connection, indexPattern string, beatLocation | |
}, | ||
} | ||
|
||
if sf.RunFrom != nil { | ||
if runFromID != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found a bug with this approach, As we are passing the state query only when runFrom is specified. It leads to a bug when then runFrom is set and removed later.
|
||
queryMustClauses = append(queryMustClauses, mapstr.M{ | ||
"match": mapstr.M{"observer.name": sf.RunFrom.ID}, | ||
"match": mapstr.M{"observer.name": runFromID}, | ||
}) | ||
} | ||
reqBody := mapstr.M{ | ||
|
@@ -70,7 +75,7 @@ func MakeESLoader(esc *eslegclient.Connection, indexPattern string, beatLocation | |
|
||
status, body, err := esc.Request("POST", strings.Join([]string{"/", indexPattern, "/", "_search", "?size=1"}, ""), "", nil, reqBody) | ||
if err != nil || status > 299 { | ||
return nil, fmt.Errorf("error executing state search for %s: %w", sf.ID, err) | ||
return nil, fmt.Errorf("error executing state search for %s in loc=%s: %w", sf.ID, runFromID, err) | ||
} | ||
|
||
type stateHits struct { | ||
|
@@ -91,7 +96,7 @@ func MakeESLoader(esc *eslegclient.Connection, indexPattern string, beatLocation | |
} | ||
|
||
if len(sh.Hits.Hits) == 0 { | ||
logp.L().Infof("no previous state found for monitor %s", sf.ID) | ||
logp.L().Infof("no previous state found for monitor %s in Elasticsearch (loc=%s)", sf.ID, runFromID) | ||
return nil, nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we have
default
value as runFrom Id in state andunknown
here, can we follow a common value.