Skip to content

Commit abb9226

Browse files
committed
Merge remote-tracking branch 'upstream/main' into tests/ephemeral-ports-toctou
Resolve conflict in otel_filebeat_input_test.go: adopt upstream's refactor that factors the shared `service:` block into the otelElasticsearchServiceYAML constant, and drop the now-redundant `telemetry.metrics.level: none` block from that constant. Metrics-off is applied centrally in oteltestcol.New (merged on top of every test config), so the per-config block this branch removed in 6b02d5e must stay removed in the shared helper too.
2 parents 32240cc + b6e6fc1 commit abb9226

27 files changed

Lines changed: 859 additions & 654 deletions

NOTICE.txt

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

1079910799
--------------------------------------------------------------------------------
1080010800
Dependency : github.com/elastic/elastic-agent-libs
10801-
Version: v0.45.0
10801+
Version: v0.46.1
1080210802
Licence type (autodetected): Apache-2.0
1080310803
--------------------------------------------------------------------------------
1080410804

10805-
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.45.0/LICENSE:
10805+
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.46.1/LICENSE:
1080610806

1080710807
Apache License
1080810808
Version 2.0, January 2004
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: bug-fix
2+
3+
summary: Prevent statestore startup failure when meta.json is left empty after an unclean shutdown
4+
5+
component: libbeat
6+
7+
pr: https://github.com/elastic/beats/pull/51897
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: bug-fix
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: update elastic-agent-libs to v0.46.1
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
description: Fixed an issue where malformed TLS keys could be printed in the error logs during loading failures.
20+
21+
# Affected component; a word indicating the component this changeset affects.
22+
component: all
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
pr: https://github.com/elastic/beats/pull/51921
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
#issue: https://github.com/owner/repo/1234

filebeat/beater/filebeat.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ func (fb *Filebeat) Run(b *beat.Beat) error {
312312
// Start the check-in loop, so Filebeat can respond to Elastic Agent,
313313
// but it won't start any inputs/output
314314
if err := b.Manager.PreInit(); err != nil {
315+
fb.runReady.Close()
315316
return err
316317
}
317318

filebeat/beater/stop_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,61 @@
1818
package beater
1919

2020
import (
21+
"errors"
2122
"testing"
2223
"time"
2324

25+
"github.com/stretchr/testify/require"
26+
27+
"github.com/elastic/beats/v7/filebeat/fileset"
28+
"github.com/elastic/beats/v7/libbeat/beat"
29+
"github.com/elastic/beats/v7/libbeat/beatmonitoring"
30+
"github.com/elastic/beats/v7/libbeat/management"
2431
"github.com/elastic/elastic-agent-libs/logp"
2532
)
2633

34+
// TestRunClosesRunReadyOnPreInitFailure guards against the regression in
35+
// commit 00068f7 where the defer fb.runReady.Close() was placed after the
36+
// PreInit call, leaving runReady unclosed when PreInit fails. An unclosed
37+
// runReady causes StopWithContext to wait the full five-second timeout.
38+
func TestRunClosesRunReadyOnPreInitFailure(t *testing.T) {
39+
preInitErr := errors.New("preinit failed")
40+
fb := &Filebeat{
41+
done: make(chan struct{}),
42+
runReady: &closeOnce{ch: make(chan struct{})},
43+
logger: logp.NewNopLogger(),
44+
moduleRegistry: new(fileset.ModuleRegistry),
45+
}
46+
b := &beat.Beat{
47+
Info: beat.Info{Logger: logp.NewNopLogger()},
48+
Manager: &preinitFailManager{err: preInitErr},
49+
Monitoring: beatmonitoring.NewMonitoring(),
50+
}
51+
52+
err := fb.Run(b)
53+
require.ErrorIs(t, err, preInitErr)
54+
55+
select {
56+
case <-fb.runReady.ch:
57+
// runReady was closed — StopWithContext will not block
58+
default:
59+
t.Fatal("runReady was not closed after PreInit failure; StopWithContext would wait five seconds")
60+
}
61+
}
62+
63+
// preinitFailManager is a management.Manager stub whose PreInit returns an
64+
// error. Only the methods called by Run before PreInit are implemented; any
65+
// other call panics, catching unexpected code paths during the test.
66+
type preinitFailManager struct {
67+
management.Manager // zero-valued; panics on any unimplemented method
68+
err error
69+
}
70+
71+
func (m *preinitFailManager) Enabled() bool { return true }
72+
func (m *preinitFailManager) PreInit() error { return m.err }
73+
func (m *preinitFailManager) RegisterDiagnosticHook(_, _, _, _ string, _ management.DiagnosticHook) {
74+
}
75+
2776
// TestStopWaitsForRunReady proves that Stop does not close the done channel
2877
// until Run has closed runReady (i.e., reached waitFinished.Wait).
2978
// This guards against a race where the OTel collector calls Shutdown before
File renamed without changes.

filebeat/input/filestream/filestream_test_non_windows.go renamed to filebeat/input/filestream/filestream_nonwindows_test.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,26 @@ package filestream
2222
import (
2323
"context"
2424
"os"
25+
"path/filepath"
2526
"testing"
2627
"time"
2728

2829
"github.com/stretchr/testify/assert"
30+
"github.com/stretchr/testify/require"
2931

3032
"github.com/elastic/elastic-agent-libs/logp/logptest"
3133
)
3234

3335
// these tests are separated as one cannot delete/rename files
3436
// while another process is working with it on Windows
3537
func TestLogFileRenamed(t *testing.T) {
36-
f := createTestLogFile()
38+
f := createTestLogFile(t)
3739
defer f.Close()
3840

3941
renamedFile := f.Name() + ".renamed"
4042

4143
reader, _, err := newFileReader(
42-
logptest.NewTestingLogger(t, ""),
44+
logptest.NewFileLogger(t, filepath.Join("..", "..", "build", "integration-tests")).Logger,
4345
context.TODO(),
4446
f,
4547
readerConfig{},
@@ -57,7 +59,7 @@ func TestLogFileRenamed(t *testing.T) {
5759

5860
buf := make([]byte, 1024)
5961
_, err = reader.Read(buf)
60-
assert.Nil(t, err)
62+
assert.NoError(t, err)
6163

6264
err = os.Rename(f.Name(), renamedFile)
6365
if err != nil {
@@ -71,11 +73,11 @@ func TestLogFileRenamed(t *testing.T) {
7173
}
7274

7375
func TestLogFileRemoved(t *testing.T) {
74-
f := createTestLogFile()
76+
f := createTestLogFile(t)
7577
defer f.Close()
7678

7779
reader, _, err := newFileReader(
78-
logptest.NewTestingLogger(t, ""),
80+
logptest.NewFileLogger(t, filepath.Join("..", "..", "build", "integration-tests")).Logger,
7981
context.TODO(),
8082
f,
8183
readerConfig{},
@@ -93,7 +95,7 @@ func TestLogFileRemoved(t *testing.T) {
9395

9496
buf := make([]byte, 1024)
9597
_, err = reader.Read(buf)
96-
assert.Nil(t, err)
98+
assert.NoError(t, err)
9799

98100
err = os.Remove(f.Name())
99101
if err != nil {
@@ -104,3 +106,16 @@ func TestLogFileRemoved(t *testing.T) {
104106

105107
assert.Equal(t, ErrClosed, err)
106108
}
109+
110+
// createTestLogFile creates a temporary plain-text log file with a few lines of
111+
// content, wrapped as a filestream File ready to be passed to newFileReader.
112+
func createTestLogFile(t *testing.T) File {
113+
t.Helper()
114+
fs := filestream{
115+
readerConfig: readerConfig{BufferSize: 512},
116+
compression: CompressionNone,
117+
}
118+
f, err := fs.newFile(createTestPlainLogFile(t))
119+
require.NoError(t, err, "could not create test log file")
120+
return f
121+
}

0 commit comments

Comments
 (0)