Skip to content

Commit 58f9746

Browse files
Adding in additional header to determine a more stable isolation-group (#1252)
* Adding in additional header as a config option to determine a more stable isolation-group
1 parent 407a703 commit 58f9746

File tree

9 files changed

+753
-6
lines changed

9 files changed

+753
-6
lines changed

evictiontest/workflow_cache_eviction_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func callOptions() []interface{} {
5757
gomock.Any(), // feature version
5858
gomock.Any(), // client name
5959
gomock.Any(), // feature flags
60+
gomock.Any(), // isolation group
6061
}
6162
}
6263

@@ -176,6 +177,7 @@ func (s *CacheEvictionSuite) TestResetStickyOnEviction() {
176177
workflowWorker := internal.NewWorker(s.service, "test-domain", "tasklist", worker.Options{
177178
DisableActivityWorker: true,
178179
Logger: zaptest.NewLogger(s.T()),
180+
IsolationGroup: "zone-1",
179181
})
180182
// this is an arbitrary workflow we use for this test
181183
// NOTE: a simple helloworld that doesn't execute an activity

internal/client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"context"
2626
"fmt"
2727
"time"
28+
"go.uber.org/cadence/internal/common/isolationgroup"
2829

2930
"github.com/opentracing/opentracing-go"
3031
"github.com/uber-go/tally"
@@ -358,6 +359,7 @@ type (
358359
ClientOptions struct {
359360
MetricsScope tally.Scope
360361
Identity string
362+
IsolationGroup string
361363
DataConverter DataConverter
362364
Tracer opentracing.Tracer
363365
ContextPropagators []ContextPropagator
@@ -578,6 +580,9 @@ func NewClient(service workflowserviceclient.Interface, domain string, options *
578580
if options != nil && options.Authorization != nil {
579581
service = auth.NewWorkflowServiceWrapper(service, options.Authorization)
580582
}
583+
if options != nil && options.IsolationGroup != "" {
584+
service = isolationgroup.NewWorkflowServiceWrapper(service, options.IsolationGroup)
585+
}
581586
service = metrics.NewWorkflowServiceWrapper(service, metricScope)
582587
return &workflowClient{
583588
workflowService: service,

internal/common/isolationgroup/service_wrapper.go

Lines changed: 295 additions & 0 deletions
Large diffs are not rendered by default.

internal/common/isolationgroup/service_wrapper_test.go

Lines changed: 405 additions & 0 deletions
Large diffs are not rendered by default.

internal/internal_worker.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import (
3838
"sync"
3939
"time"
4040

41+
"go.uber.org/cadence/internal/common/isolationgroup"
42+
4143
"github.com/opentracing/opentracing-go"
4244
"github.com/pborman/uuid"
4345
"github.com/uber-go/tally"
@@ -992,6 +994,9 @@ func newAggregatedWorker(
992994
if options.Authorization != nil {
993995
service = auth.NewWorkflowServiceWrapper(service, options.Authorization)
994996
}
997+
if options.IsolationGroup != "" {
998+
service = isolationgroup.NewWorkflowServiceWrapper(service, options.IsolationGroup)
999+
}
9951000
service = metrics.NewWorkflowServiceWrapper(service, workerParams.MetricsScope)
9961001
processTestTags(&wOptions, &workerParams)
9971002

internal/internal_worker_interfaces_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ func (s *InterfacesTestSuite) TestInterface() {
197197

198198
// mocks
199199
s.service.EXPECT().DescribeDomain(gomock.Any(), gomock.Any(), callOptions()...).Return(domainDesc, nil).AnyTimes()
200-
s.service.EXPECT().PollForActivityTask(gomock.Any(), gomock.Any(), callOptions()...).Return(&m.PollForActivityTaskResponse{}, nil).AnyTimes()
201-
s.service.EXPECT().RespondActivityTaskCompleted(gomock.Any(), gomock.Any(), callOptions()...).Return(nil).AnyTimes()
202-
s.service.EXPECT().PollForDecisionTask(gomock.Any(), gomock.Any(), callOptions()...).Return(&m.PollForDecisionTaskResponse{}, nil).AnyTimes()
203-
s.service.EXPECT().RespondDecisionTaskCompleted(gomock.Any(), gomock.Any(), callOptions()...).Return(nil, nil).AnyTimes()
204-
s.service.EXPECT().StartWorkflowExecution(gomock.Any(), gomock.Any(), callOptions()...).Return(&m.StartWorkflowExecutionResponse{}, nil).AnyTimes()
200+
s.service.EXPECT().PollForActivityTask(gomock.Any(), gomock.Any(), callOptionsWithIsolationGroupHeader()...).Return(&m.PollForActivityTaskResponse{}, nil).AnyTimes()
201+
s.service.EXPECT().RespondActivityTaskCompleted(gomock.Any(), gomock.Any(), callOptionsWithIsolationGroupHeader()...).Return(nil).AnyTimes()
202+
s.service.EXPECT().PollForDecisionTask(gomock.Any(), gomock.Any(), callOptionsWithIsolationGroupHeader()...).Return(&m.PollForDecisionTaskResponse{}, nil).AnyTimes()
203+
s.service.EXPECT().RespondDecisionTaskCompleted(gomock.Any(), gomock.Any(), callOptionsWithIsolationGroupHeader()...).Return(nil, nil).AnyTimes()
204+
s.service.EXPECT().StartWorkflowExecution(gomock.Any(), gomock.Any(), callOptionsWithIsolationGroupHeader()...).Return(&m.StartWorkflowExecutionResponse{}, nil).AnyTimes()
205205

206206
registry := newRegistry()
207207
// Launch worker.
@@ -231,7 +231,7 @@ func (s *InterfacesTestSuite) TestInterface() {
231231
ExecutionStartToCloseTimeout: 10 * time.Second,
232232
DecisionTaskStartToCloseTimeout: 10 * time.Second,
233233
}
234-
workflowClient := NewClient(s.service, domain, nil)
234+
workflowClient := NewClient(s.service, domain, &ClientOptions{IsolationGroup: "zone-2"})
235235
_, err := workflowClient.StartWorkflow(context.Background(), workflowOptions, "workflowType")
236236
s.NoError(err)
237237
}

internal/test_helpers_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,15 @@ func callOptions() []interface{} {
5151
gomock.Any(), // feature flags
5252
}
5353
}
54+
55+
// this is the mock for yarpcCallOptions, as gomock requires the num of arguments to be the same.
56+
// see getYarpcCallOptions for the default case.
57+
func callOptionsWithIsolationGroupHeader() []interface{} {
58+
return []interface{}{
59+
gomock.Any(), // library version
60+
gomock.Any(), // feature version
61+
gomock.Any(), // client name
62+
gomock.Any(), // feature flags
63+
gomock.Any(), // isolation group header
64+
}
65+
}

internal/worker.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ type (
128128
// default: default identity that include hostname, groupName and process ID.
129129
Identity string
130130

131+
// Optional: Defines the 'zone' or the failure group that the worker belongs to
132+
IsolationGroup string
133+
131134
// Optional: Metrics to be reported. Metrics emitted by the cadence client are not prometheus compatible by
132135
// default. To ensure metrics are compatible with prometheus make sure to create tally scope with sanitizer
133136
// options set.

internal/workflow_replayer_utils.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
// Copyright (c) 2017-2021 Uber Technologies Inc.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
121
package internal
222

323
import (

0 commit comments

Comments
 (0)