From 5bee2bb31284af4e4aee8ab9f5d2c39bb5aef7ab Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 30 Oct 2024 13:29:25 -0400 Subject: [PATCH] plumbing for the 'zrok test canary' commands (#771) --- cmd/zrok/main.go | 22 ++++++++++++++-------- cmd/zrok/testCanaryPeriodic.go | 29 +++++++++++++++++++++++++++++ cmd/zrok/testLoopPublic.go | 32 ++++++++++++++++---------------- 3 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 cmd/zrok/testCanaryPeriodic.go diff --git a/cmd/zrok/main.go b/cmd/zrok/main.go index 8dc564418..5b2c85522 100644 --- a/cmd/zrok/main.go +++ b/cmd/zrok/main.go @@ -24,7 +24,8 @@ func init() { adminCmd.AddCommand(adminDeleteCmd) adminCmd.AddCommand(adminListCmd) adminCmd.AddCommand(adminUpdateCmd) - testCmd.AddCommand(loopCmd) + testCmd.AddCommand(testCanaryCmd) + testCmd.AddCommand(testLoopCmd) rootCmd.AddCommand(adminCmd) rootCmd.AddCommand(configCmd) rootCmd.AddCommand(modifyCmd) @@ -82,12 +83,6 @@ var configCmd = &cobra.Command{ Short: "Configure your zrok environment", } -var loopCmd = &cobra.Command{ - Use: "loopback", - Aliases: []string{"loop"}, - Short: "Loopback testing utilities", -} - var modifyCmd = &cobra.Command{ Use: "modify", Aliases: []string{"mod"}, @@ -101,7 +96,18 @@ var shareCmd = &cobra.Command{ var testCmd = &cobra.Command{ Use: "test", - Short: "Utilities for testing zrok deployments", + Short: "Utilities for testing deployments", +} + +var testCanaryCmd = &cobra.Command{ + Use: "canary", + Short: "Utilities for performance management", +} + +var testLoopCmd = &cobra.Command{ + Use: "loopback", + Aliases: []string{"loop"}, + Short: "Loopback testing utilities", } func main() { diff --git a/cmd/zrok/testCanaryPeriodic.go b/cmd/zrok/testCanaryPeriodic.go new file mode 100644 index 000000000..428df8477 --- /dev/null +++ b/cmd/zrok/testCanaryPeriodic.go @@ -0,0 +1,29 @@ +package main + +import ( + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +func init() { + testCanaryCmd.AddCommand(newTestCanaryPeriodicCommand().cmd) +} + +type testCanaryPeriodicCommand struct { + cmd *cobra.Command +} + +func newTestCanaryPeriodicCommand() *testCanaryPeriodicCommand { + cmd := &cobra.Command{ + Use: "periodic", + Short: "Run a periodic canary inspection", + Args: cobra.NoArgs, + } + command := &testCanaryPeriodicCommand{cmd: cmd} + cmd.Run = command.run + return command +} + +func (c *testCanaryPeriodicCommand) run(_ *cobra.Command, _ []string) { + logrus.Info("periodic") +} diff --git a/cmd/zrok/testLoopPublic.go b/cmd/zrok/testLoopPublic.go index a47ef7210..0248c064a 100644 --- a/cmd/zrok/testLoopPublic.go +++ b/cmd/zrok/testLoopPublic.go @@ -28,7 +28,7 @@ import ( ) func init() { - loopCmd.AddCommand(newTestLoopPublicCommand().cmd) + testLoopCmd.AddCommand(newTestLoopPublicCommand().cmd) } type testLoopPublicCommand struct { @@ -50,22 +50,22 @@ func newTestLoopPublicCommand() *testLoopPublicCommand { cmd := &cobra.Command{ Use: "public", Short: "Start a loop agent testing public proxy shares", - Args: cobra.ExactArgs(0), + Args: cobra.NoArgs, } - r := &testLoopPublicCommand{cmd: cmd} - cmd.Run = r.run - cmd.Flags().IntVarP(&r.loopers, "loopers", "l", 1, "Number of current loopers to start") - cmd.Flags().IntVarP(&r.iterations, "iterations", "i", 1, "Number of iterations per looper") - cmd.Flags().IntVarP(&r.statusEvery, "status-every", "E", 100, "Show status every # iterations") - cmd.Flags().IntVarP(&r.timeoutSeconds, "timeout-seconds", "T", 30, "Time out after # seconds when sending http requests") - cmd.Flags().IntVar(&r.minPayload, "min-payload", 64, "Minimum payload size in bytes") - cmd.Flags().IntVar(&r.maxPayload, "max-payload", 10240, "Maximum payload size in bytes") - cmd.Flags().IntVar(&r.minDwellMs, "min-dwell-ms", 1000, "Minimum dwell time in milliseconds") - cmd.Flags().IntVar(&r.maxDwellMs, "max-dwell-ms", 1000, "Maximum dwell time in milliseconds") - cmd.Flags().IntVar(&r.minPacingMs, "min-pacing-ms", 0, "Minimum pacing in milliseconds") - cmd.Flags().IntVar(&r.maxPacingMs, "max-pacing-ms", 0, "Maximum pacing in milliseconds") - cmd.Flags().StringArrayVar(&r.frontendSelection, "frontends", []string{"public"}, "Selected frontends to use for the share") - return r + command := &testLoopPublicCommand{cmd: cmd} + cmd.Run = command.run + cmd.Flags().IntVarP(&command.loopers, "loopers", "l", 1, "Number of current loopers to start") + cmd.Flags().IntVarP(&command.iterations, "iterations", "i", 1, "Number of iterations per looper") + cmd.Flags().IntVarP(&command.statusEvery, "status-every", "E", 100, "Show status every # iterations") + cmd.Flags().IntVarP(&command.timeoutSeconds, "timeout-seconds", "T", 30, "Time out after # seconds when sending http requests") + cmd.Flags().IntVar(&command.minPayload, "min-payload", 64, "Minimum payload size in bytes") + cmd.Flags().IntVar(&command.maxPayload, "max-payload", 10240, "Maximum payload size in bytes") + cmd.Flags().IntVar(&command.minDwellMs, "min-dwell-ms", 1000, "Minimum dwell time in milliseconds") + cmd.Flags().IntVar(&command.maxDwellMs, "max-dwell-ms", 1000, "Maximum dwell time in milliseconds") + cmd.Flags().IntVar(&command.minPacingMs, "min-pacing-ms", 0, "Minimum pacing in milliseconds") + cmd.Flags().IntVar(&command.maxPacingMs, "max-pacing-ms", 0, "Maximum pacing in milliseconds") + cmd.Flags().StringArrayVar(&command.frontendSelection, "frontends", []string{"public"}, "Selected frontends to use for the share") + return command } func (cmd *testLoopPublicCommand) run(_ *cobra.Command, _ []string) {