-
Notifications
You must be signed in to change notification settings - Fork 39
[Ingest-Manager] Implementation for the Deploy scenario of the stand-alone mode #140
Changes from all commits
1ccf726
610483a
c8a4750
3ae5586
c00ef94
bca95b2
da3f75b
22deea6
1612e44
e5f2ac6
f5d9d58
7b6d2f5
93f48aa
0506932
acbb8ab
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 |
|---|---|---|
|
|
@@ -21,12 +21,17 @@ var stackVersion = "8.0.0-SNAPSHOT" | |
| // affecting the runtime dependencies (or profile) | ||
| var profileEnv map[string]string | ||
|
|
||
| // queryRetryTimeout is the number of seconds between elasticsearch retry queries. | ||
| // It can be overriden by OP_RETRY_TIMEOUT env var | ||
| var queryRetryTimeout = 3 | ||
|
|
||
| // All URLs running on localhost as Kibana is expected to be exposed there | ||
| const kibanaBaseURL = "http://localhost:5601" | ||
|
|
||
| func init() { | ||
| config.Init() | ||
|
|
||
| queryRetryTimeout = e2e.GetIntegerFromEnv("OP_RETRY_TIMEOUT", queryRetryTimeout) | ||
| stackVersion = e2e.GetEnv("OP_STACK_VERSION", stackVersion) | ||
| } | ||
|
|
||
|
|
@@ -75,6 +80,8 @@ func IngestManagerFeatureContext(s *godog.Suite) { | |
| "minutes": minutesToBeHealthy, | ||
| }).Error("The Kibana instance could not get the healthy status") | ||
| } | ||
|
|
||
| imts.StandAlone.RuntimeDependenciesStartDate = time.Now() | ||
|
Contributor
Author
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. Marking when the runtime deps are started. We want to have here a lower boundary for queries |
||
| }) | ||
| s.BeforeScenario(func(*messages.Pickle) { | ||
| log.Debug("Before Ingest Manager scenario") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| "github.com/cucumber/godog" | ||
| "github.com/elastic/e2e-testing/cli/docker" | ||
| "github.com/elastic/e2e-testing/cli/services" | ||
| "github.com/elastic/e2e-testing/e2e" | ||
| log "github.com/sirupsen/logrus" | ||
|
|
@@ -11,6 +15,10 @@ import ( | |
| type StandAloneTestSuite struct { | ||
| AgentConfigFilePath string | ||
| Cleanup bool | ||
| Hostname string | ||
| // date controls for queries | ||
| AgentStoppedDate time.Time | ||
| RuntimeDependenciesStartDate time.Time | ||
| } | ||
|
|
||
| func (sats *StandAloneTestSuite) contributeSteps(s *godog.Suite) { | ||
|
|
@@ -44,6 +52,13 @@ func (sats *StandAloneTestSuite) aStandaloneAgentIsDeployed() error { | |
| return err | ||
| } | ||
|
|
||
| // get container hostname once | ||
| hostname, err := getContainerHostname(serviceName) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| sats.Hostname = hostname | ||
| sats.Cleanup = true | ||
|
|
||
| if log.IsLevelEnabled(log.DebugLevel) { | ||
|
|
@@ -66,13 +81,156 @@ func (sats *StandAloneTestSuite) aStandaloneAgentIsDeployed() error { | |
| } | ||
|
|
||
| func (sats *StandAloneTestSuite) thereIsNewDataInTheIndexFromAgent() error { | ||
| return godog.ErrPending | ||
| maxTimeout := time.Duration(queryRetryTimeout) * time.Minute | ||
| minimumHitsCount := 100 | ||
|
|
||
| result, err := searchAgentData(sats.Hostname, sats.RuntimeDependenciesStartDate, minimumHitsCount, maxTimeout) | ||
|
Contributor
Author
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. We use the moment the runtime deps (kibana + ES) started to check for documents |
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| log.Debugf("Search result: %v", result) | ||
|
|
||
| return e2e.AssertHitsArePresent(result) | ||
| } | ||
|
|
||
| func (sats *StandAloneTestSuite) theDockerContainerIsStopped(arg1 string) error { | ||
| return godog.ErrPending | ||
| func (sats *StandAloneTestSuite) theDockerContainerIsStopped(serviceName string) error { | ||
| serviceManager := services.NewServiceManager() | ||
|
|
||
| err := serviceManager.RemoveServicesFromCompose("ingest-manager", []string{serviceName}, profileEnv) | ||
| if err != nil { | ||
| log.WithFields(log.Fields{ | ||
| "error": err, | ||
| "service": serviceName, | ||
| }).Error("Could not stop the service.") | ||
|
|
||
| return err | ||
| } | ||
| sats.AgentStoppedDate = time.Now() | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (sats *StandAloneTestSuite) thereIsNoNewDataInTheIndexAfterAgentShutsDown() error { | ||
| return godog.ErrPending | ||
| maxTimeout := time.Duration(30) * time.Second | ||
| minimumHitsCount := 1 | ||
|
Comment on lines
+115
to
+116
Contributor
Author
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. With just one hit found in 30 secs, we should fail the assertion |
||
|
|
||
| result, err := searchAgentData(sats.Hostname, sats.AgentStoppedDate, minimumHitsCount, maxTimeout) | ||
|
Contributor
Author
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. We use the moment the agent stopped to check for documents
Contributor
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. I should have caught this earlier, but indeed - we should put in some minimal (1 second or 2??) padding on the chance that a doc was sent right as agent is stopping and is in ES microseconds after the agent stop time is recorded @mdelapenya what do you think?
Contributor
Author
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. Flakiness at sight!! TBH not sure, we can add a few seconds to that time
Contributor
Author
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. Let's merge as is, so we can observe how it behaves |
||
| if err != nil { | ||
| log.WithFields(log.Fields{ | ||
| "error": err, | ||
| }).Info("No documents were found for the Agent in the index after it stopped") | ||
| return nil | ||
| } | ||
|
|
||
| return e2e.AssertHitsAreNotPresent(result) | ||
| } | ||
|
|
||
| // we need the container name because we use the Docker Client instead of Docker Compose | ||
| func getContainerHostname(serviceName string) (string, error) { | ||
| containerName := "ingest-manager_" + serviceName + "_1" | ||
|
|
||
| log.WithFields(log.Fields{ | ||
| "service": serviceName, | ||
| "containerName": containerName, | ||
| }).Debug("Retrieving container name from the Docker client") | ||
|
|
||
| hostname, err := docker.ExecCommandIntoContainer(context.Background(), containerName, "root", []string{"hostname"}) | ||
| if err != nil { | ||
| log.WithFields(log.Fields{ | ||
| "containerName": containerName, | ||
| "error": err, | ||
| "service": serviceName, | ||
| }).Error("Could not retrieve container name from the Docker client") | ||
| return "", err | ||
| } | ||
|
|
||
| log.WithFields(log.Fields{ | ||
| "containerName": containerName, | ||
| "hostname": hostname, | ||
| "service": serviceName, | ||
| }).Info("Hostname retrieved from the Docker client") | ||
|
|
||
| return hostname, nil | ||
| } | ||
|
|
||
| func searchAgentData(hostname string, startDate time.Time, minimumHitsCount int, maxTimeout time.Duration) (e2e.SearchResult, error) { | ||
| timezone := "America/New_York" | ||
| now := time.Now() | ||
|
|
||
| esQuery := map[string]interface{}{ | ||
|
Contributor
Author
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. Translated query from: #126 (comment) |
||
| "version": true, | ||
| "size": 500, | ||
| "docvalue_fields": []map[string]interface{}{ | ||
| { | ||
| "field": "@timestamp", | ||
| "format": "date_time", | ||
| }, | ||
| { | ||
| "field": "system.process.cpu.start_time", | ||
| "format": "date_time", | ||
| }, | ||
| { | ||
| "field": "system.service.state_since", | ||
| "format": "date_time", | ||
| }, | ||
| }, | ||
| "_source": map[string]interface{}{ | ||
| "excludes": []map[string]interface{}{}, | ||
| }, | ||
| "query": map[string]interface{}{ | ||
| "bool": map[string]interface{}{ | ||
| "must": []map[string]interface{}{}, | ||
| "filter": []map[string]interface{}{ | ||
| { | ||
| "bool": map[string]interface{}{ | ||
| "filter": []map[string]interface{}{ | ||
| { | ||
| "bool": map[string]interface{}{ | ||
| "should": []map[string]interface{}{ | ||
| { | ||
| "match_phrase": map[string]interface{}{ | ||
| "host.name": hostname, | ||
| }, | ||
| }, | ||
| }, | ||
| "minimum_should_match": 1, | ||
| }, | ||
| }, | ||
| { | ||
| "bool": map[string]interface{}{ | ||
| "should": []map[string]interface{}{ | ||
| { | ||
| "range": map[string]interface{}{ | ||
| "@timestamp": map[string]interface{}{ | ||
| "gte": now, | ||
| "time_zone": timezone, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| "minimum_should_match": 1, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| "range": map[string]interface{}{ | ||
| "@timestamp": map[string]interface{}{ | ||
| "gte": startDate, | ||
| "format": "strict_date_optional_time", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| "should": []map[string]interface{}{}, | ||
| "must_not": []map[string]interface{}{}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| indexName := "logs-agent-default" | ||
|
|
||
| return e2e.WaitForNumberOfHits(indexName, esQuery, minimumHitsCount, maxTimeout) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Removed this argument, as the code is not using a fixed retry option any more