diff --git a/NOTICE.txt b/NOTICE.txt index 938e149d3818..3c501680b0a9 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -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 diff --git a/go.mod b/go.mod index 59a0ed9ca111..31210868be1a 100644 --- a/go.mod +++ b/go.mod @@ -177,7 +177,7 @@ 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.17.0 github.com/elastic/go-quark v0.2.0 diff --git a/go.sum b/go.sum index 6b7848f82b4c..bb0f55c51a7d 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/x-pack/filebeat/tests/integration/otel_test.go b/x-pack/filebeat/tests/integration/otel_test.go new file mode 100644 index 000000000000..785e9d151dbf --- /dev/null +++ b/x-pack/filebeat/tests/integration/otel_test.go @@ -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) + +}