Skip to content

Commit 3c30546

Browse files
[9.1] (backport #11254) Use unique index for TestOtelLogsIngestion (#11420)
(cherry picked from commit 85241ff) # Conflicts: # magefile.go (cherry picked from commit 85241ff) # Conflicts: # magefile.go --------- Co-authored-by: Tiago Queiroz <[email protected]>
1 parent 60cecb7 commit 3c30546

File tree

7 files changed

+52
-62
lines changed

7 files changed

+52
-62
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,8 @@ elastic-agent.yml.*
5858
fleet.yml
5959
fleet.yml.lock
6060
fleet.yml.old
61-
pkg/component/fake/component/component
61+
internal/pkg/agent/application/filelock/testlocker/testlocker
6262
internal/pkg/agent/install/testblocking/testblocking
63+
internal/pkg/otel/manager/testing/testing
64+
pkg/component/fake/component/component
65+
pkg/core/process/testsignal/testsignal

NOTICE-fips.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,11 +1254,11 @@ SOFTWARE
12541254

12551255
--------------------------------------------------------------------------------
12561256
Dependency : github.com/elastic/elastic-agent-libs
1257-
Version: v0.26.1
1257+
Version: v0.28.0
12581258
Licence type (autodetected): Apache-2.0
12591259
--------------------------------------------------------------------------------
12601260

1261-
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.26.1/LICENSE:
1261+
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.28.0/LICENSE:
12621262

12631263
Apache License
12641264
Version 2.0, January 2004

NOTICE.txt

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,11 +1254,11 @@ SOFTWARE
12541254

12551255
--------------------------------------------------------------------------------
12561256
Dependency : github.com/elastic/elastic-agent-libs
1257-
Version: v0.26.1
1257+
Version: v0.28.0
12581258
Licence type (autodetected): Apache-2.0
12591259
--------------------------------------------------------------------------------
12601260

1261-
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.26.1/LICENSE:
1261+
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.28.0/LICENSE:
12621262

12631263
Apache License
12641264
Version 2.0, January 2004
@@ -46050,36 +46050,6 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/opentelemetry-l
4605046050
limitations under the License.
4605146051

4605246052

46053-
--------------------------------------------------------------------------------
46054-
Dependency : github.com/elastic/pkcs8
46055-
Version: v1.0.0
46056-
Licence type (autodetected): MIT
46057-
--------------------------------------------------------------------------------
46058-
46059-
Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected]/LICENSE:
46060-
46061-
The MIT License (MIT)
46062-
46063-
Copyright (c) 2014 youmark
46064-
46065-
Permission is hereby granted, free of charge, to any person obtaining a copy
46066-
of this software and associated documentation files (the "Software"), to deal
46067-
in the Software without restriction, including without limitation the rights
46068-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
46069-
copies of the Software, and to permit persons to whom the Software is
46070-
furnished to do so, subject to the following conditions:
46071-
46072-
The above copyright notice and this permission notice shall be included in all
46073-
copies or substantial portions of the Software.
46074-
46075-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46076-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46077-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46078-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46079-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
46080-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
46081-
SOFTWARE.
46082-
4608346053
--------------------------------------------------------------------------------
4608446054
Dependency : github.com/elastic/sarama
4608546055
Version: v1.19.1-0.20250603175145-7672917f26b6

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/elastic/cloud-on-k8s/v2 v2.0.0-20250327073047-b624240832ae
1919
github.com/elastic/elastic-agent-autodiscover v0.10.0
2020
github.com/elastic/elastic-agent-client/v7 v7.17.2
21-
github.com/elastic/elastic-agent-libs v0.26.1
21+
github.com/elastic/elastic-agent-libs v0.28.0
2222
github.com/elastic/elastic-agent-system-metrics v0.13.4
2323
github.com/elastic/elastic-transport-go/v8 v8.8.0
2424
github.com/elastic/go-elasticsearch/v8 v8.19.0
@@ -352,7 +352,6 @@ require (
352352
github.com/elastic/opentelemetry-collector-components/internal/sharedcomponent v0.0.0-20250220025958-386ba0c4bced // indirect
353353
github.com/elastic/opentelemetry-collector-components/processor/lsmintervalprocessor v0.8.0 // indirect
354354
github.com/elastic/opentelemetry-lib v0.21.0 // indirect
355-
github.com/elastic/pkcs8 v1.0.0 // indirect
356355
github.com/elastic/sarama v1.19.1-0.20250603175145-7672917f26b6 // indirect
357356
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
358357
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect

go.sum

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@ github.com/elastic/elastic-agent-autodiscover v0.10.0 h1:WJ4zl9uSfk1kHmn2B/0byQB
495495
github.com/elastic/elastic-agent-autodiscover v0.10.0/go.mod h1:Nf3zh9FcJ9nTTswTwDTUAqXmvQllOrNliM6xmORSxwE=
496496
github.com/elastic/elastic-agent-client/v7 v7.17.2 h1:Cl2TeABqWZgW40t5fchGWT/sRk4MDDLWA0d8iHHOxLA=
497497
github.com/elastic/elastic-agent-client/v7 v7.17.2/go.mod h1:5irRFqp6HLqtu1S+OeY0jg8x7K6PLL+DW+PwVk1vJnk=
498-
github.com/elastic/elastic-agent-libs v0.26.1 h1:ywjSQajyjiv7zQTsyZjghIVb7PpPCrXZRUOhbV3KdFM=
499-
github.com/elastic/elastic-agent-libs v0.26.1/go.mod h1:o/iXtbHYaojpG4BOY7Z3hFMQAgEoqq2owO17JPGpf3A=
498+
github.com/elastic/elastic-agent-libs v0.28.0 h1:UDL9aSxgjqC9TrHAEHgI8gtuhRYPM/1gSfh7ztHWWLw=
499+
github.com/elastic/elastic-agent-libs v0.28.0/go.mod h1:0xUg7alsNE/WhY9DZRIdTYW75nqSHC1octIAg//j/PQ=
500500
github.com/elastic/elastic-agent-system-metrics v0.13.4 h1:gX8VdlQyakPcPKFpD7uHv2QLRDyguuKfZgu0LE27V7c=
501501
github.com/elastic/elastic-agent-system-metrics v0.13.4/go.mod h1:lB8veYWYBlA9eF6TahmPN87G1IEgWlbep7QSqLSW90U=
502502
github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo=
@@ -561,8 +561,6 @@ github.com/elastic/opentelemetry-collector-components/processor/lsmintervalproce
561561
github.com/elastic/opentelemetry-collector-components/processor/lsmintervalprocessor v0.8.0/go.mod h1:uQHpGpKwGHhdO5fm2hx1mthiPMiScmFOp5XNwD0EqVw=
562562
github.com/elastic/opentelemetry-lib v0.21.0 h1:aktZQ6hocz/yVMOikDrdcjWtl/qcK/AfMBundZJTCcQ=
563563
github.com/elastic/opentelemetry-lib v0.21.0/go.mod h1:mNcdHi6ivTn5w4bE18as43gzKt2rVmK4HCeJZ9JmFXk=
564-
github.com/elastic/pkcs8 v1.0.0 h1:HhitlUKxhN288kcNcYkjW6/ouvuwJWd9ioxpjnD9jVA=
565-
github.com/elastic/pkcs8 v1.0.0/go.mod h1:ipsZToJfq1MxclVTwpG7U/bgeDtf+0HkUiOxebk95+0=
566564
github.com/elastic/sarama v1.19.1-0.20250603175145-7672917f26b6 h1:2COw7kzXkIyS4hKNUl5qw0KolrwncrY4VVNpngVNo8I=
567565
github.com/elastic/sarama v1.19.1-0.20250603175145-7672917f26b6/go.mod h1:Ua/oXS4NS+U/pp/urxgzEGWd1MvocHA+yd4Bu4+Eb80=
568566
github.com/elazarl/goproxy v0.0.0-20240909085733-6741dbfc16a1 h1:g7YUigN4dW2+zpdusdTTghZ+5Py3BaUMAStvL8Nk+FY=
@@ -1903,7 +1901,6 @@ golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58
19031901
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
19041902
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
19051903
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
1906-
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
19071904
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
19081905
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
19091906
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
@@ -2027,7 +2024,6 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
20272024
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
20282025
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
20292026
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
2030-
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
20312027
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
20322028
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
20332029
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
@@ -2043,7 +2039,6 @@ golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
20432039
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
20442040
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
20452041
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
2046-
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
20472042
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
20482043
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
20492044
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=

magefile.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2246,7 +2246,9 @@ func (Integration) Local(ctx context.Context, testName string) error {
22462246
// run the integration tests but only run test that can run locally
22472247
params := devtools.DefaultGoTestIntegrationArgs()
22482248
params.Tags = append(params.Tags, "local")
2249-
params.Packages = []string{"github.com/elastic/elastic-agent/testing/integration"}
2249+
params.Packages = []string{
2250+
"github.com/elastic/elastic-agent/testing/integration/...",
2251+
}
22502252

22512253
var goTestFlags []string
22522254
rawTestFlags := os.Getenv("GOTEST_FLAGS")

testing/integration/ess/otel_test.go

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"github.com/stretchr/testify/assert"
2727
"github.com/stretchr/testify/require"
2828

29+
"github.com/elastic/elastic-agent-libs/testing/fs"
30+
2931
"github.com/elastic/elastic-agent-libs/mapstr"
3032
"github.com/elastic/elastic-agent-libs/testing/estools"
3133
"github.com/elastic/elastic-agent-libs/transport/tlscommontest"
@@ -463,6 +465,12 @@ exporters:
463465
elasticsearch:
464466
api_key: {{.ESApiKey}}
465467
endpoint: {{.ESEndpoint}}
468+
logs_index: {{.TestId}}
469+
sending_queue:
470+
wait_for_result: true
471+
block_on_overflow: true
472+
enabled: true
473+
queue_size: 10000
466474
mapping:
467475
mode: none
468476
@@ -489,6 +497,13 @@ service:
489497
- resource/add-test-id
490498
receivers:
491499
- filelog
500+
telemetry:
501+
logs:
502+
level: DEBUG
503+
encoding: json
504+
disable_stacktrace: true
505+
output_paths:
506+
- {{.OTelLogFile}}
492507
`
493508

494509
func TestOtelLogsIngestion(t *testing.T) {
@@ -506,8 +521,9 @@ func TestOtelLogsIngestion(t *testing.T) {
506521
// Prepare the OTel config.
507522
testId := info.Namespace
508523

509-
tempDir := t.TempDir()
524+
tempDir := fs.TempDir(t, "..", "..", "..", "build")
510525
inputFilePath := filepath.Join(tempDir, "input.log")
526+
otelLogFilePath := filepath.Join(tempDir, "elastic-agent.ndjson")
511527

512528
esHost, err := integration.GetESHost()
513529
require.NoError(t, err, "failed to get ES host")
@@ -524,6 +540,7 @@ func TestOtelLogsIngestion(t *testing.T) {
524540
logsIngestionConfig = strings.ReplaceAll(logsIngestionConfig, "{{.ESEndpoint}}", esHost)
525541
logsIngestionConfig = strings.ReplaceAll(logsIngestionConfig, "{{.InputFilePath}}", inputFilePath)
526542
logsIngestionConfig = strings.ReplaceAll(logsIngestionConfig, "{{.TestId}}", testId)
543+
logsIngestionConfig = strings.ReplaceAll(logsIngestionConfig, "{{.OTelLogFile}}", otelLogFilePath)
527544

528545
cfgFilePath := filepath.Join(tempDir, "otel.yml")
529546
require.NoError(t, os.WriteFile(cfgFilePath, []byte(logsIngestionConfig), 0o600))
@@ -557,26 +574,30 @@ func TestOtelLogsIngestion(t *testing.T) {
557574
require.NoError(t, err)
558575
}
559576
inputFile.Close()
560-
t.Cleanup(func() {
561-
_ = os.Remove(inputFilePath)
562-
})
563577

564-
actualHits := &struct{ Hits int }{}
565-
require.Eventually(t,
566-
func() bool {
567-
findCtx, findCancel := context.WithTimeout(context.Background(), 10*time.Second)
578+
// It takes about 45s to ingest all files on local tests,
579+
// so set the timeout to 5min to be on the safe side.
580+
require.EventuallyWithT(
581+
t,
582+
func(c *assert.CollectT) {
583+
findCtx, findCancel := context.WithTimeout(t.Context(), 10*time.Second)
568584
defer findCancel()
569585

570-
docs, err := estools.GetLogsForIndexWithContext(findCtx, esClient, ".ds-logs-generic-default*", map[string]interface{}{
571-
"Resource.test.id": testId,
572-
})
573-
require.NoError(t, err)
574-
575-
actualHits.Hits = docs.Hits.Total.Value
576-
return actualHits.Hits == logsCount
586+
docs, err := estools.GetAllLogsForIndexWithContext(
587+
findCtx,
588+
esClient,
589+
testId)
590+
require.NoError(c, err)
591+
require.Equalf(
592+
c,
593+
logsCount,
594+
docs.Hits.Total.Value,
595+
"expecting %d events",
596+
logsCount)
577597
},
578-
2*time.Minute, 1*time.Second,
579-
"Expected %v logs, got %v", logsCount, actualHits)
598+
5*time.Minute,
599+
time.Second,
600+
"did not find the expected number of events")
580601

581602
cancel()
582603
fixtureWg.Wait()

0 commit comments

Comments
 (0)