Skip to content

Commit 1655d36

Browse files
Improve TestKubernetesJournaldInput (#11256) (#11315)
- 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) # Conflicts: # testing/integration/k8s/testdata/journald-otel.yml Co-authored-by: Tiago Queiroz <[email protected]>
1 parent b2ceb54 commit 1655d36

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-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
@@ -136,6 +136,12 @@ func journaldTest(
136136
t.Errorf("context error: %v", ctx.Err())
137137
}
138138

139+
t.Cleanup(func() {
140+
if t.Failed() {
141+
t.Logf("Index: %q, filter condition: %q=%q", index, field, value)
142+
}
143+
})
144+
139145
// Query the index and filter by the input type
140146
docs := integration.FindESDocs(t, func() (estools.Documents, error) {
141147
return estools.GetLogsForIndexWithContext(
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
receivers:
2+
filebeatreceiver:
3+
filebeat:
4+
inputs:
5+
- type: journald
6+
id: journald-input
7+
paths:
8+
- /opt/journal/
9+
merge: true
10+
11+
output:
12+
otelconsumer:
13+
logging:
14+
level: debug
15+
selectors:
16+
- '*'
17+
18+
processors:
19+
resource:
20+
attributes:
21+
- key: data_stream.namespace
22+
action: insert
23+
value: "${EA_POLICY_NAMESPACE}"
24+
25+
exporters:
26+
elasticsearch:
27+
endpoint: "${ES_HOST}"
28+
api_key: "${ES_API_KEY_ENCODED}"
29+
30+
service:
31+
pipelines:
32+
logs:
33+
receivers: [filebeatreceiver]
34+
processors: [resource]
35+
exporters:
36+
- elasticsearch
37+
telemetry:
38+
logs:
39+
level: DEBUG
40+
encoding: json
41+
disable_stacktrace: true

0 commit comments

Comments
 (0)