-
Notifications
You must be signed in to change notification settings - Fork 7
Better chaos #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Better chaos #178
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "slices" | ||
|
|
||
| "github.com/couchbaselabs/cbdinocluster/utils/clustercontrol" | ||
| "github.com/spf13/cobra" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| var chaosPickNodeCmd = &cobra.Command{ | ||
| Use: "pick-node <cluster-id>", | ||
| Short: "Picks a single non-orchestrator node from the cluster for chaos testing", | ||
| Args: cobra.ExactArgs(1), | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| helper := CmdHelper{} | ||
| logger := helper.GetLogger() | ||
| ctx := helper.GetContext() | ||
|
|
||
| clusterId := args[0] | ||
| selectOrchestrator, _ := cmd.Flags().GetBool("orchestrator") | ||
|
|
||
| _, _, cluster := helper.IdentifyCluster(ctx, clusterId) | ||
|
|
||
| // collect only cluster nodes (exclude utility nodes like load balancers) | ||
| type candidateNode struct { | ||
| ID string | ||
| IPAddress string | ||
| } | ||
|
|
||
| var candidates []candidateNode | ||
| for _, node := range cluster.GetNodes() { | ||
| if !node.IsClusterNode() { | ||
| continue | ||
| } | ||
| candidates = append(candidates, candidateNode{ | ||
| ID: node.GetID(), | ||
| IPAddress: node.GetIPAddress(), | ||
| }) | ||
| } | ||
|
|
||
| if len(candidates) == 0 { | ||
| logger.Fatal("no cluster nodes found") | ||
| } | ||
|
|
||
| // sort for deterministic selection | ||
| slices.SortFunc(candidates, func(a, b candidateNode) int { | ||
| if a.ID < b.ID { | ||
| return -1 | ||
| } | ||
| if a.ID > b.ID { | ||
| return 1 | ||
| } | ||
| return 0 | ||
| }) | ||
|
|
||
| // query ns_server to find the orchestrator | ||
| firstNodeIP := candidates[0].IPAddress | ||
| ctrl := &clustercontrol.Controller{ | ||
| Logger: logger, | ||
| Endpoint: fmt.Sprintf("http://%s:8091", firstNodeIP), | ||
| } | ||
|
|
||
| terseInfo, err := ctrl.GetTerseClusterInfo(ctx) | ||
| if err != nil { | ||
| logger.Fatal("failed to get terse cluster info", zap.Error(err)) | ||
| } | ||
|
|
||
| orchestratorOTP := terseInfo.Orchestrator | ||
|
|
||
| // resolve orchestrator OTP to a node IP by querying each node | ||
| var orchestratorIP string | ||
| for _, c := range candidates { | ||
| nodeCtrl := &clustercontrol.Controller{ | ||
| Logger: logger, | ||
| Endpoint: fmt.Sprintf("http://%s:8091", c.IPAddress), | ||
| } | ||
|
|
||
| localInfo, err := nodeCtrl.GetLocalInfo(ctx) | ||
| if err != nil { | ||
| logger.Warn("failed to get local info for node, skipping", | ||
| zap.String("node", c.ID), | ||
| zap.Error(err)) | ||
| continue | ||
| } | ||
|
|
||
| if localInfo.OTPNode == orchestratorOTP { | ||
| orchestratorIP = c.IPAddress | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if selectOrchestrator { | ||
| // select the orchestrator specifically | ||
| if orchestratorIP == "" { | ||
| logger.Fatal("could not identify orchestrator node") | ||
| } | ||
|
|
||
| var orchestrator *candidateNode | ||
| for _, c := range candidates { | ||
| if c.IPAddress == orchestratorIP { | ||
| foundOrchestrator := c | ||
| orchestrator = &foundOrchestrator | ||
| break | ||
| } | ||
| } | ||
|
|
||
| candidates = []candidateNode{*orchestrator} | ||
| } else { | ||
| // exclude the orchestrator (default behavior) | ||
| if orchestratorIP != "" { | ||
| var filtered []candidateNode | ||
| for _, c := range candidates { | ||
| if c.IPAddress != orchestratorIP { | ||
| filtered = append(filtered, c) | ||
| } | ||
| } | ||
| candidates = filtered | ||
| } else { | ||
| logger.Warn("could not identify orchestrator node, selecting from all nodes") | ||
| } | ||
|
|
||
| if len(candidates) == 0 { | ||
| logger.Fatal("no eligible nodes after excluding orchestrator") | ||
| } | ||
| } | ||
|
|
||
| selected := candidates[0] | ||
| fmt.Println(selected.ID) | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| chaosCmd.AddCommand(chaosPickNodeCmd) | ||
|
|
||
| chaosPickNodeCmd.Flags().Bool("orchestrator", false, "Select the orchestrator node instead of a non-orchestrator") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| var clusterSettingsDisableAutoFailoverCmd = &cobra.Command{ | ||
| Use: "disable-autofailover <cluster-id>", | ||
| Short: "Disables auto-failover for a cluster", | ||
| Args: cobra.ExactArgs(1), | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| helper := CmdHelper{} | ||
| logger := helper.GetLogger() | ||
| ctx := helper.GetContext() | ||
|
|
||
| clusterId := args[0] | ||
|
|
||
| _, deployer, cluster := helper.IdentifyCluster(ctx, clusterId) | ||
|
|
||
| err := deployer.SetAutoFailover(ctx, cluster.GetID(), false, 0) | ||
| if err != nil { | ||
| logger.Fatal("failed to disable auto-failover", zap.Error(err)) | ||
| } | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| clusterSettingsCmd.AddCommand(clusterSettingsDisableAutoFailoverCmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| var clusterSettingsEnableAutoFailoverCmd = &cobra.Command{ | ||
| Use: "enable-autofailover <cluster-id>", | ||
| Short: "Enables auto-failover for a cluster", | ||
| Args: cobra.ExactArgs(1), | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| helper := CmdHelper{} | ||
| logger := helper.GetLogger() | ||
| ctx := helper.GetContext() | ||
|
|
||
| clusterId := args[0] | ||
| timeout, _ := cmd.Flags().GetInt("timeout") | ||
|
|
||
| _, deployer, cluster := helper.IdentifyCluster(ctx, clusterId) | ||
|
|
||
| err := deployer.SetAutoFailover(ctx, cluster.GetID(), true, timeout) | ||
| if err != nil { | ||
| logger.Fatal("failed to enable auto-failover", zap.Error(err)) | ||
| } | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| clusterSettingsCmd.AddCommand(clusterSettingsEnableAutoFailoverCmd) | ||
|
|
||
| clusterSettingsEnableAutoFailoverCmd.Flags().Int("timeout", 120, "Auto-failover timeout in seconds") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var clusterSettingsCmd = &cobra.Command{ | ||
| Use: "cluster-settings", | ||
| Short: "Provides cluster settings management tools", | ||
| Run: nil, | ||
| } | ||
|
|
||
| func init() { | ||
| rootCmd.AddCommand(clusterSettingsCmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.