Skip to content

Commit 826a574

Browse files
Merge branch 'main' into fix/s3-poller-backup-delete
2 parents c973938 + ede7c6a commit 826a574

26 files changed

Lines changed: 1738 additions & 603 deletions

File tree

.github/workflows/fragment-in-pr.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: fragment-in-pr
33
on:
44
pull_request:
55
types: [ labeled, unlabeled, opened, reopened, synchronize ]
6+
permissions:
7+
contents: read
8+
69
jobs:
710
fragments:
811
if: "!contains(github.event.pull_request.labels.*.name, 'skip-changelog') && !contains(github.event.pull_request.labels.*.name, 'backport')"

.github/workflows/release-notes.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ on:
1212
type: string
1313
required: true
1414

15+
permissions:
16+
contents: read
17+
1518
jobs:
1619
build-release-notes:
1720
uses: elastic/elastic-agent-changelog-tool/.github/workflows/generate-release-notes.yml@main

.mergify.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,11 @@ pull_request_rules:
357357
backport:
358358
branches:
359359
- "9.4"
360+
- name: backport patches to 9.5 branch
361+
conditions:
362+
- merged
363+
- label=backport-9.5
364+
actions:
365+
backport:
366+
branches:
367+
- "9.5"

NOTICE.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17142,11 +17142,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1714217142

1714317143
--------------------------------------------------------------------------------
1714417144
Dependency : github.com/elastic/gopacket
17145-
Version: v1.1.20-0.20241002174017-e8c5fda595e6
17145+
Version: v1.1.20-0.20260708143104-cfe2cc0f0cc7
1714617146
Licence type (autodetected): BSD-3-Clause
1714717147
--------------------------------------------------------------------------------
1714817148

17149-
Contents of probable licence file $GOMODCACHE/github.com/elastic/gopacket@v1.1.20-0.20241002174017-e8c5fda595e6/LICENSE:
17149+
Contents of probable licence file $GOMODCACHE/github.com/elastic/gopacket@v1.1.20-0.20260708143104-cfe2cc0f0cc7/LICENSE:
1715017150

1715117151
Copyright (c) 2012 Google, Inc. All rights reserved.
1715217152
Copyright (c) 2009-2011 Andreas Krennmair. All rights reserved.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# REQUIRED
2+
# Kind can be one of:
3+
# - breaking-change: a change to previously-documented behavior
4+
# - deprecation: functionality that is being removed in a later release
5+
# - bug-fix: fixes a problem in a previous version
6+
# - enhancement: extends functionality but does not break or fix existing behavior
7+
# - feature: new functionality
8+
# - known-issue: problems that we are aware of in a given version
9+
# - security: impacts on the security of a product or a user’s deployment.
10+
# - upgrade: important information for someone upgrading from a prior version
11+
# - other: does not fit into any of the other categories
12+
kind: bug-fix
13+
14+
# REQUIRED for all kinds
15+
# Change summary; a 80ish characters long description of the change.
16+
summary: Load the Npcap wpcap.dll lazily to avoid blocking Npcap upgrades on Windows
17+
18+
# REQUIRED for breaking-change, deprecation, known-issue
19+
# Long description; in case the summary is not enough to describe the change
20+
# this field accommodate a description without length limits.
21+
description: >
22+
On Windows, importing gopacket/pcap loaded wpcap.dll in the package init, so
23+
every Beat that links Packetbeat's capture code held the DLL open even when it
24+
never captured traffic. This stopped Packetbeat from replacing wpcap.dll while
25+
upgrading Npcap and the install failed. The DLL is now loaded lazily, only when
26+
Packetbeat needs it.
27+
28+
# REQUIRED for breaking-change, deprecation, known-issue
29+
# impact:
30+
31+
# REQUIRED for breaking-change, deprecation, known-issue
32+
# action:
33+
34+
# REQUIRED for all kinds
35+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
36+
component: packetbeat
37+
38+
# AUTOMATED
39+
# OPTIONAL to manually add other PR URLs
40+
# PR URL: A link the PR that added the changeset.
41+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
42+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
43+
# Please provide it if you are adding a fragment for a different PR.
44+
# pr: https://github.com/owner/repo/1234
45+
46+
# AUTOMATED
47+
# OPTIONAL to manually add other issue URLs
48+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
49+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
50+
issue: https://github.com/elastic/elastic-agent/issues/14517
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# REQUIRED
2+
# Kind can be one of:
3+
# - breaking-change: a change to previously-documented behavior
4+
# - deprecation: functionality that is being removed in a later release
5+
# - bug-fix: fixes a problem in a previous version
6+
# - enhancement: extends functionality but does not break or fix existing behavior
7+
# - feature: new functionality
8+
# - known-issue: problems that we are aware of in a given version
9+
# - security: impacts on the security of a product or a user’s deployment.
10+
# - upgrade: important information for someone upgrading from a prior version
11+
# - other: does not fit into any of the other categories
12+
kind: bug-fix
13+
14+
# REQUIRED for all kinds
15+
# Change summary; a 80ish characters long description of the change.
16+
summary: Synchronize Filebeat Run and Shutdown functions.
17+
18+
# REQUIRED for breaking-change, deprecation, known-issue
19+
# Long description; in case the summary is not enough to describe the change
20+
# this field accommodate a description without length limits.
21+
# description:
22+
23+
# REQUIRED for breaking-change, deprecation, known-issue
24+
# impact:
25+
26+
# REQUIRED for breaking-change, deprecation, known-issue
27+
# action:
28+
29+
# REQUIRED for all kinds
30+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
31+
component: filebeat
32+
33+
# AUTOMATED
34+
# OPTIONAL to manually add other PR URLs
35+
# PR URL: A link the PR that added the changeset.
36+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
37+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
38+
# Please provide it if you are adding a fragment for a different PR.
39+
pr: https://github.com/elastic/beats/pull/51800
40+
41+
# AUTOMATED
42+
# OPTIONAL to manually add other issue URLs
43+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
44+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
45+
# issue: https://github.com/owner/repo/1234

filebeat/beater/filebeat.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type Filebeat struct {
8383
pipeline beat.PipelineConnector
8484
logger *logp.Logger
8585
otelStatusFactoryWrapper func(cfgfile.RunnerFactory) cfgfile.RunnerFactory
86+
runReady *closeOnce
8687
}
8788

8889
type PluginFactory func(beat.Info, statestore.States) []v2.Plugin
@@ -174,6 +175,7 @@ func newBeater(b *beat.Beat, plugins PluginFactory, rawConfig *conf.C) (beat.Bea
174175

175176
fb := &Filebeat{
176177
done: make(chan struct{}),
178+
runReady: &closeOnce{ch: make(chan struct{})},
177179
config: &config,
178180
moduleRegistry: moduleRegistry,
179181
pluginFactory: plugins,
@@ -270,6 +272,9 @@ func (fb *Filebeat) loadModulesPipelines(b *beat.Beat) error {
270272
func (fb *Filebeat) Run(b *beat.Beat) error {
271273
var err error
272274
config := fb.config
275+
// Close runReady so that Shutdown doesn't have to wait no
276+
// matter how we exit from Run.
277+
defer fb.runReady.Close()
273278

274279
if b.Manager != nil {
275280
b.Manager.RegisterDiagnosticHook("input_metrics", "Metrics from active inputs.",
@@ -530,6 +535,8 @@ func (fb *Filebeat) Run(b *beat.Beat) error {
530535

531536
// Add done channel to wait for shutdown signal
532537
waitFinished.AddChan(fb.done)
538+
// Safe for Shutdown to be called
539+
fb.runReady.Close()
533540
waitFinished.Wait()
534541

535542
// Stop reloadable lists, autodiscover -> Stop crawler -> stop inputs -> stop harvesters.
@@ -588,9 +595,24 @@ func (fb *Filebeat) Run(b *beat.Beat) error {
588595

589596
// Stop is called on exit to stop the crawling, spooling and registration processes.
590597
func (fb *Filebeat) Stop() {
598+
fb.StopWithContext(context.Background())
599+
}
600+
601+
// StopWithContext is like Stop but respects ctx when waiting for Run to reach
602+
// its ready state, so the caller's deadline is not consumed by the wait.
603+
func (fb *Filebeat) StopWithContext(ctx context.Context) {
591604
fb.logger.Info("Stopping filebeat")
592605

593-
// Stop Filebeat
606+
// Wait for Run to reach waitFinished.Wait() before closing done, so that
607+
// Stop is never delivered before the beater is ready to handle it.
608+
select {
609+
case <-fb.runReady.ch:
610+
case <-ctx.Done():
611+
fb.logger.Warn("Context cancelled waiting for Run to reach ready state; stopping anyway")
612+
case <-time.After(5 * time.Second):
613+
fb.logger.Warn("Timed out waiting for Run to reach ready state; stopping anyway")
614+
}
615+
594616
fb.stopOnce.Do(func() { close(fb.done) })
595617
}
596618

@@ -605,3 +627,14 @@ func newPipelineLoaderFactory(ctx context.Context, esConfig *conf.C, info beat.I
605627
}
606628
return pipelineLoaderFactory
607629
}
630+
631+
type closeOnce struct {
632+
ch chan struct{}
633+
once sync.Once
634+
}
635+
636+
func (coc *closeOnce) Close() {
637+
coc.once.Do(func() {
638+
close(coc.ch)
639+
})
640+
}

filebeat/beater/stop_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package beater
19+
20+
import (
21+
"testing"
22+
"time"
23+
24+
"github.com/elastic/elastic-agent-libs/logp"
25+
)
26+
27+
// TestStopWaitsForRunReady proves that Stop does not close the done channel
28+
// until Run has closed runReady (i.e., reached waitFinished.Wait).
29+
// This guards against a race where the OTel collector calls Shutdown before
30+
// the beat's Run goroutine has initialised its shutdown-signal machinery.
31+
func TestStopWaitsForRunReady(t *testing.T) {
32+
fb := &Filebeat{
33+
done: make(chan struct{}),
34+
runReady: &closeOnce{ch: make(chan struct{})},
35+
logger: logp.NewNopLogger(),
36+
}
37+
38+
stopDone := make(chan struct{})
39+
go func() {
40+
defer close(stopDone)
41+
fb.Stop()
42+
}()
43+
44+
// done must still be open: Stop is waiting for runReady to be closed.
45+
select {
46+
case <-fb.done:
47+
t.Fatal("Stop closed done before Run closed runReady")
48+
default:
49+
}
50+
51+
// Simulate Run() reaching the waitFinished.Wait() call.
52+
fb.runReady.Close()
53+
54+
select {
55+
case <-fb.done:
56+
case <-time.After(500 * time.Millisecond):
57+
t.Fatal("Stop did not close done after runReady was closed")
58+
}
59+
60+
<-stopDone
61+
}

0 commit comments

Comments
 (0)