diff --git a/NOTICE.txt b/NOTICE.txt index 185bb5295ac..a1d0b709f88 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -820,11 +820,11 @@ Contents of probable licence file $GOMODCACHE/github.com/dolmen-go/contextio@v0. -------------------------------------------------------------------------------- Dependency : github.com/elastic/elastic-agent-autodiscover -Version: v0.8.1 +Version: v0.8.2 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-autodiscover@v0.8.1/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-autodiscover@v0.8.2/LICENSE: Apache License Version 2.0, January 2004 @@ -1264,11 +1264,11 @@ SOFTWARE -------------------------------------------------------------------------------- Dependency : github.com/elastic/elastic-agent-libs -Version: v0.9.15 +Version: v0.10.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.9.15/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.10.0/LICENSE: Apache License Version 2.0, January 2004 @@ -3040,6 +3040,37 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-------------------------------------------------------------------------------- +Dependency : github.com/go-viper/mapstructure/v2 +Version: v2.1.0 +Licence type (autodetected): MIT +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/github.com/go-viper/mapstructure/v2@v2.1.0/LICENSE: + +The MIT License (MIT) + +Copyright (c) 2013 Mitchell Hashimoto + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + -------------------------------------------------------------------------------- Dependency : github.com/gofrs/flock Version: v0.8.1 @@ -3932,37 +3963,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --------------------------------------------------------------------------------- -Dependency : github.com/mitchellh/mapstructure -Version: v1.5.1-0.20231216201459-8508981c8b6c -Licence type (autodetected): MIT --------------------------------------------------------------------------------- - -Contents of probable licence file $GOMODCACHE/github.com/mitchellh/mapstructure@v1.5.1-0.20231216201459-8508981c8b6c/LICENSE: - -The MIT License (MIT) - -Copyright (c) 2013 Mitchell Hashimoto - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - - -------------------------------------------------------------------------------- Dependency : github.com/oklog/ulid/v2 Version: v2.1.0 @@ -14986,13 +14986,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- Dependency : golang.org/x/sync -Version: v0.7.0 +Version: v0.8.0 Licence type (autodetected): BSD-3-Clause -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/golang.org/x/sync@v0.7.0/LICENSE: +Contents of probable licence file $GOMODCACHE/golang.org/x/sync@v0.8.0/LICENSE: -Copyright (c) 2009 The Go Authors. All rights reserved. +Copyright 2009 The Go Authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -15004,7 +15004,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -21522,11 +21522,11 @@ Contents of probable licence file $GOMODCACHE/github.com/docker/go-connections@v -------------------------------------------------------------------------------- Dependency : github.com/elastic/go-docappender/v2 -Version: v2.2.1 +Version: v2.3.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/go-docappender/v2@v2.2.1/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/elastic/go-docappender/v2@v2.3.0/LICENSE: Apache License Version 2.0, January 2004 @@ -24901,37 +24901,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --------------------------------------------------------------------------------- -Dependency : github.com/go-viper/mapstructure/v2 -Version: v2.0.0 -Licence type (autodetected): MIT --------------------------------------------------------------------------------- - -Contents of probable licence file $GOMODCACHE/github.com/go-viper/mapstructure/v2@v2.0.0/LICENSE: - -The MIT License (MIT) - -Copyright (c) 2013 Mitchell Hashimoto - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - - -------------------------------------------------------------------------------- Dependency : github.com/go-zookeeper/zk Version: v1.0.3 @@ -37996,6 +37965,37 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +-------------------------------------------------------------------------------- +Dependency : github.com/mitchellh/mapstructure +Version: v1.5.1-0.20231216201459-8508981c8b6c +Licence type (autodetected): MIT +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/github.com/mitchellh/mapstructure@v1.5.1-0.20231216201459-8508981c8b6c/LICENSE: + +The MIT License (MIT) + +Copyright (c) 2013 Mitchell Hashimoto + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + -------------------------------------------------------------------------------- Dependency : github.com/mitchellh/reflectwalk Version: v1.0.2 diff --git a/go.mod b/go.mod index 89daa6be726..1072494f558 100644 --- a/go.mod +++ b/go.mod @@ -12,9 +12,9 @@ require ( github.com/docker/docker v26.1.5+incompatible github.com/docker/go-units v0.5.0 github.com/dolmen-go/contextio v0.0.0-20200217195037-68fc5150bcd5 - github.com/elastic/elastic-agent-autodiscover v0.8.1 + github.com/elastic/elastic-agent-autodiscover v0.8.2 github.com/elastic/elastic-agent-client/v7 v7.15.0 - github.com/elastic/elastic-agent-libs v0.9.15 + github.com/elastic/elastic-agent-libs v0.10.0 github.com/elastic/elastic-agent-system-metrics v0.11.1 github.com/elastic/elastic-transport-go/v8 v8.6.0 github.com/elastic/go-elasticsearch/v8 v8.14.0 @@ -25,6 +25,7 @@ require ( github.com/elastic/opentelemetry-collector-components/processor/elasticinframetricsprocessor v0.9.0 github.com/fatih/color v1.16.0 github.com/fsnotify/fsnotify v1.7.0 + github.com/go-viper/mapstructure/v2 v2.1.0 github.com/gofrs/flock v0.8.1 github.com/gofrs/uuid/v5 v5.2.0 github.com/google/go-cmp v0.6.0 @@ -37,7 +38,6 @@ require ( github.com/kardianos/service v1.2.1-0.20210728001519-a323c3813bc7 github.com/magefile/mage v1.15.0 github.com/mitchellh/hashstructure v1.1.0 - github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c github.com/oklog/ulid/v2 v2.1.0 github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension v0.106.1 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver v0.106.1 @@ -64,7 +64,7 @@ require ( go.uber.org/zap v1.27.0 golang.org/x/crypto v0.25.0 golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 - golang.org/x/sync v0.7.0 + golang.org/x/sync v0.8.0 golang.org/x/sys v0.22.0 golang.org/x/term v0.22.0 golang.org/x/text v0.16.0 @@ -157,7 +157,7 @@ require ( github.com/digitalocean/godo v1.117.0 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/go-connections v0.5.0 // indirect - github.com/elastic/go-docappender/v2 v2.2.1 // indirect + github.com/elastic/go-docappender/v2 v2.3.0 // indirect github.com/elastic/go-elasticsearch/v7 v7.17.10 // indirect github.com/elastic/go-structform v0.0.12 // indirect github.com/elastic/go-windows v1.0.2 // indirect @@ -182,7 +182,6 @@ require ( github.com/go-openapi/jsonreference v0.20.4 // indirect github.com/go-openapi/swag v0.22.9 // indirect github.com/go-resty/resty/v2 v2.13.1 // indirect - github.com/go-viper/mapstructure/v2 v2.0.0 // indirect github.com/go-zookeeper/zk v1.0.3 // indirect github.com/gobuffalo/here v0.6.7 // indirect github.com/gobwas/glob v0.2.3 // indirect @@ -255,6 +254,7 @@ require ( github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/moby/docker-image-spec v1.3.1 // indirect github.com/moby/spdystream v0.2.0 // indirect diff --git a/go.sum b/go.sum index 83722951edb..eb7b4438fec 100644 --- a/go.sum +++ b/go.sum @@ -776,18 +776,18 @@ github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3 github.com/dolmen-go/contextio v0.0.0-20200217195037-68fc5150bcd5 h1:BzN9o4IS1Hj+AM5qDggsfMDQGFXau5KagipEFmnyIbc= github.com/dolmen-go/contextio v0.0.0-20200217195037-68fc5150bcd5/go.mod h1:cxc20xI7fOgsFHWgt+PenlDDnMcrvh7Ocuj5hEFIdEk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/elastic/elastic-agent-autodiscover v0.8.1 h1:u6TWqh7wfevu6S4GUq4SIxYBRo4b/P5RZmx/rSvT10A= -github.com/elastic/elastic-agent-autodiscover v0.8.1/go.mod h1:0gzGsaDCAqBfUZjuCqqWsSI60eaZ778A5tQZV72rPV0= +github.com/elastic/elastic-agent-autodiscover v0.8.2 h1:Fs2FhR33AMBPfm5/jz4drVzaEZaqOIHlDBvGtkUZdIk= +github.com/elastic/elastic-agent-autodiscover v0.8.2/go.mod h1:VZnU53EVaFTxR8Xf6YsLN8FHD5DKQzHSPlKax9/4w+o= 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.9.15 h1:WCLtuErafUxczT/rXJa4Vr6mxwC8dgtqMbEq+qWGD4M= -github.com/elastic/elastic-agent-libs v0.9.15/go.mod h1:2VgYxHaeM+cCDBjiS2wbmTvzPGbnlXAtYrlcLefheS8= +github.com/elastic/elastic-agent-libs v0.10.0 h1:W7uvay0UYdLPtauXGsMD8Xfoe4qtcVWQR4icBgf/26Q= +github.com/elastic/elastic-agent-libs v0.10.0/go.mod h1:2VgYxHaeM+cCDBjiS2wbmTvzPGbnlXAtYrlcLefheS8= github.com/elastic/elastic-agent-system-metrics v0.11.1 h1:BxViQHnqxvvi/65rj3mGwG6Eto6ldFCTnuDTUJnakaU= github.com/elastic/elastic-agent-system-metrics v0.11.1/go.mod h1:3QiMu9wTKJFvpCN+5klgGqasTMNKJbgY3xcoN1KQXJk= github.com/elastic/elastic-transport-go/v8 v8.6.0 h1:Y2S/FBjx1LlCv5m6pWAF2kDJAHoSjSRSJCApolgfthA= github.com/elastic/elastic-transport-go/v8 v8.6.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= -github.com/elastic/go-docappender/v2 v2.2.1 h1:SxtmDwTPu4Smu8oggEojE/6QafNL1HJAwLDu7U7hZPA= -github.com/elastic/go-docappender/v2 v2.2.1/go.mod h1:sA82MY9VedS8fMeQBS94xTP77+HlmH9bpXc47+sQDek= +github.com/elastic/go-docappender/v2 v2.3.0 h1:Vr+l36jM+sE/LHp0JFxSIbHlWTSk8CpBblYWZZ/I1KA= +github.com/elastic/go-docappender/v2 v2.3.0/go.mod h1:VNWgXUE9HX1G6W6ON8dOs/KdH8aCxXir/fxxcfrnov4= github.com/elastic/go-elasticsearch/v7 v7.17.10 h1:TCQ8i4PmIJuBunvBS6bwT2ybzVFxxUhhltAs3Gyu1yo= github.com/elastic/go-elasticsearch/v7 v7.17.10/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4= github.com/elastic/go-elasticsearch/v8 v8.14.0 h1:1ywU8WFReLLcxE1WJqii3hTtbPUE2hc38ZK/j4mMFow= @@ -915,8 +915,8 @@ github.com/go-resty/resty/v2 v2.13.1/go.mod h1:GznXlLxkq6Nh4sU59rPmUw3VtgpO3aS96 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= -github.com/go-viper/mapstructure/v2 v2.0.0 h1:dhn8MZ1gZ0mzeodTG3jt5Vj/o87xZKuNAprG2mQfMfc= -github.com/go-viper/mapstructure/v2 v2.0.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/go-viper/mapstructure/v2 v2.1.0 h1:gHnMa2Y/pIxElCH2GlZZ1lZSsn6XMtufpGyP1XxdC/w= +github.com/go-viper/mapstructure/v2 v2.1.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/go-zookeeper/zk v1.0.3 h1:7M2kwOsc//9VeeFiPtf+uSJlVpU66x9Ba5+8XK7/TDg= github.com/go-zookeeper/zk v1.0.3/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM= @@ -2056,8 +2056,9 @@ golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/internal/pkg/agent/application/actions/handlers/handler_action_upgrade_test.go b/internal/pkg/agent/application/actions/handlers/handler_action_upgrade_test.go index e331e477253..2f127c699f0 100644 --- a/internal/pkg/agent/application/actions/handlers/handler_action_upgrade_test.go +++ b/internal/pkg/agent/application/actions/handlers/handler_action_upgrade_test.go @@ -7,7 +7,6 @@ package handlers import ( "context" "testing" - "time" "github.com/stretchr/testify/require" @@ -26,7 +25,8 @@ import ( ) type mockUpgradeManager struct { - msgChan chan string + msgChan chan string + completedChan chan struct{} } func (u *mockUpgradeManager) Upgradeable() bool { @@ -39,7 +39,7 @@ func (u *mockUpgradeManager) Reload(rawConfig *config.Config) error { func (u *mockUpgradeManager) Upgrade(ctx context.Context, version string, sourceURI string, action *fleetapi.ActionUpgrade, details *details.Details, skipVerifyOverride bool, skipDefaultPgp bool, pgpBytes ...string) (_ reexec.ShutdownCallbackFn, err error) { select { - case <-time.After(2 * time.Second): + case <-u.completedChan: u.msgChan <- "completed " + version return nil, nil case <-ctx.Done(): @@ -66,6 +66,7 @@ func TestUpgradeHandler(t *testing.T) { agentInfo := &info.AgentInfo{} msgChan := make(chan string) + completedChan := make(chan struct{}) // Create and start the coordinator c := coordinator.New( @@ -75,7 +76,7 @@ func TestUpgradeHandler(t *testing.T) { agentInfo, component.RuntimeSpecs{}, nil, - &mockUpgradeManager{msgChan: msgChan}, + &mockUpgradeManager{msgChan: msgChan, completedChan: completedChan}, nil, nil, nil, nil, nil, false) //nolint:errcheck // We don't need the termination state of the Coordinator go c.Run(ctx) @@ -85,6 +86,8 @@ func TestUpgradeHandler(t *testing.T) { Version: "8.3.0", SourceURI: "http://localhost"}} ack := noopacker.New() err := u.Handle(ctx, &a, ack) + // indicate that upgrade is completed + close(completedChan) require.NoError(t, err) msg := <-msgChan require.Equal(t, "completed 8.3.0", msg) @@ -100,6 +103,7 @@ func TestUpgradeHandlerSameVersion(t *testing.T) { agentInfo := &info.AgentInfo{} msgChan := make(chan string) + completedChan := make(chan struct{}) // Create and start the Coordinator c := coordinator.New( @@ -109,7 +113,7 @@ func TestUpgradeHandlerSameVersion(t *testing.T) { agentInfo, component.RuntimeSpecs{}, nil, - &mockUpgradeManager{msgChan: msgChan}, + &mockUpgradeManager{msgChan: msgChan, completedChan: completedChan}, nil, nil, nil, nil, nil, false) //nolint:errcheck // We don't need the termination state of the Coordinator go c.Run(ctx) @@ -122,6 +126,8 @@ func TestUpgradeHandlerSameVersion(t *testing.T) { err2 := u.Handle(ctx, &a, ack) require.NoError(t, err1) require.NoError(t, err2) + // indicate that upgrade is completed + close(completedChan) msg := <-msgChan require.Equal(t, "completed 8.3.0", msg) } @@ -136,6 +142,7 @@ func TestUpgradeHandlerNewVersion(t *testing.T) { agentInfo := &info.AgentInfo{} msgChan := make(chan string) + completedChan := make(chan struct{}) // Create and start the Coordinator c := coordinator.New( @@ -145,7 +152,7 @@ func TestUpgradeHandlerNewVersion(t *testing.T) { agentInfo, component.RuntimeSpecs{}, nil, - &mockUpgradeManager{msgChan: msgChan}, + &mockUpgradeManager{msgChan: msgChan, completedChan: completedChan}, nil, nil, nil, nil, nil, false) //nolint:errcheck // We don't need the termination state of the Coordinator go c.Run(ctx) @@ -158,11 +165,12 @@ func TestUpgradeHandlerNewVersion(t *testing.T) { ack := noopacker.New() err1 := u.Handle(ctx, &a1, ack) require.NoError(t, err1) - time.Sleep(1 * time.Second) err2 := u.Handle(ctx, &a2, ack) require.NoError(t, err2) msg1 := <-msgChan require.Equal(t, "canceled 8.2.0", msg1) + // indicate that upgrade is completed + close(completedChan) msg2 := <-msgChan require.Equal(t, "completed 8.5.0", msg2) } diff --git a/internal/pkg/agent/application/upgrade/watcher.go b/internal/pkg/agent/application/upgrade/watcher.go index ea6b03a5af3..47cf70d7c5b 100644 --- a/internal/pkg/agent/application/upgrade/watcher.go +++ b/internal/pkg/agent/application/upgrade/watcher.go @@ -93,14 +93,14 @@ func (ch *AgentWatcher) Run(ctx context.Context) { if failedErr == nil { flipFlopCount++ failedTimer.Reset(ch.checkInterval) - ch.log.Error("Agent reported failure (starting failed timer): %s", err) + ch.log.Errorf("Agent reported failure (starting failed timer): %s", err) } else { - ch.log.Error("Agent reported failure (failed timer already started): %s", err) + ch.log.Errorf("Agent reported failure (failed timer already started): %s", err) } } else { if failedErr != nil { failedTimer.Stop() - ch.log.Error("Agent reported healthy (failed timer stopped): %s", err) + ch.log.Info("Agent reported healthy (failed timer stopped)") } } failedErr = err @@ -115,7 +115,8 @@ func (ch *AgentWatcher) Run(ctx context.Context) { continue } // error lasted longer than the checkInterval, notify! - ch.notifyChan <- failedErr + ch.notifyChan <- fmt.Errorf("last error was not cleared before checkInterval (%s) elapsed: %w", + ch.checkInterval, failedErr) } } }() @@ -138,7 +139,7 @@ LOOP: connectCancel() if err != nil { ch.connectCounter++ - ch.log.Error("Failed connecting to running daemon: ", err) + ch.log.Errorf("Failed connecting to running daemon: %s", err) if ch.checkFailures() { return } @@ -152,7 +153,7 @@ LOOP: // considered a connect error stateCancel() ch.agentClient.Disconnect() - ch.log.Error("Failed to start state watch: ", err) + ch.log.Errorf("Failed to start state watch: %s", err) ch.connectCounter++ if ch.checkFailures() { return @@ -178,25 +179,30 @@ LOOP: for { state, err := watch.Recv() if err != nil { + ch.log.Debugf("received state: error: %s", + err) + // agent has crashed or exited stateCancel() ch.agentClient.Disconnect() - ch.log.Error("Lost connection: failed reading next state: ", err) + ch.log.Errorf("Lost connection: failed reading next state: %s", err) ch.lostCounter++ if ch.checkFailures() { return } continue LOOP } + ch.log.Debugf("received state: %s:%s", + state.State, state.Message) // gRPC is good at hiding the fact that connection was lost // to ensure that we don't miss a restart a changed PID means // we are now talking to a different spawned Elastic Agent if ch.lastPid == -1 { ch.lastPid = state.Info.PID - ch.log.Info(fmt.Sprintf("Communicating with PID %d", ch.lastPid)) + ch.log.Infof("Communicating with PID %d", ch.lastPid) } else if ch.lastPid != state.Info.PID { - ch.log.Error(fmt.Sprintf("Communication with PID %d lost, now communicating with PID %d", ch.lastPid, state.Info.PID)) + ch.log.Errorf("Communication with PID %d lost, now communicating with PID %d", ch.lastPid, state.Info.PID) ch.lastPid = state.Info.PID // count the PID change as a lost connection, but allow // the communication to continue unless has become a failure diff --git a/internal/pkg/agent/application/upgrade/watcher_test.go b/internal/pkg/agent/application/upgrade/watcher_test.go index 689a051d420..29e1194eb99 100644 --- a/internal/pkg/agent/application/upgrade/watcher_test.go +++ b/internal/pkg/agent/application/upgrade/watcher_test.go @@ -270,14 +270,25 @@ func TestWatcher_AgentError(t *testing.T) { } func TestWatcher_AgentErrorQuick(t *testing.T) { - // test tests for success, which only happens when no error comes in - // during this time period + // Success only happens when no error comes in during this time period ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) defer cancel() errCh := make(chan error) - logger, _ := logger.NewTesting("watcher") - w := NewAgentWatcher(errCh, logger, 100*time.Millisecond) + log, obs := logger.NewTesting("watcher") + defer func() { + if t.Failed() { + rawLogs := obs.All() + for _, rawLog := range rawLogs { + msg := fmt.Sprintf("[%s] %s", rawLog.Level, rawLog.Message) + for k, v := range rawLog.ContextMap() { + msg += fmt.Sprintf("%s=%v", k, v) + } + t.Log(msg) + } + } + }() + w := NewAgentWatcher(errCh, log, 100*time.Millisecond) // reports an error state, followed by a healthy state (should not error) mockHandler := func(srv cproto.ElasticAgentControl_StateWatchServer) error { @@ -302,7 +313,7 @@ func TestWatcher_AgentErrorQuick(t *testing.T) { return nil } mock := &mockDaemon{watch: mockHandler} - require.NoError(t, mock.Start()) + require.NoError(t, mock.Start(), "could not start mock agent daemon") defer mock.Stop() // set client to mock; before running diff --git a/internal/pkg/agent/protection/config_test.go b/internal/pkg/agent/protection/config_test.go index 239ead78d03..2a6bcb79b61 100644 --- a/internal/pkg/agent/protection/config_test.go +++ b/internal/pkg/agent/protection/config_test.go @@ -7,8 +7,8 @@ package protection import ( "testing" + "github.com/go-viper/mapstructure/v2" "github.com/google/go-cmp/cmp" - "github.com/mitchellh/mapstructure" ) func TestConfigDeserializer(t *testing.T) { diff --git a/internal/pkg/agent/protection/policy.go b/internal/pkg/agent/protection/policy.go index 830043f3547..b9d61f71bb2 100644 --- a/internal/pkg/agent/protection/policy.go +++ b/internal/pkg/agent/protection/policy.go @@ -12,7 +12,7 @@ import ( "github.com/elastic/elastic-agent/pkg/core/logger" - "github.com/mitchellh/mapstructure" + "github.com/go-viper/mapstructure/v2" ) var ( @@ -166,12 +166,12 @@ func getPolicySignedDataAndSignature(policy map[string]interface{}) (data, signa data, err = getBytes(signed, "data") if err != nil { - return + return nil, nil, err } signature, err = getBytes(signed, "signature") if err != nil { - return + return nil, nil, err } return data, signature, err diff --git a/internal/pkg/fleetapi/action.go b/internal/pkg/fleetapi/action.go index 99470262ea3..e2324617b11 100644 --- a/internal/pkg/fleetapi/action.go +++ b/internal/pkg/fleetapi/action.go @@ -10,7 +10,7 @@ import ( "strings" "time" - "github.com/mitchellh/mapstructure" + "github.com/go-viper/mapstructure/v2" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" ) diff --git a/main.go b/main.go index 98580c51c5b..de511ac3957 100644 --- a/main.go +++ b/main.go @@ -6,9 +6,7 @@ package main import ( "fmt" - "math/rand" "os" - "time" "github.com/elastic/elastic-agent/internal/pkg/agent/cmd" "github.com/elastic/elastic-agent/pkg/core/process" @@ -36,7 +34,6 @@ func main() { } defer pj.Close() - rand.Seed(time.Now().UnixNano()) command := cmd.NewCommand() err = command.Execute() if err != nil { diff --git a/pkg/component/component_test.go b/pkg/component/component_test.go index 06ccf7d718a..44120632d1e 100644 --- a/pkg/component/component_test.go +++ b/pkg/component/component_test.go @@ -634,7 +634,7 @@ func TestToComponents(t *testing.T) { ID: "filestream-default-filestream-1", Type: client.UnitTypeInput, LogLevel: defaultUnitLogLevel, - Err: errors.New("1 decoding error(s): 'meta' expected a map, got 'slice'"), + Err: fmt.Errorf("decoding error: %w", fmt.Errorf("decoding failed due to the following error(s):\n\n%w", errors.Join(errors.New("'meta' expected a map, got 'slice'")))), }, }, }, @@ -722,7 +722,7 @@ func TestToComponents(t *testing.T) { ID: "cloudbeat-default-cloudbeat-1-unit", Type: client.UnitTypeInput, LogLevel: defaultUnitLogLevel, - Err: errors.New("1 decoding error(s): 'meta' expected a map, got 'slice'"), + Err: fmt.Errorf("decoding error: %w", fmt.Errorf("decoding failed due to the following error(s):\n\n%w", errors.Join(errors.New("'meta' expected a map, got 'slice'")))), }, }, }, diff --git a/pkg/component/config.go b/pkg/component/config.go index 781e2e7624f..3c097910e59 100644 --- a/pkg/component/config.go +++ b/pkg/component/config.go @@ -11,7 +11,7 @@ import ( "reflect" "strings" - "github.com/mitchellh/mapstructure" + "github.com/go-viper/mapstructure/v2" "google.golang.org/protobuf/types/known/structpb" "github.com/elastic/elastic-agent-client/v7/pkg/proto" @@ -94,7 +94,7 @@ func ExpectedConfig(cfg map[string]interface{}) (*proto.UnitExpectedConfig, erro } if err := decoder.Decode(cfg); err != nil { - return nil, rewrapErr(err) + return nil, fmt.Errorf("decoding error: %w", err) } if err := setSource(result, cfg); err != nil { @@ -276,16 +276,3 @@ func getJSONFieldName(field reflect.StructField) string { split := strings.Split(tag, ",") return strings.TrimSpace(split[0]) } - -func rewrapErr(err error) error { - var me *mapstructure.Error - if !errors.As(err, &me) { - return err - } - errs := me.WrappedErrors() - points := make([]string, 0, len(errs)) - for _, e := range errs { - points = append(points, e.Error()) - } - return fmt.Errorf("%d decoding error(s): %s", len(errs), strings.Join(points, ", ")) -} diff --git a/pkg/component/config_test.go b/pkg/component/config_test.go index 7cdef177829..30fae90dc37 100644 --- a/pkg/component/config_test.go +++ b/pkg/component/config_test.go @@ -183,7 +183,7 @@ func TestExpectedConfig(t *testing.T) { }, }, }, - Err: errors.New("1 decoding error(s): 'meta' expected a map, got 'slice'"), + Err: errors.New("decoding error: decoding failed due to the following error(s):\n\n'meta' expected a map, got 'slice'"), }, } diff --git a/testing/integration/agent_long_running_leak_test.go b/testing/integration/agent_long_running_leak_test.go index 894954df15e..6ccc567f55a 100644 --- a/testing/integration/agent_long_running_leak_test.go +++ b/testing/integration/agent_long_running_leak_test.go @@ -9,7 +9,6 @@ package integration import ( "context" "encoding/json" - "fmt" "io" "net" "net/http" @@ -30,9 +29,7 @@ import ( "github.com/elastic/elastic-agent-libs/api/npipe" "github.com/elastic/elastic-agent-libs/kibana" "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" - "github.com/elastic/elastic-agent/pkg/control/v2/client" "github.com/elastic/elastic-agent/pkg/control/v2/cproto" - "github.com/elastic/elastic-agent/pkg/core/process" atesting "github.com/elastic/elastic-agent/pkg/testing" "github.com/elastic/elastic-agent/pkg/testing/define" "github.com/elastic/elastic-agent/pkg/testing/tools" @@ -154,7 +151,7 @@ func (runner *ExtendedRunner) TestHandleLeak() { timer := time.NewTimer(testDuration) defer timer.Stop() - ticker := time.NewTicker(time.Second * 10) + ticker := time.NewTicker(time.Second * 60) defer ticker.Stop() done := false @@ -163,10 +160,7 @@ func (runner *ExtendedRunner) TestHandleLeak() { case <-timer.C: done = true case <-ticker.C: - // https://github.com/elastic/elastic-agent/issues/5300 - // Ideally we would require healthy but we currently report as DEGRADED due to unexpected permissions errors - // accessing some process metrics. Ensure the leak tests still run as long while this is the case. - err := runner.IsHealthyOrDegraded(ctx) + err := runner.agentFixture.IsHealthy(ctx) require.NoError(runner.T(), err) // iterate through our watchers, update them for _, mon := range runner.resourceWatchers { @@ -211,8 +205,6 @@ func (runner *ExtendedRunner) TestHandleLeak() { // CheckHealthAtStartup ensures all the beats and agent are healthy and working before we continue func (runner *ExtendedRunner) CheckHealthAtStartup(ctx context.Context) { - runner.T().Helper() - // because we need to separately fetch the PIDs, wait until everything is healthy before we look for running beats compDebugName := "" require.Eventually(runner.T(), func() bool { @@ -241,11 +233,7 @@ func (runner *ExtendedRunner) CheckHealthAtStartup(ctx context.Context) { } } runner.T().Logf("component state: %s", comp.Message) - - // https://github.com/elastic/elastic-agent/issues/5300 - // Ideally we would require healthy but we currently report as DEGRADED due to unexpected permissions errors - // accessing some process metrics. Ensure the leak tests still run as long while this is the case. - if !isHealthyOrDegraded(comp.State) { + if comp.State != int(cproto.State_HEALTHY) { compDebugName = comp.Name allHealthy = false } @@ -254,26 +242,6 @@ func (runner *ExtendedRunner) CheckHealthAtStartup(ctx context.Context) { }, runner.healthCheckTime, runner.healthCheckRefreshTime, "install never became healthy: components did not return a healthy state: %s", compDebugName) } -func (runner *ExtendedRunner) IsHealthyOrDegraded(ctx context.Context, opts ...process.CmdOption) error { - runner.T().Helper() - - status, err := runner.agentFixture.ExecStatus(ctx, opts...) - if err != nil { - return fmt.Errorf("agent status returned an error: %w", err) - } - - if !isHealthyOrDegraded(status.State) { - return fmt.Errorf("agent isn't healthy or degraded, current status: %s", - client.State(status.State)) - } - - return nil -} - -func isHealthyOrDegraded(state int) bool { - return state == int(cproto.State_HEALTHY) || state == int(cproto.State_DEGRADED) -} - /* ============================================================================= Watchers for checking resource usage diff --git a/testing/integration/install_test.go b/testing/integration/install_test.go index f2159752943..6e7d4a9496f 100644 --- a/testing/integration/install_test.go +++ b/testing/integration/install_test.go @@ -334,7 +334,6 @@ func TestRepeatedInstallUninstall(t *testing.T) { } func randStr(length int) string { - rand.Seed(time.Now().UnixNano()) var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") runes := make([]rune, length)