Skip to content

Commit

Permalink
Admin command for visibility into membership info for the cluster (ca…
Browse files Browse the repository at this point in the history
…dence-workflow#2938)

* Admin command for visibility into membership info for the cluster

Added new admin API DescribeCluster which exposes all membership
information for the cluster.
Updated Membership contract to expose GetReachableMembers API on
Monitor interface and ServerCount and Servers API on
ServerResolver interface which is used for implementing the
DescribeCluster admin handler.
CLI changes to add new admin cluster command to describe cluster.
  • Loading branch information
samarabbas authored Dec 26, 2019
1 parent e5f7c87 commit 6c962c9
Show file tree
Hide file tree
Showing 20 changed files with 2,216 additions and 382 deletions.
2,227 changes: 1,850 additions & 377 deletions .gen/go/admin/admin.go

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions .gen/go/admin/adminserviceclient/client.go

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

36 changes: 35 additions & 1 deletion .gen/go/admin/adminserviceserver/server.go

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

31 changes: 31 additions & 0 deletions .gen/go/admin/adminservicetest/client.go

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

15 changes: 15 additions & 0 deletions client/admin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ func (c *clientImpl) GetWorkflowExecutionRawHistoryV2(
return client.GetWorkflowExecutionRawHistoryV2(ctx, request, opts...)
}

func (c *clientImpl) DescribeCluster(
ctx context.Context,
opts ...yarpc.CallOption,
) (*admin.DescribeClusterResponse, error) {

opts = common.AggregateYarpcOptions(ctx, opts...)
client, err := c.getRandomClient()
if err != nil {
return nil, err
}
ctx, cancel := c.createContext(ctx)
defer cancel()
return client.DescribeCluster(ctx, opts...)
}

func (c *clientImpl) createContext(parent context.Context) (context.Context, context.CancelFunc) {
if parent == nil {
return context.WithTimeout(context.Background(), c.timeout)
Expand Down
17 changes: 17 additions & 0 deletions client/admin/metricClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,20 @@ func (c *metricClient) GetWorkflowExecutionRawHistoryV2(
}
return resp, err
}

func (c *metricClient) DescribeCluster(
ctx context.Context,
opts ...yarpc.CallOption,
) (*admin.DescribeClusterResponse, error) {

c.metricsClient.IncCounter(metrics.AdminClientDescribeClusterScope, metrics.CadenceClientRequests)

sw := c.metricsClient.StartTimer(metrics.AdminClientDescribeClusterScope, metrics.CadenceClientLatency)
resp, err := c.client.DescribeCluster(ctx, opts...)
sw.Stop()

if err != nil {
c.metricsClient.IncCounter(metrics.AdminClientDescribeClusterScope, metrics.CadenceClientFailures)
}
return resp, err
}
15 changes: 15 additions & 0 deletions client/admin/retryableClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,18 @@ func (c *retryableClient) GetWorkflowExecutionRawHistoryV2(
err := backoff.Retry(op, c.policy, c.isRetryable)
return resp, err
}

func (c *retryableClient) DescribeCluster(
ctx context.Context,
opts ...yarpc.CallOption,
) (*admin.DescribeClusterResponse, error) {

var resp *admin.DescribeClusterResponse
op := func() error {
var err error
resp, err = c.client.DescribeCluster(ctx, opts...)
return err
}
err := backoff.Retry(op, c.policy, c.isRetryable)
return resp, err
}
8 changes: 7 additions & 1 deletion common/membership/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:generate mockgen -copyright_file ../../LICENSE -package $GOPACKAGE -source $GOFILE -destination interface_mock.go
//go:generate mockgen -copyright_file ../../LICENSE -package $GOPACKAGE -source $GOFILE -destination interfaces_mock.go

package membership

Expand Down Expand Up @@ -64,6 +64,8 @@ type (
AddListener(service string, name string, notifyChannel chan<- *ChangedEvent) error
// RemoveListener removes a listener for this service.
RemoveListener(service string, name string) error
// GetReachableMembers returns addresses of all members of the ring
GetReachableMembers() ([]string, error)
}

// ServiceResolver provides membership information for a specific cadence service.
Expand All @@ -77,5 +79,9 @@ type (
AddListener(name string, notifyChannel chan<- *ChangedEvent) error
// RemoveListener removes a listener for this service.
RemoveListener(name string) error
// MemberCount returns host count in hashring for any particular role
MemberCount() int
// Members returns all host addresses in hashring for any particular role
Members() []*HostInfo
}
)
43 changes: 43 additions & 0 deletions common/membership/interfaces_mock.go

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

4 changes: 4 additions & 0 deletions common/membership/rpMonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,7 @@ func (rpo *ringpopMonitor) RemoveListener(service string, name string) error {
}
return ring.RemoveListener(name)
}

func (rpo *ringpopMonitor) GetReachableMembers() ([]string, error) {
return rpo.rp.GetReachableMembers()
}
13 changes: 13 additions & 0 deletions common/membership/rpServiceResolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ func (r *ringpopServiceResolver) RemoveListener(
return nil
}

func (r *ringpopServiceResolver) MemberCount() int {
return r.ring.ServerCount()
}

func (r *ringpopServiceResolver) Members() []*HostInfo {
var servers []*HostInfo
for _, s := range r.ring.Servers() {
servers = append(servers, NewHostInfo(s, r.getLabelsMap()))
}

return servers
}

// HandleEvent handles updates from ringpop
func (r *ringpopServiceResolver) HandleEvent(
event events.Event,
Expand Down
3 changes: 3 additions & 0 deletions common/metrics/defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ const (
AdminClientGetWorkflowExecutionRawHistoryScope
// AdminClientGetWorkflowExecutionRawHistoryV2Scope tracks RPC calls to admin service
AdminClientGetWorkflowExecutionRawHistoryV2Scope
// AdminClientDescribeClusterScope tracks RPC calls to admin service
AdminClientDescribeClusterScope
// DCRedirectionDeprecateDomainScope tracks RPC calls for dc redirection
DCRedirectionDeprecateDomainScope
// DCRedirectionDescribeDomainScope tracks RPC calls for dc redirection
Expand Down Expand Up @@ -1112,6 +1114,7 @@ var ScopeDefs = map[ServiceIdx]map[int]scopeDefinition{
AdminClientDescribeWorkflowExecutionScope: {operation: "AdminClientDescribeWorkflowExecution", tags: map[string]string{CadenceRoleTagName: AdminRoleTagValue}},
AdminClientGetWorkflowExecutionRawHistoryScope: {operation: "AdminClientGetWorkflowExecutionRawHistory", tags: map[string]string{CadenceRoleTagName: AdminRoleTagValue}},
AdminClientGetWorkflowExecutionRawHistoryV2Scope: {operation: "AdminClientGetWorkflowExecutionRawHistoryV2", tags: map[string]string{CadenceRoleTagName: AdminRoleTagValue}},
AdminClientDescribeClusterScope: {operation: "AdminClientDescribeCluster", tags: map[string]string{CadenceRoleTagName: AdminRoleTagValue}},
AdminClientCloseShardScope: {operation: "AdminClientCloseShard", tags: map[string]string{CadenceRoleTagName: AdminRoleTagValue}},
DCRedirectionDeprecateDomainScope: {operation: "DCRedirectionDeprecateDomain", tags: map[string]string{CadenceRoleTagName: DCRedirectionRoleTagValue}},
DCRedirectionDescribeDomainScope: {operation: "DCRedirectionDescribeDomain", tags: map[string]string{CadenceRoleTagName: DCRedirectionRoleTagValue}},
Expand Down
28 changes: 28 additions & 0 deletions common/mocks/ServiceResolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,32 @@ func (_m *ServiceResolver) RemoveListener(name string) error {
return r0
}

// MemberCount is am mock implementation
func (_m *ServiceResolver) MemberCount() int {
ret := _m.Called()

var r0 int
if rf, ok := ret.Get(0).(func() int); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(int)
}

return r0
}

// Members is am mock implementation
func (_m *ServiceResolver) Members() []*membership.HostInfo {
ret := _m.Called()

var r0 []*membership.HostInfo
if rf, ok := ret.Get(0).(func() []*membership.HostInfo); ok {
r0 = rf()
} else {
r0 = ret.Get(0).([]*membership.HostInfo)
}

return r0
}

var _ membership.ServiceResolver = (*ServiceResolver)(nil)
4 changes: 4 additions & 0 deletions host/simpleMonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ func (s *simpleMonitor) AddListener(service string, name string, notifyChannel c
func (s *simpleMonitor) RemoveListener(service string, name string) error {
return nil
}

func (s *simpleMonitor) GetReachableMembers() ([]string, error) {
return nil, nil
}
8 changes: 8 additions & 0 deletions host/simpleServiceResolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ func (s *simpleResolver) AddListener(name string, notifyChannel chan<- *membersh
func (s *simpleResolver) RemoveListener(name string) error {
return nil
}

func (s *simpleResolver) MemberCount() int {
return len(s.hosts)
}

func (s *simpleResolver) Members() []*membership.HostInfo {
return s.hosts
}
Loading

0 comments on commit 6c962c9

Please sign in to comment.