Skip to content

Commit

Permalink
Adds tooling (cadence-workflow#5283)
Browse files Browse the repository at this point in the history
Background
This is part of the wider 'Zonal-isolation' feature:

Changes

Introduces commands for updating and getting the current state of isolation groups:

# to read for a domain 
cadence admin isolation-groups get-domain --domain cadence-system

# to read 'globally', ie for all domains
cadence admin isolation-groups get-global

# To add a drain to zones 1 and zone-2:
$ cadence admin isolation-groups update-global --set-drains zone-1 zone-2  

# Note that this is Upsert semantics, so by doing this subsequently.. 
$ cadence admin isolation-groups update-global --set-drains zone-3
# ... now only zone-3 is drained, zone-1 and zone-2 drains are removed

# to drain just for some domain 
$ cadence admin isolation-groups update-domain --set-drains zone-3 --domain some-domain

# to remove
$ cadence admin isolation-groups update-domain --remove-all-drains
Testing
Unit tests
  • Loading branch information
davidporter-id-au authored May 11, 2023
1 parent 7e85ed2 commit aec8af0
Show file tree
Hide file tree
Showing 15 changed files with 824 additions and 0 deletions.
36 changes: 36 additions & 0 deletions client/admin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,42 @@ func (c *clientImpl) ListDynamicConfig(
return c.client.ListDynamicConfig(ctx, request, opts...)
}

func (c *clientImpl) GetGlobalIsolationGroups(
ctx context.Context,
request *types.GetGlobalIsolationGroupsRequest,
opts ...yarpc.CallOption) (*types.GetGlobalIsolationGroupsResponse, error) {
ctx, cancel := c.createContext(ctx)
defer cancel()
return c.client.GetGlobalIsolationGroups(ctx, request, opts...)
}

func (c *clientImpl) UpdateGlobalIsolationGroups(
ctx context.Context,
request *types.UpdateGlobalIsolationGroupsRequest,
opts ...yarpc.CallOption) (*types.UpdateGlobalIsolationGroupsResponse, error) {
ctx, cancel := c.createContext(ctx)
defer cancel()
return c.client.UpdateGlobalIsolationGroups(ctx, request, opts...)
}

func (c *clientImpl) GetDomainIsolationGroups(
ctx context.Context,
request *types.GetDomainIsolationGroupsRequest,
opts ...yarpc.CallOption) (*types.GetDomainIsolationGroupsResponse, error) {
ctx, cancel := c.createContext(ctx)
defer cancel()
return c.client.GetDomainIsolationGroups(ctx, request, opts...)
}

func (c *clientImpl) UpdateDomainIsolationGroups(
ctx context.Context,
request *types.UpdateDomainIsolationGroupsRequest,
opts ...yarpc.CallOption) (*types.UpdateDomainIsolationGroupsResponse, error) {
ctx, cancel := c.createContext(ctx)
defer cancel()
return c.client.UpdateDomainIsolationGroups(ctx, request, opts...)
}

func (c *clientImpl) createContext(parent context.Context) (context.Context, context.CancelFunc) {
if parent == nil {
return context.WithTimeout(context.Background(), c.timeout)
Expand Down
104 changes: 104 additions & 0 deletions client/admin/errorInjectionClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,3 +772,107 @@ func (c *errorInjectionClient) ListDynamicConfig(
}
return resp, clientErr
}

func (c *errorInjectionClient) GetGlobalIsolationGroups(
ctx context.Context,
request *types.GetGlobalIsolationGroupsRequest,
opts ...yarpc.CallOption,
) (*types.GetGlobalIsolationGroupsResponse, error) {
fakeErr := errors.GenerateFakeError(c.errorRate)

var resp *types.GetGlobalIsolationGroupsResponse
var clientErr error
var forwardCall bool
if forwardCall = errors.ShouldForwardCall(fakeErr); forwardCall {
resp, clientErr = c.client.GetGlobalIsolationGroups(ctx, request, opts...)
}

if fakeErr != nil {
c.logger.Error(msgInjectedFakeErr,
tag.AdminClientOperationGetGlobalIsolationGroups,
tag.Error(fakeErr),
tag.Bool(forwardCall),
tag.ClientError(clientErr),
)
return nil, fakeErr
}
return resp, clientErr
}

func (c *errorInjectionClient) UpdateGlobalIsolationGroups(
ctx context.Context,
request *types.UpdateGlobalIsolationGroupsRequest,
opts ...yarpc.CallOption,
) (*types.UpdateGlobalIsolationGroupsResponse, error) {
fakeErr := errors.GenerateFakeError(c.errorRate)

var resp *types.UpdateGlobalIsolationGroupsResponse
var clientErr error
var forwardCall bool
if forwardCall = errors.ShouldForwardCall(fakeErr); forwardCall {
resp, clientErr = c.client.UpdateGlobalIsolationGroups(ctx, request, opts...)
}

if fakeErr != nil {
c.logger.Error(msgInjectedFakeErr,
tag.AdminClientOperationUpdateGlobalIsolationGroups,
tag.Error(fakeErr),
tag.Bool(forwardCall),
tag.ClientError(clientErr),
)
return nil, fakeErr
}
return resp, clientErr
}

func (c *errorInjectionClient) GetDomainIsolationGroups(
ctx context.Context,
request *types.GetDomainIsolationGroupsRequest,
opts ...yarpc.CallOption,
) (*types.GetDomainIsolationGroupsResponse, error) {
fakeErr := errors.GenerateFakeError(c.errorRate)

var resp *types.GetDomainIsolationGroupsResponse
var clientErr error
var forwardCall bool
if forwardCall = errors.ShouldForwardCall(fakeErr); forwardCall {
resp, clientErr = c.client.GetDomainIsolationGroups(ctx, request, opts...)
}

if fakeErr != nil {
c.logger.Error(msgInjectedFakeErr,
tag.AdminClientOperationGetDomainIsolationGroups,
tag.Error(fakeErr),
tag.Bool(forwardCall),
tag.ClientError(clientErr),
)
return nil, fakeErr
}
return resp, clientErr
}

func (c *errorInjectionClient) UpdateDomainIsolationGroups(
ctx context.Context,
request *types.UpdateDomainIsolationGroupsRequest,
opts ...yarpc.CallOption,
) (*types.UpdateDomainIsolationGroupsResponse, error) {
fakeErr := errors.GenerateFakeError(c.errorRate)

var resp *types.UpdateDomainIsolationGroupsResponse
var clientErr error
var forwardCall bool
if forwardCall = errors.ShouldForwardCall(fakeErr); forwardCall {
resp, clientErr = c.client.UpdateDomainIsolationGroups(ctx, request, opts...)
}

if fakeErr != nil {
c.logger.Error(msgInjectedFakeErr,
tag.AdminClientOperationUpdateDomainIsolationGroups,
tag.Error(fakeErr),
tag.Bool(forwardCall),
tag.ClientError(clientErr),
)
return nil, fakeErr
}
return resp, clientErr
}
20 changes: 20 additions & 0 deletions client/admin/grpcClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,23 @@ func (g grpcClient) ListDynamicConfig(ctx context.Context, request *types.ListDy
response, err := g.c.ListDynamicConfig(ctx, proto.FromListDynamicConfigRequest(request), opts...)
return proto.ToListDynamicConfigResponse(response), proto.ToError(err)
}

func (g grpcClient) GetGlobalIsolationGroups(ctx context.Context, request *types.GetGlobalIsolationGroupsRequest, opts ...yarpc.CallOption) (*types.GetGlobalIsolationGroupsResponse, error) {
response, err := g.c.GetGlobalIsolationGroups(ctx, proto.FromGetGlobalIsolationGroupsRequest(request), opts...)
return proto.ToGetGlobalIsolationGroupsResponse(response), proto.ToError(err)
}

func (g grpcClient) UpdateGlobalIsolationGroups(ctx context.Context, request *types.UpdateGlobalIsolationGroupsRequest, opts ...yarpc.CallOption) (*types.UpdateGlobalIsolationGroupsResponse, error) {
response, err := g.c.UpdateGlobalIsolationGroups(ctx, proto.FromUpdateGlobalIsolationGroupsRequest(request), opts...)
return proto.ToUpdateGlobalIsolationGroupsResponse(response), proto.ToError(err)
}

func (g grpcClient) GetDomainIsolationGroups(ctx context.Context, request *types.GetDomainIsolationGroupsRequest, opts ...yarpc.CallOption) (*types.GetDomainIsolationGroupsResponse, error) {
response, err := g.c.GetDomainIsolationGroups(ctx, proto.FromGetDomainIsolationGroupsRequest(request), opts...)
return proto.ToGetDomainIsolationGroupsResponse(response), proto.ToError(err)
}

func (g grpcClient) UpdateDomainIsolationGroups(ctx context.Context, request *types.UpdateDomainIsolationGroupsRequest, opts ...yarpc.CallOption) (*types.UpdateDomainIsolationGroupsResponse, error) {
response, err := g.c.UpdateDomainIsolationGroups(ctx, proto.FromUpdateDomainIsolationGroupsRequest(request), opts...)
return proto.ToUpdateDomainIsolationGroupsResponse(response), proto.ToError(err)
}
4 changes: 4 additions & 0 deletions client/admin/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ type Client interface {
ListDynamicConfig(context.Context, *types.ListDynamicConfigRequest, ...yarpc.CallOption) (*types.ListDynamicConfigResponse, error)
DeleteWorkflow(context.Context, *types.AdminDeleteWorkflowRequest, ...yarpc.CallOption) (*types.AdminDeleteWorkflowResponse, error)
MaintainCorruptWorkflow(context.Context, *types.AdminMaintainWorkflowRequest, ...yarpc.CallOption) (*types.AdminMaintainWorkflowResponse, error)
GetGlobalIsolationGroups(ctx context.Context, request *types.GetGlobalIsolationGroupsRequest, opts ...yarpc.CallOption) (*types.GetGlobalIsolationGroupsResponse, error)
UpdateGlobalIsolationGroups(ctx context.Context, request *types.UpdateGlobalIsolationGroupsRequest, opts ...yarpc.CallOption) (*types.UpdateGlobalIsolationGroupsResponse, error)
GetDomainIsolationGroups(ctx context.Context, request *types.GetDomainIsolationGroupsRequest, opts ...yarpc.CallOption) (*types.GetDomainIsolationGroupsResponse, error)
UpdateDomainIsolationGroups(ctx context.Context, request *types.UpdateDomainIsolationGroupsRequest, opts ...yarpc.CallOption) (*types.UpdateDomainIsolationGroupsResponse, error)
}
80 changes: 80 additions & 0 deletions client/admin/interface_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions client/admin/metricClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,47 @@ func (c *metricClient) ListDynamicConfig(
}
return resp, err
}

func (c *metricClient) GetGlobalIsolationGroups(ctx context.Context, request *types.GetGlobalIsolationGroupsRequest, opts ...yarpc.CallOption) (*types.GetGlobalIsolationGroupsResponse, error) {
c.metricsClient.IncCounter(metrics.AdminClientGetGlobalIsolationGroupsScope, metrics.CadenceClientRequests)
sw := c.metricsClient.StartTimer(metrics.AdminClientGetGlobalIsolationGroupsScope, metrics.CadenceClientLatency)
resp, err := c.client.GetGlobalIsolationGroups(ctx, request, opts...)
sw.Stop()
if err != nil {
c.metricsClient.IncCounter(metrics.AdminClientGetGlobalIsolationGroupsScope, metrics.CadenceClientFailures)
}
return resp, err
}

func (c *metricClient) UpdateGlobalIsolationGroups(ctx context.Context, request *types.UpdateGlobalIsolationGroupsRequest, opts ...yarpc.CallOption) (*types.UpdateGlobalIsolationGroupsResponse, error) {
c.metricsClient.IncCounter(metrics.AdminClientUpdateGlobalIsolationGroupsScope, metrics.CadenceClientRequests)
sw := c.metricsClient.StartTimer(metrics.AdminClientUpdateGlobalIsolationGroupsScope, metrics.CadenceClientLatency)
resp, err := c.client.UpdateGlobalIsolationGroups(ctx, request, opts...)
sw.Stop()
if err != nil {
c.metricsClient.IncCounter(metrics.AdminClientUpdateGlobalIsolationGroupsScope, metrics.CadenceClientFailures)
}
return resp, err
}

func (c *metricClient) GetDomainIsolationGroups(ctx context.Context, request *types.GetDomainIsolationGroupsRequest, opts ...yarpc.CallOption) (*types.GetDomainIsolationGroupsResponse, error) {
c.metricsClient.IncCounter(metrics.AdminClientGetDomainIsolationGroupsScope, metrics.CadenceClientRequests)
sw := c.metricsClient.StartTimer(metrics.AdminClientGetDomainIsolationGroupsScope, metrics.CadenceClientLatency)
resp, err := c.client.GetDomainIsolationGroups(ctx, request, opts...)
sw.Stop()
if err != nil {
c.metricsClient.IncCounter(metrics.AdminClientGetDomainIsolationGroupsScope, metrics.CadenceClientFailures)
}
return resp, err
}

func (c *metricClient) UpdateDomainIsolationGroups(ctx context.Context, request *types.UpdateDomainIsolationGroupsRequest, opts ...yarpc.CallOption) (*types.UpdateDomainIsolationGroupsResponse, error) {
c.metricsClient.IncCounter(metrics.AdminClientUpdateDomainIsolationGroupsScope, metrics.CadenceClientRequests)
sw := c.metricsClient.StartTimer(metrics.AdminClientUpdateDomainIsolationGroupsScope, metrics.CadenceClientLatency)
resp, err := c.client.UpdateDomainIsolationGroups(ctx, request, opts...)
sw.Stop()
if err != nil {
c.metricsClient.IncCounter(metrics.AdminClientUpdateDomainIsolationGroupsScope, metrics.CadenceClientFailures)
}
return resp, err
}
Loading

0 comments on commit aec8af0

Please sign in to comment.