Skip to content
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 and Improved Errors #30632

Merged
merged 129 commits into from Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
dee25ff
Moar intervals
andrewvc Jul 4, 2019
a3a7cbd
Checkpoint
andrewvc Jul 8, 2019
72fab36
Checkpoint
andrewvc Jul 9, 2019
22e7c12
Checkpoint
andrewvc Jul 11, 2019
aab5d8a
Merge remote-tracking branch 'origin/master' into intervals
andrewvc Sep 13, 2019
b46f81d
[Heartbeat] Report next_run info per event
andrewvc Sep 13, 2019
e90a046
Add changelog
andrewvc Sep 13, 2019
cdeac64
Incorporate PR feedback
andrewvc Sep 18, 2019
077be58
Checkpoint
andrewvc Oct 28, 2019
b06323f
Checkpoint
andrewvc Oct 28, 2019
a371f6e
Just report the timespan
andrewvc Nov 26, 2019
9c8dbe5
Merge remote-tracking branch 'origin/master' into next-run-range
andrewvc Nov 26, 2019
3e4e8ea
fix tests
andrewvc Nov 26, 2019
c9b39cb
fix relnote
andrewvc Nov 26, 2019
a00aa0f
Fmt
andrewvc Nov 26, 2019
e1d0c65
Tweaks
andrewvc Nov 26, 2019
da1fde1
Factor timeout into timespans
andrewvc Nov 26, 2019
4e08b3d
fmt
andrewvc Nov 26, 2019
51bffaa
Merge remote-tracking branch 'origin/master' into next-run-range
andrewvc Dec 8, 2019
f74c85d
Merge remote-tracking branch 'origin/master' into next-run-range
andrewvc Dec 11, 2019
1a7c1f4
Merge remote-tracking branch 'origin/master' into next-run-range
andrewvc Dec 12, 2019
0150408
Don't require docs on date_range sub-keys
andrewvc Dec 12, 2019
95acb3c
Remove print
andrewvc Dec 12, 2019
d565042
Merge remote-tracking branch 'origin/master' into next-run-range
andrewvc Dec 13, 2019
7b2162a
FMT
andrewvc Dec 13, 2019
0b28b6f
Merge remote-tracking branch 'origin/master' into intervals
andrewvc Dec 16, 2019
8feb085
Checkpoint
andrewvc Dec 16, 2019
9232921
Merge remote-tracking branch 'origin/master' into next-run-range
andrewvc Dec 16, 2019
7bf22b5
Merge branch 'next-run-range' into intervals
andrewvc Dec 16, 2019
89563ea
Merge remote-tracking branch 'origin/master' into intervals
andrewvc Dec 16, 2019
9cadda9
Merge remote-tracking branch 'origin/master' into intervals
andrewvc Aug 11, 2020
e744853
Merge commit '9cadda912e93fa0a21bf02e1164dcf96e0b9c606' into tv2
andrewvc Mar 2, 2022
67a4191
More
andrewvc Mar 10, 2022
5a15d3c
[DOCS] Removed reference to the Stack GS (#32083)
debadair Jun 23, 2022
a55ae58
[DOCS] Removed reference to the Stack GS (#32119)
debadair Jun 27, 2022
9cbb78e
Merge branch 'main', remote-tracking branch 'origin' into tv2
andrewvc Jul 6, 2022
de4f4de
Unblock blocked monitors test
andrewvc Jul 6, 2022
1814865
Works for browsers
andrewvc Jul 6, 2022
e0c8bc5
Almost working
andrewvc Jul 7, 2022
8bf1b05
more is working
andrewvc Jul 7, 2022
6751721
Merge remote-tracking branch 'origin/main' into tv2
andrewvc Aug 8, 2022
83e26b6
Clean-up initialization of ES client
andrewvc Aug 8, 2022
844460c
Many cleanups
andrewvc Aug 8, 2022
3a1d963
Checkpoint for flapping refactor
andrewvc Aug 8, 2022
21d6062
Checkpoint
andrewvc Aug 9, 2022
26eac4e
Fix tracker, add basic tracker tests, plus type for loading past state.
andrewvc Aug 10, 2022
9af04c3
Merge remote-tracking branch 'origin/main' into tv2
andrewvc Aug 11, 2022
5fdba6c
Checkpoint
andrewvc Aug 11, 2022
4da0d7e
Checkpoint
andrewvc Aug 11, 2022
6f4c20a
ES kinda works in testing.
andrewvc Aug 11, 2022
4e4af45
checkpoint
andrewvc Aug 11, 2022
ec133a5
Cleanup and refactor
andrewvc Aug 12, 2022
5b7c268
Merge remote-tracking branch 'origin/main' into tv2
andrewvc Aug 12, 2022
bed5fbf
Changelog
andrewvc Aug 12, 2022
d42b383
Cleanup dev tools usage
andrewvc Aug 12, 2022
8ac7d40
Group imports
andrewvc Aug 12, 2022
d6ed347
Cleanups
andrewvc Aug 12, 2022
79ac24a
Cleanups
andrewvc Aug 12, 2022
102db33
Cleanups
andrewvc Aug 12, 2022
c7178cc
Cleanups
andrewvc Aug 12, 2022
a7ff0e2
Cleanups
andrewvc Aug 12, 2022
1ab5ff5
Cleanups
andrewvc Aug 12, 2022
1163d53
Cleanups
andrewvc Aug 12, 2022
cf99c89
Update and add run xml
andrewvc Aug 12, 2022
007b607
Cleanups
andrewvc Aug 12, 2022
701f48c
More inclusive index pattern
andrewvc Aug 12, 2022
00199f8
More inclusive index pattern
andrewvc Aug 12, 2022
0247783
Tweaks
andrewvc Aug 12, 2022
55ae272
Tweaks
andrewvc Aug 12, 2022
ce39e3f
Tweaks for flapping
andrewvc Aug 12, 2022
cfb33c0
Fix infinite storage growth
andrewvc Aug 12, 2022
6a2e430
Fix infinite storage growth
andrewvc Aug 12, 2022
372281d
Add tests for transitions
andrewvc Aug 12, 2022
4eff88d
FMT
andrewvc Aug 12, 2022
4262352
FMT
andrewvc Aug 12, 2022
9723532
Update and refine ECS types / checks to more precisely test ECS errors
andrewvc Aug 15, 2022
f22b067
Fix state ends
andrewvc Aug 15, 2022
c480df1
Fix test failures
andrewvc Aug 15, 2022
7565406
Use error codes for most test situations
andrewvc Aug 15, 2022
56a0cd2
Fixup connection errors in HTTP tests
andrewvc Aug 15, 2022
2af1a0a
Fix broken HTTP errors
andrewvc Aug 15, 2022
8e67dd9
Make linter happy
andrewvc Aug 16, 2022
107a52b
Make linter happy, remove runner XML
andrewvc Aug 17, 2022
bff7ac8
Make linter happy
andrewvc Aug 17, 2022
55cbff0
Make linter happy
andrewvc Aug 17, 2022
363a6f8
Fix integration test targeting
andrewvc Aug 17, 2022
8500f22
Make linter happy
andrewvc Aug 17, 2022
131e187
Integration tests fixed in non-xpack heartbeat
andrewvc Aug 17, 2022
c446705
Add empty pythonIntegTest mage targets to make CI happy
andrewvc Aug 17, 2022
43dd0fc
Remove flap history field from state.ends
andrewvc Aug 17, 2022
a05c1fd
Fix nesting of state.ends
andrewvc Aug 17, 2022
c48d71a
Merge remote-tracking branch 'origin/main' into tv2
andrewvc Aug 17, 2022
e298ac6
Merge remote-tracking branch 'origin/main' into tv2
andrewvc Aug 29, 2022
54c7705
Add geo config
andrewvc Aug 29, 2022
c8f8a82
Initial tests and functionality for geo per monitor
andrewvc Aug 29, 2022
0211a38
ES loader now supports locations
andrewvc Aug 29, 2022
73b435d
FMT
andrewvc Aug 29, 2022
315b1cf
Disable flapping by default, add tests for this
andrewvc Aug 30, 2022
305c837
Fix broken integ tests, refactor integ framework
andrewvc Aug 30, 2022
a27c7ec
Initial work for scenario tests with ES
andrewvc Aug 30, 2022
7f010b1
Format
andrewvc Aug 30, 2022
eb0de76
Checkpoint
andrewvc Aug 30, 2022
3e285df
Fix stateloader scenario tests
andrewvc Aug 30, 2022
3eede87
Cleanup framework
andrewvc Aug 30, 2022
8ff8267
Make linter happy
andrewvc Aug 30, 2022
fdc4507
Make linter happy
andrewvc Aug 30, 2022
2fbe2e0
Merge remote-tracking branch 'origin/main' into tv2
andrewvc Aug 31, 2022
27435f0
Fix windows targetting
andrewvc Aug 31, 2022
3739f24
Restrict all browser source from win builds
andrewvc Aug 31, 2022
e9386a4
Fix win deps
andrewvc Aug 31, 2022
1194b06
Merge branch 'main' into tv2
andrewvc Sep 1, 2022
2e952f1
Merge remote-tracking branch 'origin/main' into tv2
andrewvc Sep 6, 2022
793eb39
Incorporate PR feedback
andrewvc Sep 7, 2022
aa5e7dc
Merge remote-tracking branch 'origin/main' into tv2
andrewvc Sep 7, 2022
b9f7590
Apply suggestions from code review
andrewvc Sep 7, 2022
cb8bce3
Merge remote-tracking branch 'andrewvc/tv2' into tv2
andrewvc Sep 7, 2022
70bd444
Update heartbeat/monitors/wrappers/monitorstate/tracker.go
andrewvc Sep 7, 2022
c11982f
Incorporate PR feedback
andrewvc Sep 7, 2022
903c841
Merge remote-tracking branch 'andrewvc/tv2' into tv2
andrewvc Sep 7, 2022
ee08dc7
Remove unnecessary state loader assignment
andrewvc Sep 8, 2022
eed6a89
Remove browser from win tests
andrewvc Sep 8, 2022
6ecac3e
Fix state loader to only use ES state loader with ES output
andrewvc Sep 9, 2022
bc39d5a
Don't run integ tests on windows
andrewvc Sep 9, 2022
045969b
Revert "ci: enable windows for testing heartbeat (#32937)"
andrewvc Sep 12, 2022
779da1b
Rename monitor.location to monitor.run_from and add tests for observe…
andrewvc Sep 12, 2022
04d29e5
Merge branch 'main' into tv2
andrewvc Sep 13, 2022
a404afa
Incorporate PR feedback
andrewvc Sep 13, 2022
816734d
Merge remote-tracking branch 'origin/main' into tv2
andrewvc Sep 13, 2022
34783dc
Merge remote-tracking branch 'andrewvc/tv2' into tv2
andrewvc Sep 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions heartbeat/monitors/factory.go
Expand Up @@ -200,8 +200,8 @@ func newCommonPublishConfigs(info beat.Info, beatLocation *config.LocationWithID
// Generally speaking direct HB users would use the beat location, and the synthetics service may as well (TBD)
// while Fleet configured monitors will always use a per location monitor
var loc *config.LocationWithID
if sf.Location != nil {
loc = sf.Location
if sf.RunFrom != nil {
loc = sf.RunFrom
} else {
loc = beatLocation
}
Expand Down
17 changes: 11 additions & 6 deletions heartbeat/monitors/mocks.go
Expand Up @@ -90,10 +90,11 @@ func makeMockFactory(pluginsReg *plugin.PluginsReg) (factory *RunnerFactory, sch
}

type mockClient struct {
publishLog []*beat.Event
pipeline beat.Pipeline
closed bool
mtx sync.Mutex
publishLog []*beat.Event
pipeline beat.Pipeline
closed bool
mtx sync.Mutex
clientConfig beat.ClientConfig
}

func (c *mockClient) IsClosed() bool {
Expand All @@ -104,6 +105,10 @@ func (c *mockClient) IsClosed() bool {
}

func (c *mockClient) Publish(e beat.Event) {
if c.clientConfig.Processing.Processor != nil {
outE, _ := c.clientConfig.Processing.Processor.Run(&e)
e = *outE
}
c.PublishAll([]beat.Event{e})
}

Expand Down Expand Up @@ -148,11 +153,11 @@ func (pc *MockPipeline) Connect() (beat.Client, error) {
return pc.ConnectWith(beat.ClientConfig{})
}

func (pc *MockPipeline) ConnectWith(beat.ClientConfig) (beat.Client, error) {
func (pc *MockPipeline) ConnectWith(cc beat.ClientConfig) (beat.Client, error) {
pc.mtx.Lock()
defer pc.mtx.Unlock()

c := &mockClient{pipeline: pc}
c := &mockClient{pipeline: pc, clientConfig: cc}

pc.Clients = append(pc.Clients, c)

Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors/stdfields/stdfields.go
Expand Up @@ -50,7 +50,7 @@ type StdMonitorFields struct {
ZipUrl *config.C `config:"zip_url"`
Local *config.C `config:"local"`
} `config:"source"`
Location *hbconfig.LocationWithID `config:"location"`
RunFrom *hbconfig.LocationWithID `config:"run_from"`
}

func ConfigToStdMonitorFields(conf *config.C) (StdMonitorFields, error) {
Expand Down
4 changes: 2 additions & 2 deletions heartbeat/monitors/wrappers/monitorstate/esloader.go
Expand Up @@ -56,9 +56,9 @@ func MakeESLoader(esc *elasticsearch.Client, indexPattern string, beatLocation *
},
}

if sf.Location != nil {
if sf.RunFrom != nil {
queryMustClauses = append(queryMustClauses, mapstr.M{
"match": mapstr.M{"observer.name": sf.Location.ID},
"match": mapstr.M{"observer.name": sf.RunFrom.ID},
})
}

Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors/wrappers/monitorstate/monitorstate.go
Expand Up @@ -44,7 +44,7 @@ func newMonitorState(sf stdfields.StdMonitorFields, status StateStatus, ctr int,
// ID is unique and sortable by time for easier aggregations
// Note that we add an incrementing counter to help with the fact that
// millisecond res isn't quite enough for uniqueness (esp. in tests)
ID: fmt.Sprintf("%s-%s-%x-%x", sf.ID, sf.Location, now.UnixMilli(), ctr),
ID: fmt.Sprintf("%s-%s-%x-%x", sf.ID, sf.RunFrom, now.UnixMilli(), ctr),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to account for missing RunFrom config. This is what I see in states

  "state": {
    "started_at": "2022-09-13T11:22:16.489384-07:00",
    "up": 0,
    "ends": null,
    "id": "my-monitor-%!s(*config.LocationWithID=<nil>)-183381669a9-0",
    "duration_ms": 20003,
    "status": "down",
    "checks": 3,
    "down": 3,
    "flap_history": []
  },

We can default to unknown location ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it should be RunFrom.id, since its using interface now.

StartedAt: now,
DurationMs: 0,
Status: status,
Expand Down
15 changes: 15 additions & 0 deletions x-pack/heartbeat/scenarios/basics_test.go
Expand Up @@ -78,3 +78,18 @@ func TestLightweightSummaries(t *testing.T) {
}
})
}

func TestRunFromOverride(t *testing.T) {
scenarioDB.RunAllWithATwist(t, TwistAddRunFrom, func(t *testing.T, mtr *framework.MonitorTestRun, err error) {
for _, e := range mtr.Events() {
testslike.Test(t, lookslike.MustCompile(map[string]interface{}{
"observer": map[string]interface{}{
"name": TestLocationDefault.ID,
"geo": map[string]interface{}{
"name": TestLocationDefault.Geo.Name,
},
},
}), e.Fields)
}
})
}
4 changes: 2 additions & 2 deletions x-pack/heartbeat/scenarios/framework/fakeloader.go
Expand Up @@ -27,8 +27,8 @@ func newLoaderDB() *loaderDB {
}

func loaderDbKey(sf stdfields.StdMonitorFields) string {
if sf.Location != nil {
return fmt.Sprintf("%s-%s", sf.ID, sf.Location.ID)
if sf.RunFrom != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this logic to monitorstate.go?

return fmt.Sprintf("%s-%s", sf.ID, sf.RunFrom.ID)
}
return sf.ID
}
Expand Down
10 changes: 5 additions & 5 deletions x-pack/heartbeat/scenarios/framework/framework.go
Expand Up @@ -37,7 +37,7 @@ type Scenario struct {
Type string
Runner ScenarioRun
Tags []string
Location *hbconfig.LocationWithID
RunFrom *hbconfig.LocationWithID
NumberOfRuns int
}

Expand All @@ -63,9 +63,9 @@ func MultiTwist(twists ...Twist) Twist {

func (s Scenario) clone() Scenario {
copy := s
if s.Location != nil {
locationCopy := *s.Location
copy.Location = &locationCopy
if s.RunFrom != nil {
locationCopy := *s.RunFrom
copy.RunFrom = &locationCopy
}
return copy
}
Expand Down Expand Up @@ -102,7 +102,7 @@ func (s Scenario) Run(t *testing.T, twist Twist, callback func(t *testing.T, mtr
var conf mapstr.M
for i := 0; i < numberRuns; i++ {
var mtr *MonitorTestRun
mtr, err = runMonitorOnce(t, cfgMap, runS.Location, loaderDB.StateLoader())
mtr, err = runMonitorOnce(t, cfgMap, runS.RunFrom, loaderDB.StateLoader())

mtr.wait()
events = append(events, mtr.Events()...)
Expand Down
10 changes: 5 additions & 5 deletions x-pack/heartbeat/scenarios/framework/framework_test.go
Expand Up @@ -25,7 +25,7 @@ var testScenario Scenario = Scenario{
"schedule": "@every 10s",
}, nil, nil
},
Location: &config.LocationWithID{
RunFrom: &config.LocationWithID{
ID: "TestID",
Geo: util.GeoConfig{
Name: "TestName",
Expand All @@ -39,9 +39,9 @@ func TestClone(t *testing.T) {
require.NotEqual(t, testScenario.Name, clone.Name)
clone.Tags = []string{"CloneTag"}
require.NotEqual(t, testScenario.Tags, clone.Tags)
clone.Location.ID = "CloneID"
require.NotEqual(t, testScenario.Location.ID, clone.Location.ID)
clone.Location.Geo.Name = "CloneGeoName"
require.NotEqual(t, testScenario.Location.Geo.Name, clone.Location.Geo.Name)
clone.RunFrom.ID = "CloneID"
require.NotEqual(t, testScenario.RunFrom.ID, clone.RunFrom.ID)
clone.RunFrom.Geo.Name = "CloneGeoName"
require.NotEqual(t, testScenario.RunFrom.Geo.Name, clone.RunFrom.Geo.Name)

}
2 changes: 1 addition & 1 deletion x-pack/heartbeat/scenarios/stateloader_test.go
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/elastic/beats/v7/x-pack/heartbeat/scenarios/framework"
)

var esIntegTwists = framework.MultiTwist(TwistAddLocation, TwistMultiRun(3))
var esIntegTwists = framework.MultiTwist(TwistAddRunFrom, TwistMultiRun(3))

func TestStateContinuity(t *testing.T) {
scenarioDB.RunAllWithATwist(t, esIntegTwists, func(t *testing.T, mtr *framework.MonitorTestRun, err error) {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/heartbeat/scenarios/twists.go
Expand Up @@ -22,8 +22,8 @@ var TestLocationMpls = &config.LocationWithID{
},
}

var TwistAddLocation = framework.MakeTwist("add location", func(s framework.Scenario) framework.Scenario {
s.Location = TestLocationDefault
var TwistAddRunFrom = framework.MakeTwist("add run_from", func(s framework.Scenario) framework.Scenario {
s.RunFrom = TestLocationDefault
return s
})

Expand Down