Skip to content

Commit 6d4ff3b

Browse files
authored
Refactor: Move constants.go to dedicated constants package (#6713)
* Refactor: Move constants.go to dedicated constants package Move common/constants.go -> common/constants/constants.go
1 parent dff05ae commit 6d4ff3b

File tree

247 files changed

+1930
-1798
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+1930
-1798
lines changed

canary/canary.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"go.uber.org/cadence/worker"
3030
"go.uber.org/zap"
3131

32-
"github.com/uber/cadence/common"
32+
"github.com/uber/cadence/common/constants"
3333
)
3434

3535
type (
@@ -66,8 +66,8 @@ const (
6666
func newCanary(domain string, rc *RuntimeContext, canaryConfig *Canary) Runnable {
6767
canaryClient := newCadenceClient(domain, rc)
6868
archivalClient := newCadenceClient(archivalDomain, rc)
69-
systemClient := newCadenceClient(common.SystemLocalDomainName, rc)
70-
batcherClient := newCadenceClient(common.BatcherLocalDomainName, rc)
69+
systemClient := newCadenceClient(constants.SystemLocalDomainName, rc)
70+
batcherClient := newCadenceClient(constants.BatcherLocalDomainName, rc)
7171
var xClusterDest cadenceClient
7272
if canaryConfig.CrossClusterTestMode == CrossClusterCanaryModeFull {
7373
xClusterDest = newCadenceClient(deriveCanaryDomain(domain), rc)

client/matching/loadbalancer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"fmt"
2727
"math/rand"
2828

29-
"github.com/uber/cadence/common"
29+
"github.com/uber/cadence/common/constants"
3030
"github.com/uber/cadence/common/types"
3131
)
3232

@@ -134,5 +134,5 @@ func getPartitionTaskListName(root string, partition int) string {
134134
if partition <= 0 {
135135
return root
136136
}
137-
return fmt.Sprintf("%v%v/%v", common.ReservedTaskListPrefix, root, partition)
137+
return fmt.Sprintf("%v%v/%v", constants.ReservedTaskListPrefix, root, partition)
138138
}

client/matching/multi_loadbalancer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ package matching
2525
import (
2626
"strings"
2727

28-
"github.com/uber/cadence/common"
28+
"github.com/uber/cadence/common/constants"
2929
"github.com/uber/cadence/common/dynamicconfig"
3030
"github.com/uber/cadence/common/log"
3131
"github.com/uber/cadence/common/log/tag"
@@ -122,5 +122,5 @@ func (lb *multiLoadBalancer) UpdateWeight(
122122
}
123123

124124
func (lb *multiLoadBalancer) canRedirectToPartition(req ReadRequest) bool {
125-
return req.GetForwardedFrom() == "" && req.GetTaskList().GetKind() != types.TaskListKindSticky && !strings.HasPrefix(req.GetTaskList().GetName(), common.ReservedTaskListPrefix)
125+
return req.GetForwardedFrom() == "" && req.GetTaskList().GetKind() != types.TaskListKindSticky && !strings.HasPrefix(req.GetTaskList().GetName(), constants.ReservedTaskListPrefix)
126126
}

client/templates/metered.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import (
22
"context"
33

44
"go.uber.org/yarpc"
5-
5+
"github.com/uber/cadence/common/constants"
66
"github.com/uber/cadence/common/metrics"
77
"github.com/uber/cadence/common/types"
88
)
@@ -60,7 +60,7 @@ func (c *{{$decorator}}) emitForwardedFromStats(scope int, req any) {
6060
taskList := p.GetTaskList()
6161
forwardedFrom := p.GetForwardedFrom()
6262

63-
isChildPartition := strings.HasPrefix(taskList.GetName(), common.ReservedTaskListPrefix)
63+
isChildPartition := strings.HasPrefix(taskList.GetName(), constants.ReservedTaskListPrefix)
6464
if forwardedFrom != ""{
6565
c.metricsClient.IncCounter(scope, metrics.MatchingClientForwardedCounter)
6666
return

client/wrappers/metered/matching_generated.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/wrappers/metered/metered_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333

3434
"github.com/uber/cadence/client/frontend"
3535
"github.com/uber/cadence/client/matching"
36-
"github.com/uber/cadence/common"
36+
"github.com/uber/cadence/common/constants"
3737
"github.com/uber/cadence/common/metrics"
3838
"github.com/uber/cadence/common/types"
3939
)
@@ -161,7 +161,7 @@ func TestMatching(t *testing.T) {
161161

162162
_, err := retryableClient.AddActivityTask(context.Background(), &types.AddActivityTaskRequest{
163163
ForwardedFrom: "",
164-
TaskList: &types.TaskList{Name: common.ReservedTaskListPrefix + "test"},
164+
TaskList: &types.TaskList{Name: constants.ReservedTaskListPrefix + "test"},
165165
})
166166
assert.NoError(t, err)
167167
assert.Len(t, testScope.Snapshot().Counters(), 2, "there should be two counters registered, one for call and one for invalid task list")

cmd/server/cadence/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/uber/cadence/common/blobstore/filestore"
3737
"github.com/uber/cadence/common/cluster"
3838
"github.com/uber/cadence/common/config"
39+
"github.com/uber/cadence/common/constants"
3940
"github.com/uber/cadence/common/dynamicconfig"
4041
"github.com/uber/cadence/common/dynamicconfig/configstore"
4142
"github.com/uber/cadence/common/elasticsearch"
@@ -310,9 +311,9 @@ func (s *server) setupVisibilityClients(params *resource.Params) {
310311

311312
// Handle advanced visibility store based on type and migration state
312313
switch advancedVisStoreKey {
313-
case common.PinotVisibilityStoreName:
314+
case constants.PinotVisibilityStoreName:
314315
s.setupPinotClient(params, advancedVisStore)
315-
case common.OSVisibilityStoreName:
316+
case constants.OSVisibilityStoreName:
316317
s.setupOSClient(params, advancedVisStore)
317318
default: // Assume Elasticsearch by default
318319
s.setupESClient(params)
@@ -333,7 +334,7 @@ func (s *server) setupPinotClient(params *resource.Params, advancedVisStore conf
333334
}
334335

335336
func (s *server) setupESClient(params *resource.Params) {
336-
esVisibilityStore, ok := s.cfg.Persistence.DataStores[common.ESVisibilityStoreName]
337+
esVisibilityStore, ok := s.cfg.Persistence.DataStores[constants.ESVisibilityStoreName]
337338
if !ok {
338339
log.Fatalf("Cannot find Elasticsearch visibility store in config")
339340
}
@@ -375,7 +376,7 @@ func (s *server) setupOSClient(params *resource.Params, advancedVisStore config.
375376
}
376377

377378
func validateIndex(config *config.ElasticSearchConfig) {
378-
indexName, ok := config.Indices[common.VisibilityAppName]
379+
indexName, ok := config.Indices[constants.VisibilityAppName]
379380
if !ok || len(indexName) == 0 {
380381
log.Fatalf("Visibility index is missing in config")
381382
}

common/archiver/archivalMetadata.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
"fmt"
2525
"strings"
2626

27-
"github.com/uber/cadence/common"
2827
"github.com/uber/cadence/common/config"
28+
"github.com/uber/cadence/common/constants"
2929
"github.com/uber/cadence/common/dynamicconfig"
3030
"github.com/uber/cadence/common/types"
3131
)
@@ -197,11 +197,11 @@ func (a *archivalConfig) GetDomainDefaultURI() string {
197197
func getClusterArchivalStatus(str string) (ArchivalStatus, error) {
198198
str = strings.TrimSpace(strings.ToLower(str))
199199
switch str {
200-
case "", common.ArchivalDisabled:
200+
case "", constants.ArchivalDisabled:
201201
return ArchivalDisabled, nil
202-
case common.ArchivalPaused:
202+
case constants.ArchivalPaused:
203203
return ArchivalPaused, nil
204-
case common.ArchivalEnabled:
204+
case constants.ArchivalEnabled:
205205
return ArchivalEnabled, nil
206206
}
207207
return ArchivalDisabled, fmt.Errorf("invalid archival status of %v for cluster, valid status are: {\"\", \"disabled\", \"paused\", \"enabled\"}", str)
@@ -210,9 +210,9 @@ func getClusterArchivalStatus(str string) (ArchivalStatus, error) {
210210
func getDomainArchivalStatus(str string) (types.ArchivalStatus, error) {
211211
str = strings.TrimSpace(strings.ToLower(str))
212212
switch str {
213-
case "", common.ArchivalDisabled:
213+
case "", constants.ArchivalDisabled:
214214
return types.ArchivalStatusDisabled, nil
215-
case common.ArchivalEnabled:
215+
case constants.ArchivalEnabled:
216216
return types.ArchivalStatusEnabled, nil
217217
}
218218
return types.ArchivalStatusDisabled, fmt.Errorf("invalid archival status of %v for domain, valid status are: {\"\", \"disabled\", \"enabled\"}", str)

common/archiver/filestore/historyArchiver_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/uber/cadence/common"
3737
"github.com/uber/cadence/common/archiver"
3838
"github.com/uber/cadence/common/config"
39+
"github.com/uber/cadence/common/constants"
3940
"github.com/uber/cadence/common/log/testlogger"
4041
"github.com/uber/cadence/common/types"
4142
"github.com/uber/cadence/common/util"
@@ -203,7 +204,7 @@ func (s *historyArchiverSuite) TestArchive_Fail_HistoryMutated() {
203204
{
204205
Events: []*types.HistoryEvent{
205206
{
206-
ID: common.FirstEventID + 1,
207+
ID: constants.FirstEventID + 1,
207208
Timestamp: common.Int64Ptr(time.Now().UnixNano()),
208209
Version: testCloseFailoverVersion + 1,
209210
},
@@ -269,7 +270,7 @@ func (s *historyArchiverSuite) TestArchive_Skip() {
269270
{
270271
Events: []*types.HistoryEvent{
271272
{
272-
ID: common.FirstEventID,
273+
ID: constants.FirstEventID,
273274
Timestamp: common.Int64Ptr(time.Now().UnixNano()),
274275
Version: testCloseFailoverVersion,
275276
},
@@ -305,12 +306,12 @@ func (s *historyArchiverSuite) TestArchive_Success() {
305306
{
306307
Events: []*types.HistoryEvent{
307308
{
308-
ID: common.FirstEventID + 1,
309+
ID: constants.FirstEventID + 1,
309310
Timestamp: common.Int64Ptr(time.Now().UnixNano()),
310311
Version: testCloseFailoverVersion,
311312
},
312313
{
313-
ID: common.FirstEventID + 2,
314+
ID: constants.FirstEventID + 2,
314315
Timestamp: common.Int64Ptr(time.Now().UnixNano()),
315316
Version: testCloseFailoverVersion,
316317
},
@@ -581,12 +582,12 @@ func (s *historyArchiverSuite) setupHistoryDirectory() {
581582
{
582583
Events: []*types.HistoryEvent{
583584
{
584-
ID: common.FirstEventID + 1,
585+
ID: constants.FirstEventID + 1,
585586
Timestamp: common.Int64Ptr(time.Now().UnixNano()),
586587
Version: testCloseFailoverVersion,
587588
},
588589
{
589-
ID: common.FirstEventID + 1,
590+
ID: constants.FirstEventID + 1,
590591
Timestamp: common.Int64Ptr(time.Now().UnixNano()),
591592
Version: testCloseFailoverVersion,
592593
},

common/archiver/filestore/util_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/stretchr/testify/suite"
3232

3333
"github.com/uber/cadence/common"
34+
"github.com/uber/cadence/common/constants"
3435
"github.com/uber/cadence/common/types"
3536
"github.com/uber/cadence/common/util"
3637
)
@@ -58,20 +59,20 @@ func (s *UtilSuite) TestEncodeDecodeHistoryBatches() {
5859
{
5960
Events: []*types.HistoryEvent{
6061
{
61-
ID: common.FirstEventID,
62+
ID: constants.FirstEventID,
6263
Version: 1,
6364
},
6465
},
6566
},
6667
{
6768
Events: []*types.HistoryEvent{
6869
{
69-
ID: common.FirstEventID + 1,
70+
ID: constants.FirstEventID + 1,
7071
Timestamp: common.Int64Ptr(time.Now().UnixNano()),
7172
Version: 1,
7273
},
7374
{
74-
ID: common.FirstEventID + 2,
75+
ID: constants.FirstEventID + 2,
7576
Version: 2,
7677
DecisionTaskStartedEventAttributes: &types.DecisionTaskStartedEventAttributes{
7778
Identity: "some random identity",

0 commit comments

Comments
 (0)