-
Notifications
You must be signed in to change notification settings - Fork 870
feat(shard-distributor): Add ping verification to ephemeral shard creator #7496
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
jakobht
merged 6 commits into
cadence-workflow:master
from
jakobht:add-ephemeral-shard-ping
Dec 5, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3a5d593
Add ping verification to ephemeral shard creator
jakobht 0f6256f
Wire up canary ping/pong components in module
jakobht 7a98d3a
We now use the interface correctly to create and ping shards in one go
jakobht 8998fb4
the pinging for fixed namespaces now works
jakobht 843f27a
Fixed unit test
jakobht 150093f
Small fix to the initializaiton
jakobht 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 |
|---|---|---|
| @@ -1,21 +1,27 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net" | ||
| "os" | ||
| "time" | ||
|
|
||
| "github.com/uber-go/tally" | ||
| "github.com/urfave/cli/v2" | ||
| "go.uber.org/fx" | ||
| "go.uber.org/yarpc" | ||
| "go.uber.org/yarpc/api/peer" | ||
| "go.uber.org/yarpc/transport/grpc" | ||
| "go.uber.org/zap" | ||
|
|
||
| sharddistributorv1 "github.com/uber/cadence/.gen/proto/sharddistributor/v1" | ||
| "github.com/uber/cadence/common/clock" | ||
| "github.com/uber/cadence/common/log" | ||
| "github.com/uber/cadence/service/sharddistributor/canary" | ||
| "github.com/uber/cadence/service/sharddistributor/canary/executors" | ||
| "github.com/uber/cadence/service/sharddistributor/client/clientcommon" | ||
| "github.com/uber/cadence/service/sharddistributor/client/executorclient" | ||
| "github.com/uber/cadence/service/sharddistributor/client/spectatorclient" | ||
| "github.com/uber/cadence/service/sharddistributor/config" | ||
| "github.com/uber/cadence/tools/common/commoncli" | ||
| ) | ||
|
|
@@ -25,6 +31,7 @@ const ( | |
| defaultShardDistributorEndpoint = "127.0.0.1:7943" | ||
| defaultFixedNamespace = "shard-distributor-canary" | ||
| defaultEphemeralNamespace = "shard-distributor-canary-ephemeral" | ||
| defaultCanaryGRPCPort = 7953 // Port for canary to receive ping requests | ||
|
|
||
| shardDistributorServiceName = "cadence-shard-distributor" | ||
| ) | ||
|
|
@@ -33,11 +40,12 @@ func runApp(c *cli.Context) { | |
| endpoint := c.String("endpoint") | ||
| fixedNamespace := c.String("fixed-namespace") | ||
| ephemeralNamespace := c.String("ephemeral-namespace") | ||
| canaryGRPCPort := c.Int("canary-grpc-port") | ||
|
|
||
| fx.New(opts(fixedNamespace, ephemeralNamespace, endpoint)).Run() | ||
| fx.New(opts(fixedNamespace, ephemeralNamespace, endpoint, canaryGRPCPort)).Run() | ||
| } | ||
|
|
||
| func opts(fixedNamespace, ephemeralNamespace, endpoint string) fx.Option { | ||
| func opts(fixedNamespace, ephemeralNamespace, endpoint string, canaryGRPCPort int) fx.Option { | ||
| configuration := clientcommon.Config{ | ||
| Namespaces: []clientcommon.NamespaceConfig{ | ||
| {Namespace: fixedNamespace, HeartBeatInterval: 1 * time.Second, MigrationMode: config.MigrationModeONBOARDED}, | ||
|
|
@@ -49,22 +57,51 @@ func opts(fixedNamespace, ephemeralNamespace, endpoint string) fx.Option { | |
| }, | ||
| } | ||
|
|
||
| canaryGRPCAddress := fmt.Sprintf("127.0.0.1:%d", canaryGRPCPort) | ||
|
|
||
| // Create listener for GRPC inbound | ||
| listener, err := net.Listen("tcp", canaryGRPCAddress) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| transport := grpc.NewTransport() | ||
| yarpcConfig := yarpc.Config{ | ||
| Name: "shard-distributor-canary", | ||
| Outbounds: yarpc.Outbounds{ | ||
| shardDistributorServiceName: { | ||
| Unary: transport.NewSingleOutbound(endpoint), | ||
| }, | ||
| }, | ||
|
|
||
| executorMetadata := executorclient.ExecutorMetadata{ | ||
| clientcommon.GrpcAddressMetadataKey: canaryGRPCAddress, | ||
| } | ||
|
|
||
| return fx.Options( | ||
| fx.Supply( | ||
| fx.Annotate(tally.NoopScope, fx.As(new(tally.Scope))), | ||
| fx.Annotate(clock.NewRealTimeSource(), fx.As(new(clock.TimeSource))), | ||
| yarpcConfig, | ||
| configuration, | ||
| transport, | ||
| executorMetadata, | ||
| ), | ||
|
|
||
| fx.Provide(func(peerChooser spectatorclient.SpectatorPeerChooserInterface) yarpc.Config { | ||
| return yarpc.Config{ | ||
| Name: "shard-distributor-canary", | ||
| Inbounds: yarpc.Inbounds{ | ||
| transport.NewInbound(listener), // Listen for incoming ping requests | ||
| }, | ||
| Outbounds: yarpc.Outbounds{ | ||
| shardDistributorServiceName: { | ||
| Unary: transport.NewSingleOutbound(endpoint), | ||
| Stream: transport.NewSingleOutbound(endpoint), | ||
| }, | ||
| // canary-to-canary outbound uses peer chooser to route to other canary instances | ||
| "shard-distributor-canary": { | ||
| Unary: transport.NewOutbound(peerChooser), | ||
| Stream: transport.NewOutbound(peerChooser), | ||
| }, | ||
| }, | ||
| } | ||
| }), | ||
|
|
||
| fx.Provide( | ||
| func(t *grpc.Transport) peer.Transport { return t }, | ||
| ), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have transport in fx.supply, do we need this? it seems redundant |
||
| fx.Provide( | ||
| yarpc.NewDispatcher, | ||
|
|
@@ -73,12 +110,17 @@ func opts(fixedNamespace, ephemeralNamespace, endpoint string) fx.Option { | |
| fx.Provide(zap.NewDevelopment), | ||
| fx.Provide(log.NewLogger), | ||
|
|
||
| // Register canary procedures with dispatcher | ||
| fx.Invoke(func(dispatcher *yarpc.Dispatcher, server sharddistributorv1.ShardDistributorExecutorCanaryAPIYARPCServer) { | ||
| dispatcher.Register(sharddistributorv1.BuildShardDistributorExecutorCanaryAPIYARPCProcedures(server)) | ||
| }), | ||
|
|
||
| // Start the YARPC dispatcher | ||
| fx.Invoke(func(lc fx.Lifecycle, dispatcher *yarpc.Dispatcher) { | ||
| lc.Append(fx.StartStopHook(dispatcher.Start, dispatcher.Stop)) | ||
| }), | ||
|
|
||
| // Include the canary module | ||
| // Include the canary module - it will set up spectator peer choosers and canary client | ||
| canary.Module(canary.NamespacesNames{FixedNamespace: fixedNamespace, EphemeralNamespace: ephemeralNamespace, ExternalAssignmentNamespace: executors.ExternalAssignmentNamespace, SharddistributorServiceName: shardDistributorServiceName}), | ||
| ) | ||
| } | ||
|
|
@@ -110,6 +152,11 @@ func buildCLI() *cli.App { | |
| Value: defaultEphemeralNamespace, | ||
| Usage: "namespace for ephemeral shard creation testing", | ||
| }, | ||
| &cli.IntFlag{ | ||
| Name: "canary-grpc-port", | ||
| Value: defaultCanaryGRPCPort, | ||
| Usage: "port for canary to receive ping requests", | ||
| }, | ||
| }, | ||
| Action: func(c *cli.Context) error { | ||
| runApp(c) | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package pinger | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| "go.uber.org/yarpc" | ||
| "go.uber.org/zap" | ||
|
|
||
| sharddistributorv1 "github.com/uber/cadence/.gen/proto/sharddistributor/v1" | ||
| "github.com/uber/cadence/service/sharddistributor/client/spectatorclient" | ||
| ) | ||
|
|
||
| const ( | ||
| pingTimeout = 5 * time.Second | ||
| ) | ||
|
|
||
| func PingShard(ctx context.Context, canaryClient sharddistributorv1.ShardDistributorExecutorCanaryAPIYARPCClient, logger *zap.Logger, namespace, shardKey string) { | ||
| request := &sharddistributorv1.PingRequest{ | ||
| ShardKey: shardKey, | ||
| Namespace: namespace, | ||
| } | ||
|
|
||
| ctx, cancel := context.WithTimeout(ctx, pingTimeout) | ||
| defer cancel() | ||
|
|
||
| response, err := canaryClient.Ping(ctx, request, yarpc.WithShardKey(shardKey), yarpc.WithHeader(spectatorclient.NamespaceHeader, namespace)) | ||
| if err != nil { | ||
| logger.Error("Failed to ping shard", zap.String("namespace", namespace), zap.String("shard_key", shardKey), zap.Error(err)) | ||
| return | ||
| } | ||
|
|
||
| // Verify response | ||
| if !response.GetOwnsShard() { | ||
| logger.Warn("Executor does not own shard", zap.String("namespace", namespace), zap.String("shard_key", shardKey), zap.String("executor_id", response.GetExecutorId())) | ||
| return | ||
| } | ||
|
|
||
| logger.Info("Successfully pinged shard owner", zap.String("namespace", namespace), zap.String("shard_key", shardKey), zap.String("executor_id", response.GetExecutorId())) | ||
| } |
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.
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.
we have transport in fx.supply, do we need this? it seems redundant