This repository was archived by the owner on Sep 17, 2024. It is now read-only.
-
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
Merged
mdelapenya
merged 15 commits into
elastic:master
from
mdelapenya:ingest-manager-deploy-stand-alone-impl
Jun 24, 2020
Merged
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1ccf726
chore: do not pass metricbeat-specific info to the assertion method
mdelapenya 610483a
chore: support authenticated queries in the ES client
mdelapenya c8a4750
fix: compilation issue on metricbeat test suite
mdelapenya 3ae5586
feat: check that there are hits in the index
mdelapenya c00ef94
fix: add a small delay waiting for docs
mdelapenya bca95b2
Merge branch 'master' into ingest-manager-deploy-stand-alone-impl
mdelapenya da3f75b
feat: use a backoff+retry strategy waiting for a number of hits
mdelapenya 22deea6
chore: use new waitForHits method in metricbeat tests
mdelapenya 1612e44
fix: discard error to fix linter
mdelapenya e5f2ac6
chore: store container hostname in the struct, to be reused across steps
mdelapenya f5d9d58
chore: use service name in the feature file
mdelapenya 7b6d2f5
feat: stop the agent service, storing the time it happened
mdelapenya 93f48aa
feat: check that there are no hits in the index after the agent stops
mdelapenya 0506932
chore: extract search-agent-data to a function
mdelapenya acbb8ab
fix: remove more ocurrences of QUERY_MAX_ATTEMPTS
mdelapenya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
|
|
@@ -66,7 +70,113 @@ func (sats *StandAloneTestSuite) aStandaloneAgentIsDeployed() error { | |
| } | ||
|
|
||
| func (sats *StandAloneTestSuite) thereIsNewDataInTheIndexFromAgent() error { | ||
| return godog.ErrPending | ||
| timezone := "America/New_York" | ||
| now := time.Now() | ||
| startDate := now.Add(-15 * time.Minute) | ||
|
|
||
| serviceName := "ingest-manager_elastic-agent_1" | ||
| hostname, err := getContainerName(serviceName) | ||
| if err != nil { | ||
| log.WithFields(log.Fields{ | ||
| "error": err, | ||
| "service": serviceName, | ||
| }).Error("Could not retrieve container name from the Docker client") | ||
| return err | ||
| } | ||
|
|
||
| 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{}{}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| // wait an amount of time for documents | ||
| e2e.Sleep("5") | ||
|
|
||
| indexName := "logs-agent-default" | ||
|
|
||
| result, err := e2e.RetrySearch(indexName, esQuery, queryMaxAttempts, queryRetryTimeout) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| log.Debugf("Search result: %v", result) | ||
|
|
||
| err = e2e.AssertHitsArePresent(result) | ||
| if err != nil { | ||
| log.WithFields(log.Fields{ | ||
| "index": indexName, | ||
| }).Error(err.Error()) | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (sats *StandAloneTestSuite) theDockerContainerIsStopped(arg1 string) error { | ||
|
|
@@ -76,3 +186,21 @@ func (sats *StandAloneTestSuite) theDockerContainerIsStopped(arg1 string) error | |
| func (sats *StandAloneTestSuite) thereIsNoNewDataInTheIndexAfterAgentShutsDown() error { | ||
| return godog.ErrPending | ||
| } | ||
|
|
||
| func getContainerName(serviceName string) (string, error) { | ||
| log.WithFields(log.Fields{ | ||
| "service": serviceName, | ||
| }).Debug("Retrieving container name from the Docker client") | ||
|
|
||
| containerName, err := docker.ExecCommandIntoContainer(context.Background(), serviceName, "root", []string{"hostname"}) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| log.WithFields(log.Fields{ | ||
| "containerName": containerName, | ||
| "service": serviceName, | ||
| }).Debug("Container name retrieved from the Docker client") | ||
|
|
||
| return containerName, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,8 @@ func getElasticsearchClientFromHostPort(host string, port int) (*es.Client, erro | |
|
|
||
| cfg := es.Config{ | ||
| Addresses: []string{fmt.Sprintf("http://%s:%d", host, port)}, | ||
| Username: "elastic", | ||
|
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. I ran locally other tests using the ES client, and they pass! |
||
| Password: "changeme", | ||
| } | ||
| esClient, err := es.NewClient(cfg) | ||
| if err != nil { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As a follow-up improvement, I'm considering converting this basic retry into the backoff strategy. So it's in the TODO