From 24d7cf05bc88e18fee1caa31786f9bd154b7db60 Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Mon, 25 Nov 2024 22:03:58 +0100 Subject: [PATCH] feat: remove 32bit platformcheck (#41544) beats and all downstream clients dropped support for 32bit artifacts remove the native platform check as it will always pass --- libbeat/cmd/platformcheck/platformcheck.go | 48 -------------- .../cmd/platformcheck/platformcheck_other.go | 24 ------- .../cmd/platformcheck/platformcheck_test.go | 65 ------------------- libbeat/cmd/root.go | 7 -- 4 files changed, 144 deletions(-) delete mode 100644 libbeat/cmd/platformcheck/platformcheck.go delete mode 100644 libbeat/cmd/platformcheck/platformcheck_other.go delete mode 100644 libbeat/cmd/platformcheck/platformcheck_test.go diff --git a/libbeat/cmd/platformcheck/platformcheck.go b/libbeat/cmd/platformcheck/platformcheck.go deleted file mode 100644 index 891b7827ae9..00000000000 --- a/libbeat/cmd/platformcheck/platformcheck.go +++ /dev/null @@ -1,48 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build linux || windows - -package platformcheck - -import ( - "fmt" - "math/bits" - "strings" - - "github.com/shirou/gopsutil/v4/host" -) - -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/libbeat/cmd/platformcheck/platformcheck_other.go b/libbeat/cmd/platformcheck/platformcheck_other.go deleted file mode 100644 index cab7157f7ee..00000000000 --- a/libbeat/cmd/platformcheck/platformcheck_other.go +++ /dev/null @@ -1,24 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build !linux && !windows - -package platformcheck - -func CheckNativePlatformCompat() error { - return nil -} diff --git a/libbeat/cmd/platformcheck/platformcheck_test.go b/libbeat/cmd/platformcheck/platformcheck_test.go deleted file mode 100644 index 9e8d71b4f96..00000000000 --- a/libbeat/cmd/platformcheck/platformcheck_test.go +++ /dev/null @@ -1,65 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package platformcheck - -import ( - "os" - "os/exec" - "path/filepath" - "runtime" - "testing" - - "github.com/stretchr/testify/require" -) - -func TestCheckPlatformCompat(t *testing.T) { - if !(runtime.GOARCH == "amd64" && (runtime.GOOS == "linux" || - runtime.GOOS == "windows")) { - 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") - - // run test helper - cmd = exec.Command(helper, "-test.v", "-test.run", "TestHelper") - cmd.Env = []string{"GO_USE_HELPER=1"} - output, err := cmd.Output() - if err != nil { - t.Logf("32bit binary tester failed.\n Output: %s", output) - } -} - -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/libbeat/cmd/root.go b/libbeat/cmd/root.go index cbe2f7f8f6e..335b83560d7 100644 --- a/libbeat/cmd/root.go +++ b/libbeat/cmd/root.go @@ -20,14 +20,12 @@ package cmd import ( "flag" "fmt" - "os" "github.com/spf13/cobra" "github.com/elastic/beats/v7/libbeat/beat" "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cmd/instance" - "github.com/elastic/beats/v7/libbeat/cmd/platformcheck" "github.com/elastic/beats/v7/libbeat/licenser" "github.com/elastic/beats/v7/libbeat/outputs/elasticsearch" ) @@ -53,11 +51,6 @@ func GenRootCmdWithSettings(beatCreator beat.Creator, settings instance.Settings // Check we are actually talking with Elasticsearch, to ensure that used features actually exist. _, _ = elasticsearch.RegisterGlobalCallback(licenser.FetchAndVerify) - if err := platformcheck.CheckNativePlatformCompat(); err != nil { - fmt.Fprintf(os.Stderr, "Failed to initialize: %v\n", err) - os.Exit(1) - } - if settings.IndexPrefix == "" { settings.IndexPrefix = settings.Name }