-
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] 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 |
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.
Left an initial review based on viewing code alone, will do some manual testing next.
heartbeat/_meta/fields.common.yml
Outdated
@@ -158,6 +158,8 @@ | |||
- name: down | |||
type: integer | |||
description: total down checks run | |||
- name: reason |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once again, worth nixing unless we use it
heartbeat/docs/fields.asciidoc
Outdated
@@ -16395,6 +16395,13 @@ type: object | |||
|
|||
-- | |||
|
|||
*`state.reason`*:: |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very idiomatic go concurrency!
@@ -65,3 +67,27 @@ func TestTrackerRecordFlappingDisabled(t *testing.T) { | |||
require.Equal(t, StatusDown, ms.Status) | |||
requireMSStatusCount(t, ms, StatusDown, 1) | |||
} | |||
|
|||
func TestAtomicStateLoader(t *testing.T) { |
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.
Can we add a test for the new DeferredStateLoader
as well?
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.
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:
DeferredStateLoader
reloader 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.Client
witheslegclient.Connection
, which supports alloutput
options by default.Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.How to test this PR locally
To test
eslegclient
:To test output reloader:
Screenshots