-
Notifications
You must be signed in to change notification settings - Fork 1
[proxy]: Resolve upstreams per request from namespace and metadata #81
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
Changes from all commits
Commits
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
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,83 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "context" | ||
| "net" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "go.temporal.io/api/workflowservice/v1" | ||
| "google.golang.org/grpc" | ||
| "google.golang.org/grpc/metadata" | ||
|
|
||
| "github.com/temporalio/temporal-proxy/internal/config" | ||
| ) | ||
|
|
||
| // TestEndToEndTemplatedUpstreamRoutesByRenderedAddress drives the full stack | ||
| // with a single templated upstream whose hostPort renders from request | ||
| // metadata, and proves each request reaches the upstream its metadata names. | ||
| // This exercises per-request address rendering end to end, and because two | ||
| // distinct rendered targets are both reached, it also proves the connection | ||
| // pool keys by rendered target rather than collapsing onto the first dial. | ||
| func TestEndToEndTemplatedUpstreamRoutesByRenderedAddress(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| svcA, addrA := newFakeUpstream(t) | ||
| svcB, addrB := newFakeUpstream(t) | ||
|
|
||
| inboundAddr := freeTCPAddr(t) | ||
| app := newFullApp(t, &config.Config{ | ||
| Listen: config.ListenConfig{HostPort: inboundAddr}, | ||
| Routing: config.Routing{DefaultUpstream: "dynamic"}, | ||
| Upstreams: []config.Upstream{{ | ||
| Name: "dynamic", | ||
| Listen: config.ListenConfig{HostPort: `{{ index .Metadata "x-upstream" }}`}, | ||
| }}, | ||
| }) | ||
| require.NoError(t, app.Err()) | ||
|
|
||
| startCtx, cancel := context.WithTimeout(t.Context(), 5*time.Second) | ||
| defer cancel() | ||
| require.NoError(t, app.Start(startCtx)) | ||
| t.Cleanup(func() { | ||
| stopCtx, stopCancel := context.WithTimeout(t.Context(), 5*time.Second) | ||
| defer stopCancel() | ||
| _ = app.Stop(stopCtx) | ||
| }) | ||
|
|
||
| conn := dialInbound(t, inboundAddr) | ||
| defer func() { _ = conn.Close() }() | ||
| client := workflowservice.NewWorkflowServiceClient(conn) | ||
|
|
||
| call := func(target string) { | ||
| ctx := metadata.AppendToOutgoingContext(startCtx, "x-upstream", target) | ||
| _, err := client.GetSystemInfo(ctx, &workflowservice.GetSystemInfoRequest{}, grpc.WaitForReady(true)) | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| call(addrA) | ||
| call(addrB) | ||
|
|
||
| require.NotNil(t, svcA.received(), "the request naming upstream A must reach A") | ||
| require.NotNil(t, svcB.received(), "the request naming upstream B must reach B") | ||
| require.Equal(t, []string{addrA}, svcA.received().Get("x-upstream")) | ||
| require.Equal(t, []string{addrB}, svcB.received().Get("x-upstream")) | ||
| } | ||
|
|
||
| // newFakeUpstream stands up a plaintext fake WorkflowService frontend and | ||
| // returns it with its dial address. | ||
| func newFakeUpstream(t *testing.T) (*capturingWorkflowService, string) { | ||
| t.Helper() | ||
|
|
||
| svc := &capturingWorkflowService{} | ||
| srv := grpc.NewServer() | ||
| workflowservice.RegisterWorkflowServiceServer(srv, svc) | ||
|
|
||
| lis, err := net.Listen("tcp", "127.0.0.1:0") | ||
| require.NoError(t, err) | ||
| go func() { _ = srv.Serve(lis) }() | ||
| t.Cleanup(srv.Stop) | ||
|
|
||
| return svc, lis.Addr().String() | ||
| } |
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.