Skip to content

Commit

Permalink
[filebeat] Add E2E testing for filebeat in otel mode (#42226)
Browse files Browse the repository at this point in the history
* [filebeat] Add E2E testing for filebeat in otel mode

- Add E2E test for filebeat and elasticsearch

Co-authored-by: Denis <denis@rdner.de>

* use v8 es version

* check for existence of events

---------

Co-authored-by: Denis <denis@rdner.de>
  • Loading branch information
khushijain21 and rdner authored Jan 9, 2025
1 parent 04f1c4a commit e22f933
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 10 deletions.
8 changes: 4 additions & 4 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12488,11 +12488,11 @@ SOFTWARE

--------------------------------------------------------------------------------
Dependency : github.com/elastic/elastic-agent-libs
Version: v0.18.0
Version: v0.18.1
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.18.0/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.18.1/LICENSE:

Apache License
Version 2.0, January 2004
Expand Down Expand Up @@ -13121,11 +13121,11 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/go-concert@v0.3

--------------------------------------------------------------------------------
Dependency : github.com/elastic/go-elasticsearch/v8
Version: v8.14.0
Version: v8.17.0
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/go-elasticsearch/v8@v8.14.0/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/elastic/go-elasticsearch/v8@v8.17.0/LICENSE:

Apache License
Version 2.0, January 2004
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ require (
github.com/elastic/bayeux v1.0.5
github.com/elastic/ebpfevents v0.6.0
github.com/elastic/elastic-agent-autodiscover v0.9.0
github.com/elastic/elastic-agent-libs v0.18.0
github.com/elastic/elastic-agent-libs v0.18.1
github.com/elastic/elastic-agent-system-metrics v0.11.7
github.com/elastic/go-elasticsearch/v8 v8.14.0
github.com/elastic/go-elasticsearch/v8 v8.17.0
github.com/elastic/go-quark v0.2.0
github.com/elastic/go-sfdc v0.0.0-20241010131323-8e176480d727
github.com/elastic/mito v1.16.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0
github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4=
github.com/elastic/elastic-agent-client/v7 v7.15.0 h1:nDB7v8TBoNuD6IIzC3z7Q0y+7bMgXoT2DsHfolO2CHE=
github.com/elastic/elastic-agent-client/v7 v7.15.0/go.mod h1:6h+f9QdIr3GO2ODC0Y8+aEXRwzbA5W4eV4dd/67z7nI=
github.com/elastic/elastic-agent-libs v0.18.0 h1:PKG1StgHu2MfOwOryGuAVgNZlZXyvVSDw3SvLUfel+w=
github.com/elastic/elastic-agent-libs v0.18.0/go.mod h1:5CR02awPrBr+tfmjBBK+JI+dMmHNQjpVY24J0wjbC7M=
github.com/elastic/elastic-agent-libs v0.18.1 h1:dE6jf/D9bP8eRMQsV7KKpKV/G8zQzwMFBTj1w4e716c=
github.com/elastic/elastic-agent-libs v0.18.1/go.mod h1:rWdyrrAFzZwgNNi41Tsqhlt2c2GdXWhCEwcsnqISJ2U=
github.com/elastic/elastic-agent-system-metrics v0.11.7 h1:1xm2okCM0eQZ4jivZgUFSlt6HAn/nPgKB/Fj8eLG6mY=
github.com/elastic/elastic-agent-system-metrics v0.11.7/go.mod h1:nzkrGajQA29YNcfP62gfzhxX9an3/xdQ3RmfQNw9YTI=
github.com/elastic/elastic-transport-go/v8 v8.6.0 h1:Y2S/FBjx1LlCv5m6pWAF2kDJAHoSjSRSJCApolgfthA=
Expand All @@ -358,8 +358,8 @@ github.com/elastic/go-docappender/v2 v2.3.0 h1:Vr+l36jM+sE/LHp0JFxSIbHlWTSk8CpBb
github.com/elastic/go-docappender/v2 v2.3.0/go.mod h1:VNWgXUE9HX1G6W6ON8dOs/KdH8aCxXir/fxxcfrnov4=
github.com/elastic/go-elasticsearch/v7 v7.17.10 h1:TCQ8i4PmIJuBunvBS6bwT2ybzVFxxUhhltAs3Gyu1yo=
github.com/elastic/go-elasticsearch/v7 v7.17.10/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4=
github.com/elastic/go-elasticsearch/v8 v8.14.0 h1:1ywU8WFReLLcxE1WJqii3hTtbPUE2hc38ZK/j4mMFow=
github.com/elastic/go-elasticsearch/v8 v8.14.0/go.mod h1:WRvnlGkSuZyp83M2U8El/LGXpCjYLrvlkSgkAH4O5I4=
github.com/elastic/go-elasticsearch/v8 v8.17.0 h1:e9cWksE/Fr7urDRmGPGp47Nsp4/mvNOrU8As1l2HQQ0=
github.com/elastic/go-elasticsearch/v8 v8.17.0/go.mod h1:lGMlgKIbYoRvay3xWBeKahAiJOgmFDsjZC39nmO3H64=
github.com/elastic/go-libaudit/v2 v2.6.1 h1:eN7tobGizmB+OJpCuG7gvPX7Nxni//H47uvMDXlMrI0=
github.com/elastic/go-libaudit/v2 v2.6.1/go.mod h1:8205nkf2oSrXFlO4H5j8/cyVMoSF3Y7jt+FjgS4ubQU=
github.com/elastic/go-licenser v0.4.2 h1:bPbGm8bUd8rxzSswFOqvQh1dAkKGkgAmrPxbUi+Y9+A=
Expand Down
111 changes: 111 additions & 0 deletions x-pack/filebeat/tests/integration/otel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build integration && !agentbeat

package integration

import (
"context"
"crypto/tls"
"fmt"
"net/http"
"os"
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/elastic/beats/v7/libbeat/tests/integration"
"github.com/elastic/elastic-agent-libs/testing/estools"
"github.com/elastic/go-elasticsearch/v8"
)

var beatsCfgFile = `
filebeat.inputs:
- type: filestream
id: filestream-input-id
enabled: true
file_identity.native: ~
prospector.scanner.fingerprint.enabled: false
paths:
- %s
output:
elasticsearch:
hosts:
- localhost:9200
protocol: http
username: admin
password: testing
index: %s
queue.mem.flush.timeout: 0s
`

func TestFilebeatOTelE2E(t *testing.T) {
integration.EnsureESIsRunning(t)

filebeatOTel := integration.NewBeat(
t,
"filebeat-otel",
"../../filebeat.test",
"otel",
)

logFilePath := filepath.Join(filebeatOTel.TempDir(), "log.log")
filebeatOTel.WriteConfigFile(fmt.Sprintf(beatsCfgFile, logFilePath, "logs-integration-default"))

logFile, err := os.Create(logFilePath)
if err != nil {
t.Fatalf("could not create file '%s': %s", logFilePath, err)
}

numEvents := 5

// write events to log file
for i := 0; i < numEvents; i++ {
msg := fmt.Sprintf("Line %d", i)
_, err = logFile.Write([]byte(msg + "\n"))
require.NoErrorf(t, err, "failed to write line %d to temp file", i)
}

if err := logFile.Sync(); err != nil {
t.Fatalf("could not sync log file '%s': %s", logFilePath, err)
}
if err := logFile.Close(); err != nil {
t.Fatalf("could not close log file '%s': %s", logFilePath, err)
}

filebeatOTel.Start()

// prepare to query ES
esCfg := elasticsearch.Config{
Addresses: []string{"http://localhost:9200"},
Username: "admin",
Password: "testing",
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, //nolint:gosec // this is only for testing
},
},
}
es, err := elasticsearch.NewClient(esCfg)
require.NoError(t, err)

actualHits := &struct{ Hits int }{}
// wait for logs to be published
require.Eventually(t,
func() bool {
findCtx, findCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer findCancel()

OTelDocs, err := estools.GetAllLogsForIndexWithContext(findCtx, es, ".ds-logs-integration-default*")
require.NoError(t, err)

actualHits.Hits = OTelDocs.Hits.Total.Value
return actualHits.Hits == numEvents
},
2*time.Minute, 1*time.Second, numEvents, actualHits.Hits)

}

0 comments on commit e22f933

Please sign in to comment.