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

testing: set env in docker entrypoint for logstash #3994

Merged
merged 1 commit into from
Apr 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
testing: set env in docker entrypoint for logstash
Also make the test that revealed the failure a bit more strict
Giuseppe Valente committed Apr 11, 2017
commit 12553ed41597799550bc97e2ed05d8209f9b49ab
26 changes: 19 additions & 7 deletions libbeat/outputs/logstash/logstash_integration_test.go
Original file line number Diff line number Diff line change
@@ -219,15 +219,18 @@ func (es *esConnection) Count() (int, error) {
return resp.Count, nil
}

func waitUntilTrue(duration time.Duration, fn func() bool) bool {
func waitUntilTrue(duration time.Duration, fn func() bool) (bool, time.Duration) {
end := time.Now().Add(duration)
var timeSlept time.Duration
sleepTime := 100 * time.Millisecond
for time.Now().Before(end) {
if fn() {
return true
return true, timeSlept
}
time.Sleep(100 * time.Millisecond)
time.Sleep(sleepTime)
timeSlept += sleepTime
}
return false
return false, timeSlept
}

func checkIndex(reader esCountReader, minValues int) func() bool {
@@ -269,10 +272,18 @@ func testSendMessageViaLogstash(t *testing.T, name string, tls bool) {
"type": "log",
"message": "hello world",
}}
ls.PublishEvent(nil, testOptions, event)
err := ls.PublishEvent(nil, testOptions, event)
if err != nil {
t.Fatalf("failed to publish to Logstash: %s", err)
}

// wait for logstash event flush + elasticsearch
waitUntilTrue(5*time.Second, checkIndex(ls, 1))
timeout := 5 * time.Second
if ok, waited := waitUntilTrue(timeout, checkIndex(ls, 1)); !ok {
t.Fatalf("Logstash event flush timed out after %s", timeout)
} else {
t.Logf("Logstash event flushed after %s", waited)
}

// search value in logstash elasticsearch index
resp, err := ls.Read()
@@ -377,8 +388,9 @@ func testSendMultipleBatchesViaLogstash(
}

// wait for logstash event flush + elasticsearch
ok := waitUntilTrue(5*time.Second, checkIndex(ls, numBatches*batchSize))
ok, waited := waitUntilTrue(5*time.Second, checkIndex(ls, numBatches*batchSize))
assert.True(t, ok) // check number of events matches total number of events
t.Logf("Logstash event flushed after %s", waited)

// search value in logstash elasticsearch index
resp, err := ls.Read()
1 change: 1 addition & 0 deletions testing/environments/docker/logstash/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@ updateConfigFile() {

# Main

readParams
updateConfigFile
waitForElasticsearch
exec "$@"