Skip to content

Commit 1bf0fd7

Browse files
authored
Set default shadow workflow status to OPEN (#1070)
1 parent 7f92111 commit 1bf0fd7

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

internal/query_builder.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const (
3939
WorkflowStatusOpen WorkflowStatus = "OPEN"
4040
// WorkflowStatusClosed is the WorkflowStatus for closed workflows
4141
WorkflowStatusClosed WorkflowStatus = "CLOSED"
42+
// WorkflowStatusALL is the WorkflowStatus for all workflows
43+
WorkflowStatusALL WorkflowStatus = "ALL"
4244
)
4345

4446
var (
@@ -104,6 +106,9 @@ func (q *queryBuilderImpl) WorkflowStatus(statuses []WorkflowStatus) QueryBuilde
104106
statusQuery = keyCloseTime + " = missing"
105107
case WorkflowStatusClosed:
106108
statusQuery = keyCloseTime + " != missing"
109+
case WorkflowStatusALL:
110+
// no query needed
111+
return q
107112
default:
108113
statusQuery = keyCloseStatus + ` = "` + string(status) + `"`
109114
}

internal/query_builder_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ func (s *queryBuilderSuite) TestWorkflowStatusQuery() {
101101
workflowStatuses: []WorkflowStatus{WorkflowStatusFailed, WorkflowStatusTimedOut},
102102
expectedQuery: `(CloseStatus = "FAILED" or CloseStatus = "TIMED_OUT")`,
103103
},
104+
{
105+
msg: "all workflows",
106+
workflowStatuses: []WorkflowStatus{WorkflowStatusTerminated, WorkflowStatusALL},
107+
expectedQuery: "",
108+
},
104109
}
105110

106111
for _, test := range testCases {
@@ -189,7 +194,6 @@ func (s *queryBuilderSuite) TestToWorkflowStatus() {
189194
expectedStatus: WorkflowStatusTimedOut,
190195
},
191196
{
192-
193197
msg: "upper case status string",
194198
statusString: "TERMINATED",
195199
expectErr: false,

internal/workflow_shadower.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ type (
6363

6464
// Optional: A list of workflow status.
6565
// The list will be used to construct WorkflowQuery. Only workflows with status listed will be replayed.
66-
// accepted values (case-insensitive): OPEN, CLOSED, COMPLETED, FAILED, CANCELED, TERMINATED, CONTINUED_AS_NEW, TIMED_OUT
67-
// default: empty list, which matches all workflow status
66+
// accepted values (case-insensitive): OPEN, CLOSED, ALL, COMPLETED, FAILED, CANCELED, TERMINATED, CONTINUED_AS_NEW, TIMED_OUT
67+
// default: OPEN, which matches only open workflows
6868
WorkflowStatus []string
6969

7070
// Optional: Min and Max workflow start timestamp.
@@ -312,6 +312,9 @@ func (o *ShadowOptions) validateAndPopulateFields() error {
312312
}
313313
statuses = append(statuses, status)
314314
}
315+
if len(statuses) == 0 {
316+
statuses = []WorkflowStatus{WorkflowStatusOpen}
317+
}
315318
queryBuilder.WorkflowStatus(statuses)
316319

317320
if !o.WorkflowStartTimeFilter.isEmpty() {

internal/workflow_shadower_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ func (s *workflowShadowerSuite) TestShadowOptionsValidation() {
194194
expectErr: true,
195195
},
196196
{
197-
msg: "populate sampling rate and concurrency",
197+
msg: "populate sampling rate, concurrency and status",
198198
options: ShadowOptions{},
199199
expectErr: false,
200200
validationFn: func(options *ShadowOptions) {
201-
s.Empty(options.WorkflowQuery)
201+
s.Equal("(CloseTime = missing)", options.WorkflowQuery)
202202
s.Equal(1.0, options.SamplingRate)
203203
s.Equal(1, options.Concurrency)
204204
},

0 commit comments

Comments
 (0)