From 0843a4a342cf840415ef2d0f0635fc213c7dd9eb Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Wed, 19 Jun 2024 03:45:35 +0200 Subject: [PATCH] refactor: remove fleetctl cmd We are no longer using fleet for systemtests or local dev so the utility is unused. --- systemtest/cmd/fleetctl/README.md | 24 ---- systemtest/cmd/fleetctl/main.go | 187 ------------------------------ systemtest/go.mod | 3 - systemtest/go.sum | 8 -- 4 files changed, 222 deletions(-) delete mode 100644 systemtest/cmd/fleetctl/README.md delete mode 100644 systemtest/cmd/fleetctl/main.go diff --git a/systemtest/cmd/fleetctl/README.md b/systemtest/cmd/fleetctl/README.md deleted file mode 100644 index a67085e5efd..00000000000 --- a/systemtest/cmd/fleetctl/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# fleetctl - -`fleetctl` provides a minimal CLI for interacting with the Fleet API, -for use in development and testing. This tool may be useful for -manipulating APM integration config vars that are not shown in the -APM integration policy editor. - -# Examples - -## Listing policies - -`fleetctl -u list-policies` - -## Updating vars - -`fleetctl -u set-policy-var tail_sampling_storage_limit=30MB` - -## Updating arbitrary config - -This command can be used to set arbitrary configuration understood by APM Server, -where that configuration has no corresponding integration package var. - -`fleetctl -u set-policy-config apm-server.max_concurrent_decoders=300` - diff --git a/systemtest/cmd/fleetctl/main.go b/systemtest/cmd/fleetctl/main.go deleted file mode 100644 index e2b02a24633..00000000000 --- a/systemtest/cmd/fleetctl/main.go +++ /dev/null @@ -1,187 +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 main - -import ( - "errors" - "fmt" - "log" - "net/url" - "reflect" - "strings" - - "github.com/spf13/cobra" - "gopkg.in/yaml.v3" - - "github.com/elastic/apm-server/systemtest/fleettest" -) - -var client *fleettest.Client - -func parseKV(s ...string) (map[string]string, error) { - out := make(map[string]string) - for _, s := range s { - i := strings.IndexRune(s, '=') - if i < 0 { - return nil, errors.New("missing '='; expected format k=v") - } - k, vstr := s[:i], s[i+1:] - out[k] = vstr - } - return out, nil -} - -var listPackagePoliciesCommand = &cobra.Command{ - Use: "list-policies", - Short: "List Fleet integration package policies", - RunE: func(cmd *cobra.Command, _ []string) error { - policies, err := client.ListPackagePolicies() - if err != nil { - return fmt.Errorf("failed to fetch package policies: %w", err) - } - return yaml.NewEncoder(cmd.OutOrStdout()).Encode(policies) - }, -} - -var setPolicyVarCommand = &cobra.Command{ - Use: "set-policy-var ", - Short: "Set config vars for a Fleet integration package policy", - Args: cobra.MinimumNArgs(2), - RunE: func(_ *cobra.Command, args []string) error { - setVars, err := parseKV(args[1:]...) - if err != nil { - return err - } - - policy, err := client.PackagePolicy(args[0]) - if err != nil { - return fmt.Errorf("failed to fetch package policy: %w", err) - } - if len(policy.Inputs) != 1 { - return fmt.Errorf("expected 1 input, got %d", len(policy.Inputs)) - } - - for k, v := range setVars { - varObj, ok := policy.Inputs[0].Vars[k].(map[string]interface{}) - if !ok { - return fmt.Errorf("var %q not found in package policy", k) - } - value := varObj["value"] - ptrZero := reflect.New(reflect.TypeOf(value)) - if err := yaml.Unmarshal([]byte(v), ptrZero.Interface()); err != nil { - return fmt.Errorf("failed to unmarshal var %q: %w", k, err) - } - varObj["value"] = ptrZero.Elem().Interface() - } - - if err := client.UpdatePackagePolicy(policy); err != nil { - return fmt.Errorf("failed to update policy: %w", err) - } - return nil - }, -} - -var setPolicyConfigCommand = &cobra.Command{ - Use: "set-policy-config ", - Short: "Set arbitrary config for a Fleet integration package policy", - Args: cobra.MinimumNArgs(2), - RunE: func(_ *cobra.Command, args []string) error { - config, err := parseKV(args[1:]...) - if err != nil { - return err - } - - policy, err := client.PackagePolicy(args[0]) - if err != nil { - return fmt.Errorf("failed to fetch package policy: %w", err) - } - if len(policy.Inputs) != 1 { - return fmt.Errorf("expected 1 input, got %d", len(policy.Inputs)) - } - - merge := func(k string, v interface{}, to map[string]interface{}) { - for { - before, after, found := strings.Cut(k, ".") - if !found { - to[before] = v - return - } - m, ok := to[before].(map[string]interface{}) - if !ok { - m = make(map[string]interface{}) - to[before] = m - } - k = after - to = m - } - } - - existing := policy.Inputs[0].Config - if existing == nil { - existing = make(map[string]interface{}) - policy.Inputs[0].Config = existing - } - for k, v := range config { - var value interface{} - if err := yaml.Unmarshal([]byte(v), &value); err != nil { - return fmt.Errorf("failed to unmarshal var %q: %w", k, err) - } - // Each top-level key's value is nested under "value". - if before, after, ok := strings.Cut(k, "."); ok { - k = strings.Join([]string{before, "value", after}, ".") - } else { - k = before + ".value" - } - merge(k, value, existing) - } - - if err := client.UpdatePackagePolicy(policy); err != nil { - return fmt.Errorf("failed to update policy: %w", err) - } - return nil - }, -} - -func main() { - var ( - kibanaURL string - kibanaUser string - kibanaPass string - ) - rootCommand := &cobra.Command{Use: "fleetctl", - PersistentPreRunE: func(_ *cobra.Command, _ []string) error { - u, err := url.Parse(kibanaURL) - if err != nil { - return err - } - u.User = url.UserPassword(kibanaUser, kibanaPass) - client = fleettest.NewClient(u.String()) - return nil - }, - } - rootCommand.AddCommand(listPackagePoliciesCommand) - rootCommand.AddCommand(setPolicyVarCommand) - rootCommand.AddCommand(setPolicyConfigCommand) - rootCommand.PersistentFlags().StringVarP(&kibanaURL, "kibana", "u", "http://localhost:5601", "URL of the Kibana server") - rootCommand.PersistentFlags().StringVar(&kibanaUser, "user", "admin", "Username to use for Kibana authentication") - rootCommand.PersistentFlags().StringVar(&kibanaPass, "pass", "changeme", "Password to use for Kibana authentication") - - if err := rootCommand.Execute(); err != nil { - log.Fatal(err) - } -} diff --git a/systemtest/go.mod b/systemtest/go.mod index 8e7817250ab..6882b05793a 100644 --- a/systemtest/go.mod +++ b/systemtest/go.mod @@ -14,7 +14,6 @@ require ( github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 github.com/hashicorp/go-multierror v1.1.1 github.com/jaegertracing/jaeger v1.58.0 - github.com/spf13/cobra v1.8.1 github.com/stretchr/testify v1.9.0 github.com/testcontainers/testcontainers-go v0.31.0 github.com/tidwall/gjson v1.17.1 @@ -66,7 +65,6 @@ require ( github.com/google/uuid v1.6.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect - github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.17.8 // indirect @@ -89,7 +87,6 @@ require ( github.com/shirou/gopsutil/v3 v3.24.4 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/sirupsen/logrus v1.9.3 // indirect - github.com/spf13/pflag v1.0.5 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect github.com/tidwall/sjson v1.2.5 // indirect diff --git a/systemtest/go.sum b/systemtest/go.sum index 5851a64de8a..9d24dd717de 100644 --- a/systemtest/go.sum +++ b/systemtest/go.sum @@ -21,7 +21,6 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E= github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= -github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -80,8 +79,6 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= -github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jaegertracing/jaeger v1.58.0 h1:aslb9VilVaddzHUA618PUtAaO3GblA7hlyItfwtzAe0= github.com/jaegertracing/jaeger v1.58.0/go.mod h1:2qpJpm9BzpbxNpaillaCA4pvdAIRTJT0ZRxrzMglBlo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -137,7 +134,6 @@ github.com/prometheus/procfs v0.15.0 h1:A82kmvXJq2jTu5YUhSGNlYoxh85zLnKgPz4bMZgI github.com/prometheus/procfs v0.15.0/go.mod h1:Y0RJ/Y5g5wJpkTisOtqwDSo4HwhGmLB4VQSw2sQJLHk= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shirou/gopsutil/v3 v3.24.4 h1:dEHgzZXt4LMNm+oYELpzl9YCqV65Yr/6SfrvgRBtXeU= github.com/shirou/gopsutil/v3 v3.24.4/go.mod h1:lTd2mdiOspcqLgAnr9/nGi71NkeMpWKdmhuxm9GusH8= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= @@ -146,10 +142,6 @@ github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= -github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=