From 4b6e557c59862c952eac18483630c1baa913a342 Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Wed, 28 Aug 2024 05:41:39 +0200 Subject: [PATCH 1/3] feat: remove 32bit platform check elastic agent dropped support for 32bit systems a long time ago remove the platform check on startup --- go.mod | 2 +- internal/pkg/agent/cmd/platformcheck.go | 38 ------------ internal/pkg/agent/cmd/platformcheck_other.go | 14 ----- internal/pkg/agent/cmd/platformcheck_test.go | 62 ------------------- main.go | 6 -- 5 files changed, 1 insertion(+), 121 deletions(-) delete mode 100644 internal/pkg/agent/cmd/platformcheck.go delete mode 100644 internal/pkg/agent/cmd/platformcheck_other.go delete mode 100644 internal/pkg/agent/cmd/platformcheck_test.go diff --git a/go.mod b/go.mod index ea44bb21970..8ed62e3d5f6 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,6 @@ require ( github.com/rs/zerolog v1.27.0 github.com/sajari/regression v1.0.1 github.com/schollz/progressbar/v3 v3.13.1 - github.com/shirou/gopsutil/v3 v3.24.5 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.9.0 @@ -302,6 +301,7 @@ require ( github.com/rs/cors v1.11.0 // indirect github.com/scaleway/scaleway-sdk-go v1.0.0-beta.27 // indirect github.com/sergi/go-diff v1.3.1 // indirect + github.com/shirou/gopsutil/v3 v3.24.5 // indirect github.com/shirou/gopsutil/v4 v4.24.7 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/stretchr/objx v0.5.2 // indirect diff --git a/internal/pkg/agent/cmd/platformcheck.go b/internal/pkg/agent/cmd/platformcheck.go deleted file mode 100644 index b3bdac6ad55..00000000000 --- a/internal/pkg/agent/cmd/platformcheck.go +++ /dev/null @@ -1,38 +0,0 @@ -// 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 linux || windows - -package cmd - -import ( - "fmt" - "math/bits" - "strings" - - "github.com/shirou/gopsutil/v3/host" -) - -// CheckNativePlatformCompat checks if the binary is running -// on an appropriate system. 32-bit binaries can only run on -// 32-bit systems and 64-bit binaries only run on 64-bit systems. -func CheckNativePlatformCompat() error { - const compiledArchBits = bits.UintSize // 32 if the binary was compiled for 32 bit architecture. - - if compiledArchBits > 32 { - // We assume that 64bit binaries can only be run on 64bit systems - return nil - } - - arch, err := host.KernelArch() - if err != nil { - return err - } - - if strings.Contains(arch, "64") { - return fmt.Errorf("trying to run %vBit binary on 64Bit system", compiledArchBits) - } - - return nil -} diff --git a/internal/pkg/agent/cmd/platformcheck_other.go b/internal/pkg/agent/cmd/platformcheck_other.go deleted file mode 100644 index 419fa331aa9..00000000000 --- a/internal/pkg/agent/cmd/platformcheck_other.go +++ /dev/null @@ -1,14 +0,0 @@ -// 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 !linux && !windows - -package cmd - -// CheckNativePlatformCompat verifies is the platform is compatible -// with the current system. This is used to check if you are trying to run a 32bits -// binary on a 64 bits system. -func CheckNativePlatformCompat() error { - return nil -} diff --git a/internal/pkg/agent/cmd/platformcheck_test.go b/internal/pkg/agent/cmd/platformcheck_test.go deleted file mode 100644 index 2de871ab98b..00000000000 --- a/internal/pkg/agent/cmd/platformcheck_test.go +++ /dev/null @@ -1,62 +0,0 @@ -// 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. - -package cmd - -import ( - "os" - "os/exec" - "path/filepath" - "runtime" - "testing" - - "github.com/stretchr/testify/require" -) - -func TestCheckPlatformCompat(t *testing.T) { - t.Skip("there is no failure condition on this test and it's flaky, " + - "failing due to the default 10min timeout. " + - "See https://github.com/elastic/elastic-agent/issues/3964") - if !(runtime.GOARCH == "amd64" && (isLinux() || - isWindows())) { - t.Skip("Test not support on current platform") - } - - // compile test helper - tmp := t.TempDir() - helper := filepath.Join(tmp, "helper") - - cmd := exec.Command("go", "test", "-c", "-o", helper) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.Env = append(os.Environ(), "GOARCH=386") - require.NoError(t, cmd.Run(), "failed to compile test helper") - t.Logf("compiled test binary %q", helper) - - // run test helper - cmd = exec.Command(helper, "-test.v", "-test.run", "TestHelper") - cmd.Env = []string{"GO_USE_HELPER=1"} - t.Logf("running %q", cmd.Args) - output, err := cmd.Output() - if err != nil { - t.Logf("32bit binary tester failed.\n Err: %v\nOutput: %s", - err, output) - } -} - -func isLinux() bool { - return runtime.GOOS == "linux" -} - -func TestHelper(t *testing.T) { - if os.Getenv("GO_USE_HELPER") != "1" { - t.Log("ignore helper") - return - } - - err := CheckNativePlatformCompat() - if err.Error() != "trying to run 32Bit binary on 64Bit system" { - t.Error("expected the native platform check to fail") - } -} diff --git a/main.go b/main.go index de511ac3957..29c71df1ad3 100644 --- a/main.go +++ b/main.go @@ -21,12 +21,6 @@ func main() { } }() - err = cmd.CheckNativePlatformCompat() - if err != nil { - fmt.Fprintf(os.Stderr, "Failed to initialize: %v\n", err) - return - } - pj, err := process.CreateJobObject() if err != nil { fmt.Fprintf(os.Stderr, "Failed to initialize process job object: %v\n", err) From 5c0f7cbd08b7fb5b2ec80a5f5f6d8713eec260ab Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Wed, 28 Aug 2024 05:44:20 +0200 Subject: [PATCH 2/3] build: bump elastic-agent-system-metrics to drop gopsutil/v3 dep --- go.mod | 3 +-- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 8ed62e3d5f6..92ec89c03f4 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( 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.10.0 - github.com/elastic/elastic-agent-system-metrics v0.11.1 + github.com/elastic/elastic-agent-system-metrics v0.11.2 github.com/elastic/elastic-transport-go/v8 v8.6.0 github.com/elastic/go-elasticsearch/v8 v8.14.0 github.com/elastic/go-licenser v0.4.2 @@ -301,7 +301,6 @@ require ( github.com/rs/cors v1.11.0 // indirect github.com/scaleway/scaleway-sdk-go v1.0.0-beta.27 // indirect github.com/sergi/go-diff v1.3.1 // indirect - github.com/shirou/gopsutil/v3 v3.24.5 // indirect github.com/shirou/gopsutil/v4 v4.24.7 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/stretchr/objx v0.5.2 // indirect diff --git a/go.sum b/go.sum index 9db629330ec..07828b4e887 100644 --- a/go.sum +++ b/go.sum @@ -782,8 +782,8 @@ github.com/elastic/elastic-agent-client/v7 v7.15.0 h1:nDB7v8TBoNuD6IIzC3z7Q0y+7b github.com/elastic/elastic-agent-client/v7 v7.15.0/go.mod h1:6h+f9QdIr3GO2ODC0Y8+aEXRwzbA5W4eV4dd/67z7nI= 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-agent-system-metrics v0.11.2 h1:UjSBcY6U3H3venB5zAPEFNjAb4Bb38EiVqaA4zALEnM= +github.com/elastic/elastic-agent-system-metrics v0.11.2/go.mod h1:saqLKe9fuyuAo6IADAnnuy1kaBI7VNlxfwMo8KzSRyQ= 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.3.0 h1:Vr+l36jM+sE/LHp0JFxSIbHlWTSk8CpBblYWZZ/I1KA= From 74609adaa2d89200d20b5a964731c772937fedcd Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Wed, 28 Aug 2024 06:20:51 +0200 Subject: [PATCH 3/3] lint: regenerate notice --- NOTICE.txt | 144 ++++++++++++++++++++++++++--------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index a31efd05fea..4e589995a3c 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -1475,11 +1475,11 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-l -------------------------------------------------------------------------------- Dependency : github.com/elastic/elastic-agent-system-metrics -Version: v0.11.1 +Version: v0.11.2 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-system-metrics@v0.11.1/LICENSE.txt: +Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-system-metrics@v0.11.2/LICENSE.txt: Apache License Version 2.0, January 2004 @@ -8589,76 +8589,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --------------------------------------------------------------------------------- -Dependency : github.com/shirou/gopsutil/v3 -Version: v3.24.5 -Licence type (autodetected): BSD-3-Clause --------------------------------------------------------------------------------- - -Contents of probable licence file $GOMODCACHE/github.com/shirou/gopsutil/v3@v3.24.5/LICENSE: - -gopsutil is distributed under BSD license reproduced below. - -Copyright (c) 2014, WAKAYAMA Shirou -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above 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 the gopsutil authors nor the names of its contributors - may be used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -------- -internal/common/binary.go in the gopsutil is copied and modified from golang/encoding/binary.go. - - - -Copyright (c) 2009 The Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -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 -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -------------------------------------------------------------------------------- Dependency : github.com/spf13/cobra Version: v1.8.1 @@ -49036,6 +48966,76 @@ DEALINGS IN THE SOFTWARE. +-------------------------------------------------------------------------------- +Dependency : github.com/shirou/gopsutil/v3 +Version: v3.24.5 +Licence type (autodetected): BSD-3-Clause +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/github.com/shirou/gopsutil/v3@v3.24.5/LICENSE: + +gopsutil is distributed under BSD license reproduced below. + +Copyright (c) 2014, WAKAYAMA Shirou +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above 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 the gopsutil authors nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +------- +internal/common/binary.go in the gopsutil is copied and modified from golang/encoding/binary.go. + + + +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +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 +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + -------------------------------------------------------------------------------- Dependency : github.com/shirou/gopsutil/v4 Version: v4.24.7