Skip to content

Commit cd2bdee

Browse files
authored
Updates to partition config middleware (#5334)
1 parent bc8bebe commit cd2bdee

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

common/rpc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ const (
5656
// IsolationGroupHeaderName refers to the name of the header that contains the isolation group of the client
5757
IsolationGroupHeaderName = "cadence-worker-isolation-group"
5858

59-
// ClientZoneHeaderName refers to the name of the header that contaains the zone which the client request is from
60-
ClientZoneHeaderName = "cadence-client-zone"
59+
// ClientIsolationGroupHeaderName refers to the name of the header that contains the isolation group which the client request is from
60+
ClientIsolationGroupHeaderName = "cadence-client-isolation-group"
6161
)
6262

6363
type (

common/rpc/middleware.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ func (m *ForwardPartitionConfigMiddleware) Call(ctx context.Context, request *tr
224224
return out.Call(ctx, request)
225225
}
226226

227-
// ZonalPartitionConfigMiddleware stores the partition config and isolation group of the request into the context
228-
// It reads a header from client request which indicates the zone which the request is from and uses it as the isolation group
229-
type ZonalPartitionConfigMiddleware struct{}
227+
// ClientPartitionConfigMiddleware stores the partition config and isolation group of the request into the context
228+
// It reads a header from client request and uses it as the isolation group
229+
type ClientPartitionConfigMiddleware struct{}
230230

231-
func (m *ZonalPartitionConfigMiddleware) Handle(ctx context.Context, req *transport.Request, resw transport.ResponseWriter, h transport.UnaryHandler) error {
232-
zone, _ := req.Headers.Get(common.ClientZoneHeaderName)
231+
func (m *ClientPartitionConfigMiddleware) Handle(ctx context.Context, req *transport.Request, resw transport.ResponseWriter, h transport.UnaryHandler) error {
232+
zone, _ := req.Headers.Get(common.ClientIsolationGroupHeaderName)
233233
if zone != "" {
234234
ctx = partition.ContextWithConfig(ctx, map[string]string{
235235
partition.IsolationGroupKey: zone,

common/rpc/middleware_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,20 +304,20 @@ func TestForwardPartitionConfigMiddleware(t *testing.T) {
304304
})
305305
}
306306

307-
func TestZonalPartitionConfigMiddleware(t *testing.T) {
307+
func TestClientPartitionConfigMiddleware(t *testing.T) {
308308
t.Run("it sets the partition config", func(t *testing.T) {
309-
m := &ZonalPartitionConfigMiddleware{}
309+
m := &ClientPartitionConfigMiddleware{}
310310
h := &fakeHandler{}
311311
headers := transport.NewHeaders().
312-
With(common.ClientZoneHeaderName, "dca1")
312+
With(common.ClientIsolationGroupHeaderName, "dca1")
313313
err := m.Handle(context.Background(), &transport.Request{Headers: headers}, nil, h)
314314
assert.NoError(t, err)
315315
assert.Equal(t, map[string]string{partition.IsolationGroupKey: "dca1"}, partition.ConfigFromContext(h.ctx))
316316
assert.Equal(t, "dca1", partition.IsolationGroupFromContext(h.ctx))
317317
})
318318

319319
t.Run("noop when header is empty", func(t *testing.T) {
320-
m := &ZonalPartitionConfigMiddleware{}
320+
m := &ClientPartitionConfigMiddleware{}
321321
h := &fakeHandler{}
322322
headers := transport.NewHeaders()
323323
ctx := context.Background()

common/rpc/params.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,13 @@ func NewParams(serviceName string, config *config.Config, dc *dynamicconfig.Coll
132132
InboundTLS: inboundTLS,
133133
OutboundTLS: outboundTLS,
134134
InboundMiddleware: yarpc.InboundMiddleware{
135-
Unary: &InboundMetricsMiddleware{},
135+
// order matters: ForwardPartitionConfigMiddleware must be applied after ClientPartitionConfigMiddleware
136+
Unary: yarpc.UnaryInboundMiddleware(&InboundMetricsMiddleware{}, &ClientPartitionConfigMiddleware{}, &ForwardPartitionConfigMiddleware{}),
136137
},
137138
OutboundMiddleware: yarpc.OutboundMiddleware{
138-
Unary: &HeaderForwardingMiddleware{
139+
Unary: yarpc.UnaryOutboundMiddleware(&HeaderForwardingMiddleware{
139140
Rules: forwardingRules,
140-
},
141+
}, &ForwardPartitionConfigMiddleware{}),
141142
},
142143
}, nil
143144
}

0 commit comments

Comments
 (0)