Skip to content

Commit

Permalink
[CLI] fix nil pointer issue in domain migration command rendering (ub…
Browse files Browse the repository at this point in the history
…er#5378)

What changed?

correct empty response
refactor long running checker a little and add long running definition in the output

Why?
Empty response should include Value field otherwise it's going to cause nil pointer error in the rendering.

How did you test it?
tested locally
---------

Co-authored-by: David Porter <david.porter@uber.com>
  • Loading branch information
shijiesheng and davidporter-id-au authored Aug 29, 2023
1 parent 01b0bd4 commit 99daa45
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions tools/cli/domainMigrationCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ import (
"github.com/uber/cadence/common/types"
)

var domainMigrationTemplate = `Validation Check:
const (
// workflows running longer than 14 days are considered long running workflows
longRunningDuration = 14 * 24 * time.Hour
)

var (
domainMigrationTemplate = `Validation Check:
{{- range .}}
- {{.ValidationCheck}}: {{.ValidationResult}}
{{- with .ValidationDetails}}
Expand All @@ -59,7 +65,7 @@ var domainMigrationTemplate = `Validation Check:
Mismatched Domain Meta Data: {{.MismatchedDomainMetaData}}
{{- end }}
{{- if .LongRunningWorkFlowNum}}
Long Running Workflow Num: {{.LongRunningWorkFlowNum}}
Long Running Workflow Num (> 14 days): {{.LongRunningWorkFlowNum}}
{{- end}}
{{- if .MissingCurrSearchAttributes}}
Missing Search Attributes in Current Domain:
Expand Down Expand Up @@ -96,6 +102,12 @@ var domainMigrationTemplate = `Validation Check:
{{- end}}
{{- end}}
`
emptyGetDynamicConfigRequest = &types.GetDynamicConfigResponse{
Value: &types.DataBlob{
EncodingType: types.EncodingTypeJSON.Ptr(),
},
}
)

type domainMigrationCLIImpl struct {
frontendClient, destinationClient frontend.Client
Expand Down Expand Up @@ -196,11 +208,10 @@ func (d *domainMigrationCLIImpl) migrationDomainWorkFlowCheck(c *cli.Context) Do

func (d *domainMigrationCLIImpl) countLongRunningWorkflow(c *cli.Context) int {
domain := c.GlobalString(FlagDomain)
now := time.Now()
past14Days := now.Add(-14 * 24 * time.Hour)
thresholdOfLongRunning := time.Now().Add(-longRunningDuration)
request := &types.CountWorkflowExecutionsRequest{
Domain: domain,
Query: "CloseTime=missing AND StartTime < " + strconv.FormatInt(past14Days.UnixNano(), 10),
Query: "CloseTime=missing AND StartTime < " + strconv.FormatInt(thresholdOfLongRunning.UnixNano(), 10),
}
ctx, cancel := newContextForLongPoll(c)
defer cancel()
Expand Down Expand Up @@ -332,12 +343,12 @@ func (d *domainMigrationCLIImpl) migrationDynamicConfigCheck(c *cli.Context) Dom
currResp, err := d.frontendAdminClient.GetDynamicConfig(ctx, currRequest)
if err != nil {
// empty to indicate N/A
currResp = &types.GetDynamicConfigResponse{}
currResp = emptyGetDynamicConfigRequest
}
newResp, err := d.destinationAdminClient.GetDynamicConfig(ctx, newRequest)
if err != nil {
// empty to indicate N/A
newResp = &types.GetDynamicConfigResponse{}
newResp = emptyGetDynamicConfigRequest
}

if !reflect.DeepEqual(currResp.Value, newResp.Value) {
Expand Down Expand Up @@ -370,12 +381,12 @@ func (d *domainMigrationCLIImpl) migrationDynamicConfigCheck(c *cli.Context) Dom
currResp, err := d.frontendAdminClient.GetDynamicConfig(ctx, currRequest)
if err != nil {
// empty to indicate N/A
currResp = &types.GetDynamicConfigResponse{}
currResp = emptyGetDynamicConfigRequest
}
newResp, err := d.destinationAdminClient.GetDynamicConfig(ctx, newRequest)
if err != nil {
// empty to indicate N/A
newResp = &types.GetDynamicConfigResponse{}
newResp = emptyGetDynamicConfigRequest
}

if !reflect.DeepEqual(currResp.Value, newResp.Value) {
Expand Down Expand Up @@ -415,12 +426,12 @@ func (d *domainMigrationCLIImpl) migrationDynamicConfigCheck(c *cli.Context) Dom
currResp, err := d.frontendAdminClient.GetDynamicConfig(ctx, currRequest)
if err != nil {
// empty to indicate N/A
currResp = &types.GetDynamicConfigResponse{}
currResp = emptyGetDynamicConfigRequest
}
newResp, err := d.destinationAdminClient.GetDynamicConfig(ctx, newRequest)
if err != nil {
// empty to indicate N/A
newResp = &types.GetDynamicConfigResponse{}
newResp = emptyGetDynamicConfigRequest
}

if !reflect.DeepEqual(currResp.Value, newResp.Value) {
Expand Down

0 comments on commit 99daa45

Please sign in to comment.