[Heartbeat] States reloader and eslegclient#33405
Conversation
|
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
|
Pinging @elastic/uptime (Team:Uptime) |
|
/test |
andrewvc
left a comment
There was a problem hiding this comment.
Left an initial review based on viewing code alone, will do some manual testing next.
heartbeat/_meta/fields.common.yml
Outdated
| - name: down | ||
| type: integer | ||
| description: total down checks run | ||
| - name: reason |
There was a problem hiding this comment.
We should nix this unless we actually populate it in this PR
| Ends *State `json:"ends"` | ||
| Ends *State `json:"ends"` | ||
| // Cause of the transition to this state | ||
| Reason string `json:"reason"` |
There was a problem hiding this comment.
Once again, worth nixing unless we use it
heartbeat/docs/fields.asciidoc
Outdated
|
|
||
| -- | ||
|
|
||
| *`state.reason`*:: |
There was a problem hiding this comment.
Will be deleted by a mage update
| if esc != nil { | ||
| stateLoader = monitorstate.MakeESLoader(esc, "synthetics-*,heartbeat-*", parsedConfig.RunFrom) | ||
| stateLoader, replaceStateLoader := monitorstate.AtomicStateLoader(monitorstate.NilStateLoader) | ||
| if b.Config.Output.Name() == "elasticsearch" && !b.Manager.Enabled() { |
There was a problem hiding this comment.
We should also add in the changes from https://github.com/elastic/beats/pull/33375/files#diff-3edc3a1c86f948ac04dc2aeef09be1c549a2e5cbedd80a76e49dde4d95fa6883R82 which adds a heartbeat.states.enabled config flag. The service won't have the manager enabled, so we'll have to enable that to have states work with the service.
There was a problem hiding this comment.
This actually checks if heartbeat is in unmanaged mode (!b.Manager.Enabled()) to initialize a non-deferred states loader, so it should apply for the service as well.
IIRC, states flag was motivated by #33357. IMO, this PR supersedes the original problem since we can now load the config on both modes. Is there an scenario where we would still like to disable states?
| logp.L().Warn("Timeout trying to defer state loader") | ||
| } | ||
|
|
||
| defer cancel() |
There was a problem hiding this comment.
why defer these both if no statements follow them? Were they intended to go at the top of the function?
There was a problem hiding this comment.
Probably a mix of an idiomatic declaration of intent and a sequential mindset when writing it 😄 I can move them to the top
| stateLoader, replaceStateLoader := AtomicStateLoader(inner) | ||
|
|
||
| wg := sync.WaitGroup{} | ||
| ctx, cancel := context.WithTimeout(context.Background(), timeout) |
There was a problem hiding this comment.
Very idiomatic go concurrency!
| requireMSStatusCount(t, ms, StatusDown, 1) | ||
| } | ||
|
|
||
| func TestAtomicStateLoader(t *testing.T) { |
There was a problem hiding this comment.
Can we add a test for the new DeferredStateLoader as well?
andrewvc
left a comment
There was a problem hiding this comment.
I've tested this with heartbeat's local monitor reloading, it worked fine. I think the CFT cluster I used to test this was missing elastic/kibana#143162, but I'm LGTM given what I've seen here.
|
Drive by comment: this should ensure your ES client keeps working when we merge the agent V2 support for beats in the next few days. I have this PR listed as a "blocker" for our merge of the v2 agent changes here for this reason, to ensure your second ES client keeps working after we merge those changes. |
|
@cmacknz My initial impression was that IMO, the scope of elastic/elastic-agent#1476 changes with this approach. Do you think it would be possible to have a similar mechanism with the shipper? |
Yes, ideally this should be the only change you need to make. When the shipper is introduced, we just need to keep providing the Elasticsearch output configuration to Heartbeat and this code should keep working. |
* Better loading / reloading of state tracker * Refactor states loader to use eslegclient and reload config when running in managed mode * Add deferred state loader for managed instances, fix some logs * Fix integration tests * Review feedback, deferred loader unit test and changelog Co-authored-by: Andrew Cholakian <andrewvc@elastic.co> (cherry picked from commit 5c1d1af)
* Better loading / reloading of state tracker * Refactor states loader to use eslegclient and reload config when running in managed mode * Add deferred state loader for managed instances, fix some logs * Fix integration tests * Review feedback, deferred loader unit test and changelog Co-authored-by: Andrew Cholakian <andrewvc@elastic.co> (cherry picked from commit 5c1d1af) Co-authored-by: Emilio Alvarez Piñeiro <95703246+emilioalvap@users.noreply.github.com>
* Better loading / reloading of state tracker * Refactor states loader to use eslegclient and reload config when running in managed mode * Add deferred state loader for managed instances, fix some logs * Fix integration tests * Review feedback, deferred loader unit test and changelog Co-authored-by: Andrew Cholakian <andrewvc@elastic.co>
What does this PR do?
Requires andrewvc/integrations#1.
Supersedes #33357.
Fixes #33354, #33299 and #33244
This PR:
DeferredStateLoaderreloader for managed output section of heartbeat instances. It holds monitors from running state queries until the agent has had enough time to initialize it async or a default timeout is triggered.elasticsearch.Clientwitheslegclient.Connection, which supports alloutputoptions by default.Checklist
CHANGELOG.next.asciidocorCHANGELOG-developer.next.asciidoc.How to test this PR locally
To test
eslegclient:To test output reloader:
Screenshots