Skip to content

Commit 45270e5

Browse files
belimawrmergify[bot]
authored andcommitted
Improve TestKubernetesJournaldInput (#11256)
- Log as ndjson so logs can easily be parsed/ingested into Elasticsearch - Set the log level to debug so we can see the events - If the test fails, log the index and search condition used - Improve `FindESDocs` to not log expected failures/errors (cherry picked from commit 3062264)
1 parent 1902651 commit 45270e5

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

testing/integration/common.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"testing"
1414
"time"
1515

16+
"github.com/stretchr/testify/assert"
1617
"github.com/stretchr/testify/require"
1718

1819
"github.com/elastic/elastic-agent-libs/testing/estools"
@@ -33,21 +34,17 @@ func GetESHost() (string, error) {
3334
// FindESDocs runs `findFn` until at least one document is returned and there is no error
3435
func FindESDocs(t *testing.T, findFn func() (estools.Documents, error)) estools.Documents {
3536
var docs estools.Documents
36-
require.Eventually(
37+
require.EventuallyWithT(
3738
t,
38-
func() bool {
39+
func(c *assert.CollectT) {
3940
var err error
4041
docs, err = findFn()
41-
if err != nil {
42-
t.Logf("got an error querying ES, retrying. Error: %s", err)
43-
return false
44-
}
45-
46-
return docs.Hits.Total.Value != 0
42+
require.NoErrorf(c, err, "got an error querying ES, retrying. Error: %s", err)
43+
require.NotEqualValues(c, 0, docs.Hits.Total.Value, "expecting at least one document returned by 'findFn'")
4744
},
4845
3*time.Minute,
4946
15*time.Second,
50-
)
47+
"did not find the expected documents on ES")
5148

5249
return docs
5350
}

testing/integration/k8s/journald_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ func journaldTest(
211211
t.Errorf("context error: %v", ctx.Err())
212212
}
213213

214+
t.Cleanup(func() {
215+
if t.Failed() {
216+
t.Logf("Index: %q, filter condition: %q=%q", index, field, value)
217+
}
218+
})
219+
214220
// Query the index and filter by the input type
215221
docs := integration.FindESDocs(t, func() (estools.Documents, error) {
216222
return estools.GetLogsForIndexWithContext(

testing/integration/k8s/testdata/journald-otel.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ service:
3434
processors: [resource]
3535
exporters:
3636
- elasticsearch
37+
telemetry:
38+
logs:
39+
level: DEBUG
40+
encoding: json
41+
disable_stacktrace: true

0 commit comments

Comments
 (0)