-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> * use v8 es version * check for existence of events --------- Co-authored-by: Denis <[email protected]> (cherry picked from commit e22f933) Co-authored-by: Khushi Jain <[email protected]>
- Loading branch information
1 parent
c2a6a48
commit 12bca23
Showing
4 changed files
with
121 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13406,11 +13406,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/[email protected].0/LICENSE: | ||
Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected].1/LICENSE: | ||
|
||
Apache License | ||
Version 2.0, January 2004 | ||
|
@@ -14039,11 +14039,11 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected] | |
|
||
-------------------------------------------------------------------------------- | ||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |