From 48e7e3a4d185b6db5c0b5e218f15853e2b0498db Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 08:49:32 +0100 Subject: [PATCH] re-enable otel subcommand on Windows (#6068) (#6156) * move processing windows events earlier in the boot process * add Windows to otel integration tests (cherry picked from commit 8e83ce0a06ec222f6b7e17886af3bd02308cdc1d) Co-authored-by: Lee E Hinman <57081003+leehinman@users.noreply.github.com> Co-authored-by: Pierre HILBERT --- ...-re-enable-otel-subcommand-on-Windows.yaml | 32 +++++++++++++++++++ internal/pkg/agent/cmd/otel.go | 2 +- internal/pkg/agent/cmd/run.go | 24 +++++++------- internal/pkg/agent/cmd/validate_test.go | 2 -- testing/integration/otel_test.go | 8 ++--- 5 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 changelog/fragments/1731962301-re-enable-otel-subcommand-on-Windows.yaml diff --git a/changelog/fragments/1731962301-re-enable-otel-subcommand-on-Windows.yaml b/changelog/fragments/1731962301-re-enable-otel-subcommand-on-Windows.yaml new file mode 100644 index 00000000000..9fc7207dd3e --- /dev/null +++ b/changelog/fragments/1731962301-re-enable-otel-subcommand-on-Windows.yaml @@ -0,0 +1,32 @@ +# Kind can be one of: +# - breaking-change: a change to previously-documented behavior +# - deprecation: functionality that is being removed in a later release +# - bug-fix: fixes a problem in a previous version +# - enhancement: extends functionality but does not break or fix existing behavior +# - feature: new functionality +# - known-issue: problems that we are aware of in a given version +# - security: impacts on the security of a product or a user’s deployment. +# - upgrade: important information for someone upgrading from a prior version +# - other: does not fit into any of the other categories +kind: enhancement + +# Change summary; a 80ish characters long description of the change. +summary: re-enable otel subcommand on Windows + +# Long description; in case the summary is not enough to describe the change +# this field accommodate a description without length limits. +# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment. +#description: + +# Affected component; a word indicating the component this changeset affects. +component: elastic-agent + +# PR URL; optional; the PR number that added the changeset. +# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. +# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. +# Please provide it if you are adding a fragment for a different PR. +pr: https://github.com/elastic/elastic-agent/pull/6068 + +# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of). +# If not present is automatically filled by the tooling with the issue linked to the PR number. +issue: https://github.com/elastic/elastic-agent/issues/4976 diff --git a/internal/pkg/agent/cmd/otel.go b/internal/pkg/agent/cmd/otel.go index 3ce0d3db269..36788b265bf 100644 --- a/internal/pkg/agent/cmd/otel.go +++ b/internal/pkg/agent/cmd/otel.go @@ -71,7 +71,7 @@ func runCollector(cmdCtx context.Context, configFiles []string) error { stop := make(chan bool) ctx, cancel := context.WithCancel(cmdCtx) - var stopCollector = func() { + stopCollector := func() { close(stop) } diff --git a/internal/pkg/agent/cmd/run.go b/internal/pkg/agent/cmd/run.go index 7cdf1e9db66..21e4c19a28e 100644 --- a/internal/pkg/agent/cmd/run.go +++ b/internal/pkg/agent/cmd/run.go @@ -129,18 +129,6 @@ func run(override cfgOverrider, testingMode bool, fleetInitTimeout time.Duration service.WaitExecutionDone() }() - if err := handleUpgrade(); err != nil { - return fmt.Errorf("error checking for and handling upgrade: %w", err) - } - - locker := filelock.NewAppLocker(paths.Data(), paths.AgentLockFileName) - if err := locker.TryLock(); err != nil { - return err - } - defer func() { - _ = locker.Unlock() - }() - service.BeforeRun() defer service.Cleanup() @@ -154,6 +142,18 @@ func run(override cfgOverrider, testingMode bool, fleetInitTimeout time.Duration defer cancel() go service.ProcessWindowsControlEvents(stopBeat) + if err := handleUpgrade(); err != nil { + return fmt.Errorf("error checking for and handling upgrade: %w", err) + } + + locker := filelock.NewAppLocker(paths.Data(), paths.AgentLockFileName) + if err := locker.TryLock(); err != nil { + return err + } + defer func() { + _ = locker.Unlock() + }() + return runElasticAgent(ctx, cancel, override, stop, testingMode, fleetInitTimeout, modifiers...) } diff --git a/internal/pkg/agent/cmd/validate_test.go b/internal/pkg/agent/cmd/validate_test.go index 2ca2a653dff..ee5066c3c18 100644 --- a/internal/pkg/agent/cmd/validate_test.go +++ b/internal/pkg/agent/cmd/validate_test.go @@ -2,8 +2,6 @@ // or more contributor license agreements. Licensed under the Elastic License 2.0; // you may not use this file except in compliance with the Elastic License 2.0. -//go:build !windows - package cmd import ( diff --git a/testing/integration/otel_test.go b/testing/integration/otel_test.go index 3ff827b164e..4c68534bfa7 100644 --- a/testing/integration/otel_test.go +++ b/testing/integration/otel_test.go @@ -83,7 +83,7 @@ func TestOtelFileProcessing(t *testing.T) { Group: Default, Local: true, OS: []define.OS{ - // input path missing on windows + {Type: define.Windows}, {Type: define.Linux}, {Type: define.Darwin}, }, @@ -428,7 +428,7 @@ func TestOtelLogsIngestion(t *testing.T) { Group: Default, Local: true, OS: []define.OS{ - // input path missing on windows + {Type: define.Windows}, {Type: define.Linux}, {Type: define.Darwin}, }, @@ -725,7 +725,7 @@ func TestFileBeatReceiver(t *testing.T) { Group: Default, Local: true, OS: []define.OS{ - // {Type: define.Windows}, we don't support otel on Windows yet + {Type: define.Windows}, {Type: define.Linux}, {Type: define.Darwin}, }, @@ -830,7 +830,7 @@ func TestOtelFBReceiverE2E(t *testing.T) { Group: Default, Local: true, OS: []define.OS{ - // {Type: define.Windows}, we don't support otel on Windows yet + {Type: define.Windows}, {Type: define.Linux}, {Type: define.Darwin}, },