-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
add support for vtgate traffic mirroring #15945
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
79983de
add support for vtgate traffic mirroring (topo, workflow)
maxenglander c9430d0
cr: rename var, extract common test code to helper fn
maxenglander 02113ff
merge <- main
maxenglander a9dbf34
update tests
maxenglander a0cffe5
Update go/cmd/vtctldclient/command/vreplication/common/mirrortraffic.go
maxenglander 859b421
Update go/cmd/vtctldclient/command/vreplication/common/mirrortraffic.go
maxenglander 71b9a00
cr: test repeat calls to mirror traffic
maxenglander 446445c
cr: remove ApplyMirrorRules vtctldclient command
maxenglander 91a75e4
Merge branch 'main' into maxeng-mirror-routingrules
maxenglander 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 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 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 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,58 @@ | ||
/* | ||
Copyright 2024 The Vitess Authors. | ||
|
||
Licensed 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 command | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"vitess.io/vitess/go/cmd/vtctldclient/cli" | ||
|
||
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" | ||
) | ||
|
||
// GetMirrorRules makes a GetMirrorRules gRPC call to a vtctld. | ||
var GetMirrorRules = &cobra.Command{ | ||
Use: "GetMirrorRules", | ||
Short: "Displays the VSchema mirror rules.", | ||
DisableFlagsInUseLine: true, | ||
Args: cobra.NoArgs, | ||
RunE: commandGetMirrorRules, | ||
} | ||
|
||
func commandGetMirrorRules(cmd *cobra.Command, args []string) error { | ||
cli.FinishedParsing(cmd) | ||
|
||
resp, err := client.GetMirrorRules(commandCtx, &vtctldatapb.GetMirrorRulesRequest{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
data, err := cli.MarshalJSON(resp.MirrorRules) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("%s\n", data) | ||
|
||
return nil | ||
} | ||
|
||
func init() { | ||
Root.AddCommand(GetMirrorRules) | ||
} |
89 changes: 89 additions & 0 deletions
89
go/cmd/vtctldclient/command/vreplication/common/mirrortraffic.go
This file contains 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,89 @@ | ||
/* | ||
Copyright 2024 The Vitess Authors. | ||
|
||
Licensed 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 common | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"vitess.io/vitess/go/cmd/vtctldclient/cli" | ||
|
||
topodatapb "vitess.io/vitess/go/vt/proto/topodata" | ||
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" | ||
) | ||
|
||
func GetMirrorTrafficCommand(opts *SubCommandsOpts) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "mirrortraffic", | ||
Short: fmt.Sprintf("Mirror traffic for a %s MoveTables workflow.", opts.SubCommand), | ||
Example: fmt.Sprintf(`vtctldclient --server localhost:15999 %s --workflow %s --target-keyspace customer mirrortraffic --percent 5.0`, opts.SubCommand, opts.Workflow), | ||
DisableFlagsInUseLine: true, | ||
Aliases: []string{"MirrorTraffic"}, | ||
Args: cobra.NoArgs, | ||
PreRun: func(cmd *cobra.Command, args []string) { | ||
if !cmd.Flags().Lookup("tablet-types").Changed { | ||
// We mirror traffic for all tablet types if none are provided. | ||
MirrorTrafficOptions.TabletTypes = []topodatapb.TabletType{ | ||
topodatapb.TabletType_PRIMARY, | ||
topodatapb.TabletType_REPLICA, | ||
topodatapb.TabletType_RDONLY, | ||
} | ||
} | ||
}, | ||
RunE: commandMirrorTraffic, | ||
} | ||
return cmd | ||
} | ||
|
||
func commandMirrorTraffic(cmd *cobra.Command, args []string) error { | ||
format, err := GetOutputFormat(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cli.FinishedParsing(cmd) | ||
|
||
req := &vtctldatapb.WorkflowMirrorTrafficRequest{ | ||
Keyspace: BaseOptions.TargetKeyspace, | ||
Workflow: BaseOptions.Workflow, | ||
TabletTypes: MirrorTrafficOptions.TabletTypes, | ||
Percent: MirrorTrafficOptions.Percent, | ||
} | ||
resp, err := GetClient().WorkflowMirrorTraffic(GetCommandCtx(), req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var output []byte | ||
if format == "json" { | ||
output, err = cli.MarshalJSONPretty(resp) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
tout := bytes.Buffer{} | ||
tout.WriteString(resp.Summary + "\n\n") | ||
tout.WriteString(fmt.Sprintf("Start State: %s\n", resp.StartState)) | ||
tout.WriteString(fmt.Sprintf("Current State: %s\n", resp.CurrentState)) | ||
output = tout.Bytes() | ||
} | ||
fmt.Printf("%s\n", output) | ||
|
||
return nil | ||
} |
This file contains 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 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 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
114 changes: 114 additions & 0 deletions
114
go/test/endtoend/vreplication/movetables_mirrortraffic_test.go
This file contains 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,114 @@ | ||
/* | ||
Copyright 2024 The Vitess Authors. | ||
|
||
Licensed 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 vreplication | ||
|
||
import ( | ||
"testing" | ||
|
||
binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata" | ||
topodatapb "vitess.io/vitess/go/vt/proto/topodata" | ||
) | ||
|
||
func testMoveTablesMirrorTraffic(t *testing.T, flavor workflowFlavor) { | ||
setSidecarDBName("_vt") | ||
vc = setupMinimalCluster(t) | ||
defer vc.TearDown() | ||
|
||
sourceKeyspace := "product" | ||
targetKeyspace := "customer" | ||
workflowName := "wf1" | ||
tables := []string{"customer", "loadtest", "customer2"} | ||
|
||
_ = setupMinimalCustomerKeyspace(t) | ||
|
||
mtwf := &moveTablesWorkflow{ | ||
workflowInfo: &workflowInfo{ | ||
vc: vc, | ||
workflowName: workflowName, | ||
targetKeyspace: targetKeyspace, | ||
}, | ||
sourceKeyspace: sourceKeyspace, | ||
tables: "customer,loadtest,customer2", | ||
mirrorFlags: []string{"--percent", "25"}, | ||
} | ||
mt := newMoveTables(vc, mtwf, flavor) | ||
|
||
// Mirror rules do not exist by default. | ||
mt.Create() | ||
confirmNoMirrorRules(t) | ||
|
||
waitForWorkflowState(t, vc, ksWorkflow, binlogdatapb.VReplicationWorkflowState_Running.String()) | ||
|
||
// Mirror rules can be created after a MoveTables workflow is created. | ||
mt.MirrorTraffic() | ||
confirmMirrorRulesExist(t) | ||
expectMirrorRules(t, sourceKeyspace, targetKeyspace, tables, []topodatapb.TabletType{ | ||
topodatapb.TabletType_PRIMARY, | ||
topodatapb.TabletType_REPLICA, | ||
topodatapb.TabletType_RDONLY, | ||
}, 25) | ||
|
||
// Mirror rules can be adjusted after mirror rules are in place. | ||
mtwf.mirrorFlags[1] = "50" | ||
mt.MirrorTraffic() | ||
confirmMirrorRulesExist(t) | ||
expectMirrorRules(t, sourceKeyspace, targetKeyspace, tables, []topodatapb.TabletType{ | ||
topodatapb.TabletType_PRIMARY, | ||
topodatapb.TabletType_REPLICA, | ||
topodatapb.TabletType_RDONLY, | ||
}, 50) | ||
|
||
// Mirror rules can be adjusted multiple times after mirror rules are in | ||
// place. | ||
mtwf.mirrorFlags[1] = "75" | ||
mt.MirrorTraffic() | ||
confirmMirrorRulesExist(t) | ||
expectMirrorRules(t, sourceKeyspace, targetKeyspace, tables, []topodatapb.TabletType{ | ||
topodatapb.TabletType_PRIMARY, | ||
topodatapb.TabletType_REPLICA, | ||
topodatapb.TabletType_RDONLY, | ||
}, 75) | ||
|
||
lg := newLoadGenerator(t, vc) | ||
go func() { | ||
lg.start() | ||
}() | ||
lg.waitForCount(1000) | ||
|
||
mt.SwitchReads() | ||
confirmMirrorRulesExist(t) | ||
|
||
// Mirror rules can be adjusted for writes after reads have been switched. | ||
mtwf.mirrorFlags[1] = "100" | ||
mtwf.mirrorFlags = append(mtwf.mirrorFlags, "--tablet-types", "primary") | ||
mt.MirrorTraffic() | ||
confirmMirrorRulesExist(t) | ||
expectMirrorRules(t, sourceKeyspace, targetKeyspace, tables, []topodatapb.TabletType{ | ||
topodatapb.TabletType_PRIMARY, | ||
}, 100) | ||
|
||
// Mirror rules are removed after writes are switched. | ||
mt.SwitchWrites() | ||
confirmNoMirrorRules(t) | ||
} | ||
|
||
func TestMoveTablesMirrorTraffic(t *testing.T) { | ||
currentWorkflowType = binlogdatapb.VReplicationWorkflowType_MoveTables | ||
t.Run(workflowFlavorNames[workflowFlavorVtctld], func(t *testing.T) { | ||
testMoveTablesMirrorTraffic(t, workflowFlavorVtctld) | ||
}) | ||
} |
This file contains 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 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does switching traffic delete mirror rules? Interesting, but also seems correct. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, i think you suggested that during one of the Vitess team meetings i attended, unless i misunderstood 😅