Skip to content

Commit

Permalink
Compare task type enum (#3464)
Browse files Browse the repository at this point in the history
* Compare task type enum
  • Loading branch information
yux0 authored and dnr committed Oct 10, 2022
1 parent f089fda commit cb2f574
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
4 changes: 3 additions & 1 deletion common/dynamicconfig/client.go
Expand Up @@ -26,6 +26,8 @@ package dynamicconfig

import (
enumspb "go.temporal.io/api/enums/v1"

enumsspb "go.temporal.io/server/api/enums/v1"
)

type (
Expand Down Expand Up @@ -95,6 +97,6 @@ type (
TaskQueueName string
TaskQueueType enumspb.TaskQueueType
ShardID int32
TaskType string
TaskType enumsspb.TaskType
}
)
2 changes: 1 addition & 1 deletion common/dynamicconfig/collection.go
Expand Up @@ -508,7 +508,7 @@ func shardIDPrecedence(shardID int32) []Constraints {

func taskTypePrecedence(taskType enumsspb.TaskType) []Constraints {
return []Constraints{
{TaskType: taskType.String()},
{TaskType: taskType},
{},
}
}
Expand Down
7 changes: 7 additions & 0 deletions common/dynamicconfig/config/testConfig.yaml
Expand Up @@ -74,3 +74,10 @@ testGetStringPropertyKey:
- value: constrained-string
constraints:
namespace: random-namespace
testGetDurationPropertyFilteredByTaskTypeKey:
- value: 10s
constraints:
historytasktype: ActivityRetryTimer
- value: 10s
constraints:
historytasktype: 1
17 changes: 17 additions & 0 deletions common/dynamicconfig/file_based_client.go
Expand Up @@ -38,6 +38,7 @@ import (
enumspb "go.temporal.io/api/enums/v1"
"gopkg.in/yaml.v3"

enumsspb "go.temporal.io/server/api/enums/v1"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/log/tag"
)
Expand Down Expand Up @@ -294,6 +295,9 @@ func (fc *fileBasedClient) appendConstrainedValue(logLine *strings.Builder, valu
if value.Constraints.ShardID != 0 {
logLine.WriteString(fmt.Sprintf("{ShardID:%d}", value.Constraints.ShardID))
}
if value.Constraints.TaskType != enumsspb.TASK_TYPE_UNSPECIFIED {
logLine.WriteString(fmt.Sprintf("{HistoryTaskType:%s}", value.Constraints.TaskType))
}
logLine.WriteString(fmt.Sprint("} value: ", value.Value, " }"))
}
}
Expand Down Expand Up @@ -372,6 +376,19 @@ func convertYamlConstraints(m map[string]any) (Constraints, error) {
default:
return cs, fmt.Errorf("taskType constraint must be Workflow/Activity")
}
case "historytasktype":
switch v := v.(type) {
case string:
if i, ok := enumsspb.TaskType_value[v]; ok && i > 0 {
cs.TaskType = enumsspb.TaskType(i)
} else {
return cs, fmt.Errorf("taskType %s constraint is not supported", v)
}
case int:
cs.TaskType = enumsspb.TaskType(v)
default:
return cs, fmt.Errorf("taskType %T constraint is not supported", v)
}
case "shardid":
if v, ok := v.(int); ok {
cs.ShardID = int32(v)
Expand Down
14 changes: 14 additions & 0 deletions common/dynamicconfig/file_based_client_test.go
Expand Up @@ -34,6 +34,8 @@ import (
"github.com/stretchr/testify/suite"

enumspb "go.temporal.io/api/enums/v1"

enumsspb "go.temporal.io/server/api/enums/v1"
"go.temporal.io/server/common/log"
)

Expand Down Expand Up @@ -225,6 +227,18 @@ func (s *fileBasedClientSuite) TestGetDurationValue_ParseFailed() {
s.Equal(time.Second, v)
}

func (s *fileBasedClientSuite) TestGetDurationValue_FilteredByTaskTypeQueue() {
expectedValue := time.Second * 10
v := s.collection.GetDurationPropertyFilteredByTaskType(testGetDurationPropertyFilteredByTaskTypeKey, 0)(
enumsspb.TASK_TYPE_ACTIVITY_RETRY_TIMER,
)
s.Equal(expectedValue, v)
v = s.collection.GetDurationPropertyFilteredByTaskType(testGetDurationPropertyFilteredByTaskTypeKey, 0)(
enumsspb.TASK_TYPE_REPLICATION_HISTORY,
)
s.Equal(expectedValue, v)
}

func (s *fileBasedClientSuite) TestValidateConfig_ConfigNotExist() {
_, err := NewFileBasedClient(nil, nil, nil)
s.Error(err)
Expand Down

0 comments on commit cb2f574

Please sign in to comment.