forked from uber/cadence
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dynamicconfig.go
192 lines (172 loc) · 6.44 KB
/
dynamicconfig.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package host
import (
"sync"
"time"
"github.com/uber/cadence/common"
"github.com/uber/cadence/common/dynamicconfig"
"github.com/uber/cadence/common/types"
)
var (
// Override values for dynamic configs
staticOverrides = map[dynamicconfig.Key]interface{}{
dynamicconfig.FrontendUserRPS: 3000,
dynamicconfig.FrontendVisibilityListMaxQPS: 200,
dynamicconfig.FrontendESIndexMaxResultWindow: defaultTestValueOfESIndexMaxResultWindow,
dynamicconfig.MatchingNumTasklistWritePartitions: 3,
dynamicconfig.MatchingNumTasklistReadPartitions: 3,
dynamicconfig.TimerProcessorHistoryArchivalSizeLimit: 5 * 1024,
dynamicconfig.ReplicationTaskProcessorErrorRetryMaxAttempts: 1,
dynamicconfig.AdvancedVisibilityWritingMode: common.AdvancedVisibilityWritingModeOff,
dynamicconfig.DecisionHeartbeatTimeout: 5 * time.Second,
dynamicconfig.ReplicationTaskFetcherAggregationInterval: 200 * time.Millisecond,
dynamicconfig.ReplicationTaskFetcherErrorRetryWait: 50 * time.Millisecond,
dynamicconfig.ReplicationTaskProcessorErrorRetryWait: time.Millisecond,
dynamicconfig.EnableConsistentQueryByDomain: true,
dynamicconfig.MinRetentionDays: 0,
}
)
type dynamicClient struct {
sync.RWMutex
overrides map[dynamicconfig.Key]interface{}
client dynamicconfig.Client
}
func (d *dynamicClient) GetValue(name dynamicconfig.Key, defaultValue interface{}) (interface{}, error) {
d.RLock()
if val, ok := d.overrides[name]; ok {
d.RUnlock()
return val, nil
}
d.RUnlock()
return d.client.GetValue(name, defaultValue)
}
func (d *dynamicClient) GetValueWithFilters(
name dynamicconfig.Key, filters map[dynamicconfig.Filter]interface{}, defaultValue interface{},
) (interface{}, error) {
d.RLock()
if val, ok := d.overrides[name]; ok {
d.RUnlock()
return val, nil
}
d.RUnlock()
return d.client.GetValueWithFilters(name, filters, defaultValue)
}
func (d *dynamicClient) GetIntValue(name dynamicconfig.Key, filters map[dynamicconfig.Filter]interface{}, defaultValue int) (int, error) {
d.RLock()
if val, ok := d.overrides[name]; ok {
if intVal, ok := val.(int); ok {
d.RUnlock()
return intVal, nil
}
}
d.RUnlock()
return d.client.GetIntValue(name, filters, defaultValue)
}
func (d *dynamicClient) GetFloatValue(name dynamicconfig.Key, filters map[dynamicconfig.Filter]interface{}, defaultValue float64) (float64, error) {
d.RLock()
if val, ok := d.overrides[name]; ok {
if floatVal, ok := val.(float64); ok {
d.RUnlock()
return floatVal, nil
}
}
d.RUnlock()
return d.client.GetFloatValue(name, filters, defaultValue)
}
func (d *dynamicClient) GetBoolValue(name dynamicconfig.Key, filters map[dynamicconfig.Filter]interface{}, defaultValue bool) (bool, error) {
d.RLock()
if val, ok := d.overrides[name]; ok {
if boolVal, ok := val.(bool); ok {
d.RUnlock()
return boolVal, nil
}
}
d.RUnlock()
return d.client.GetBoolValue(name, filters, defaultValue)
}
func (d *dynamicClient) GetStringValue(name dynamicconfig.Key, filters map[dynamicconfig.Filter]interface{}, defaultValue string) (string, error) {
d.RLock()
if val, ok := d.overrides[name]; ok {
if stringVal, ok := val.(string); ok {
d.RUnlock()
return stringVal, nil
}
}
d.RUnlock()
return d.client.GetStringValue(name, filters, defaultValue)
}
func (d *dynamicClient) GetMapValue(
name dynamicconfig.Key, filters map[dynamicconfig.Filter]interface{}, defaultValue map[string]interface{},
) (map[string]interface{}, error) {
d.RLock()
if val, ok := d.overrides[name]; ok {
if mapVal, ok := val.(map[string]interface{}); ok {
d.RUnlock()
return mapVal, nil
}
}
d.RUnlock()
return d.client.GetMapValue(name, filters, defaultValue)
}
func (d *dynamicClient) GetDurationValue(
name dynamicconfig.Key, filters map[dynamicconfig.Filter]interface{}, defaultValue time.Duration,
) (time.Duration, error) {
d.RLock()
if val, ok := d.overrides[name]; ok {
if durationVal, ok := val.(time.Duration); ok {
d.RUnlock()
return durationVal, nil
}
}
d.RUnlock()
return d.client.GetDurationValue(name, filters, defaultValue)
}
func (d *dynamicClient) UpdateValue(name dynamicconfig.Key, value interface{}) error {
if name == dynamicconfig.AdvancedVisibilityWritingMode { // override for es integration tests
d.Lock()
defer d.Unlock()
d.overrides[dynamicconfig.AdvancedVisibilityWritingMode] = value.(string)
return nil
}
return d.client.UpdateValue(name, value)
}
func (d *dynamicClient) OverrideValue(name dynamicconfig.Key, value interface{}) {
d.Lock()
defer d.Unlock()
d.overrides[name] = value
}
func (d *dynamicClient) ListValue(name dynamicconfig.Key) ([]*types.DynamicConfigEntry, error) {
return d.client.ListValue(name)
}
func (d *dynamicClient) RestoreValue(name dynamicconfig.Key, filters map[dynamicconfig.Filter]interface{}) error {
return d.client.RestoreValue(name, filters)
}
// newIntegrationConfigClient - returns a dynamic config client for integration testing
func newIntegrationConfigClient(client dynamicconfig.Client) *dynamicClient {
integrationClient := &dynamicClient{
overrides: make(map[dynamicconfig.Key]interface{}),
client: client,
}
for key, value := range staticOverrides {
integrationClient.OverrideValue(key, value)
}
return integrationClient
}