Skip to content

Commit

Permalink
Change cadence config to dynamic (#851)
Browse files Browse the repository at this point in the history
* Add unit tests for Collection getProperty

* Change frontend config to dynamic

* Fix typo

* test

* revert test

* Change default property values

* Remove not used config and dead code

* Rename frontend config

* Add filter to frontend visibilityMaxPageSize

* Change frontend key name

* Add test

* Revert manual test

* Add filter to HistoryMaxPageSize

* Fix typo

* Change history cache

* Add timer configs

* Add transferQueueProcessor settings

* Add ReplicatorQueueProcessor settings

* Add persistence settings

* Add remaining settings

* Add remaining in matching

* Refactor keys from array to map

* refactor get property with domain filter

* Refactor property with filter

* Small change of hitoryReplicator log
  • Loading branch information
vancexu authored Jun 14, 2018
1 parent 1276b22 commit 1733b61
Show file tree
Hide file tree
Showing 31 changed files with 575 additions and 290 deletions.
2 changes: 1 addition & 1 deletion common/persistence/cassandraMetadataPersistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (m *cassandraMetadataPersistence) ListDomain(request *ListDomainRequest) (*
}

func (m *cassandraMetadataPersistence) GetMetadata() (*GetMetadataResponse, error) {
panic("cassandraMetadataPersistence do not supporgetsmetadatain operation.")
panic("cassandraMetadataPersistence do not support get metadata operation.")
}

func (m *cassandraMetadataPersistence) deleteDomain(name, ID string) error {
Expand Down
28 changes: 28 additions & 0 deletions common/service/dynamicconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ type PropertyFn func() interface{}
// IntPropertyFn is a wrapper to get int property from dynamic config
type IntPropertyFn func(opts ...FilterOption) int

// IntPropertyFn is a wrapper to get int property from dynamic config with domainName as filter
type IntPropertyFnWithDomainFilter func(domain string) int

// FloatPropertyFn is a wrapper to get float property from dynamic config
type FloatPropertyFn func(opts ...FilterOption) float64

// DurationPropertyFn is a wrapper to get duration property from dynamic config
type DurationPropertyFn func(opts ...FilterOption) time.Duration

// DurationPropertyFnWithDomainFilter is a wrapper to get duration property from dynamic config with domainName as filter
type DurationPropertyFnWithDomainFilter func(domain string) time.Duration

// BoolPropertyFn is a wrapper to get bool property from dynamic config
type BoolPropertyFn func(opts ...FilterOption) bool

Expand Down Expand Up @@ -121,3 +127,25 @@ func (c *Collection) GetBoolProperty(key Key, defaultValue bool) BoolPropertyFn
return val
}
}

// GetIntPropertyFilteredByDomain gets property with domain filter and asserts that it's an integer
func (c *Collection) GetIntPropertyFilteredByDomain(key Key, defaultValue int) IntPropertyFnWithDomainFilter {
return func(domain string) int {
val, err := c.client.GetIntValue(key, getFilterMap(DomainFilter(domain)), defaultValue)
if err != nil {
c.logNoValue(key, err)
}
return val
}
}

// GetDurationPropertyFilteredByDomain gets property with domain filter and asserts that it's a duration
func (c *Collection) GetDurationPropertyFilteredByDomain(key Key, defaultValue time.Duration) DurationPropertyFnWithDomainFilter {
return func(domain string) time.Duration {
val, err := c.client.GetDurationValue(key, getFilterMap(DomainFilter(domain)), defaultValue)
if err != nil {
c.logNoValue(key, err)
}
return val
}
}
45 changes: 45 additions & 0 deletions common/service/dynamicconfig/config_mock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 dynamicconfig

import "time"

// These mock functions are for tests to use config properties that are dynamic

// GetIntPropertyFn returns value as IntPropertyFn
func GetIntPropertyFn(value int) func(opts ...FilterOption) int {
return func(...FilterOption) int { return value }
}

// GetFloatPropertyFn returns value as FloatPropertyFn
func GetFloatPropertyFn(value float64) func(opts ...FilterOption) float64 {
return func(...FilterOption) float64 { return value }
}

// GetBoolPropertyFn returns value as BoolPropertyFn
func GetBoolPropertyFn(value bool) func(opts ...FilterOption) bool {
return func(...FilterOption) bool { return value }
}

// GetDurationPropertyFn returns value as DurationPropertyFn
func GetDurationPropertyFn(value time.Duration) func(opts ...FilterOption) time.Duration {
return func(...FilterOption) time.Duration { return value }
}
84 changes: 76 additions & 8 deletions common/service/dynamicconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,54 @@ func (mc *inMemoryClient) GetValueWithFilters(
}

func (mc *inMemoryClient) GetIntValue(name Key, filters map[Filter]interface{}, defaultValue int) (int, error) {
v := mc.globalValues.Load().(map[Key]interface{})
if val, ok := v[name]; ok {
return val.(int), nil
}
return defaultValue, errors.New("unable to find key")
}

func (mc *inMemoryClient) GetFloatValue(name Key, filters map[Filter]interface{}, defaultValue float64) (float64, error) {
v := mc.globalValues.Load().(map[Key]interface{})
if val, ok := v[name]; ok {
return val.(float64), nil
}
return defaultValue, errors.New("unable to find key")
}

func (mc *inMemoryClient) GetBoolValue(name Key, filters map[Filter]interface{}, defaultValue bool) (bool, error) {
v := mc.globalValues.Load().(map[Key]interface{})
if val, ok := v[name]; ok {
return val.(bool), nil
}
return defaultValue, errors.New("unable to find key")
}

func (mc *inMemoryClient) GetStringValue(name Key, filters map[Filter]interface{}, defaultValue string) (string, error) {
v := mc.globalValues.Load().(map[Key]interface{})
if val, ok := v[name]; ok {
return val.(string), nil
}
return defaultValue, errors.New("unable to find key")
}

func (mc *inMemoryClient) GetMapValue(
name Key, filters map[Filter]interface{}, defaultValue map[string]interface{},
) (map[string]interface{}, error) {
v := mc.globalValues.Load().(map[Key]interface{})
if val, ok := v[name]; ok {
return val.(map[string]interface{}), nil
}
return defaultValue, errors.New("unable to find key")
}

func (mc *inMemoryClient) GetDurationValue(
name Key, filters map[Filter]interface{}, defaultValue time.Duration,
) (time.Duration, error) {
v := mc.globalValues.Load().(map[Key]interface{})
if val, ok := v[name]; ok {
return val.(time.Duration), nil
}
return defaultValue, errors.New("unable to find key")
}

Expand All @@ -105,16 +129,60 @@ func (s *configSuite) SetupSuite() {
s.cln = NewCollection(s.client, bark.NewLoggerFromLogrus(logrus.New()))
}

func (s *configSuite) TestGetPropertyInt() {
key := MatchingMaxTaskBatchSize
size := s.cln.GetProperty(key, 10)
s.Equal(10, size())
func (s *configSuite) TestGetProperty() {
key := testGetPropertyKey
value := s.cln.GetProperty(key, "a")
s.Equal("a", value())
s.client.SetValue(key, "b")
s.Equal("b", value())
}

func (s *configSuite) TestGetIntProperty() {
key := testGetIntPropertyKey
value := s.cln.GetIntProperty(key, 10)
s.Equal(10, value())
s.client.SetValue(key, 50)
s.Equal(50, size().(int))
s.Equal(50, value())
}

func (s *configSuite) TestGetFloat64Property() {
key := testGetFloat64PropertyKey
value := s.cln.GetFloat64Property(key, 0.1)
s.Equal(0.1, value())
s.client.SetValue(key, 0.01)
s.Equal(0.01, value())
}

func (s *configSuite) TestGetBoolProperty() {
key := testGetBoolPropertyKey
value := s.cln.GetBoolProperty(key, true)
s.Equal(true, value())
s.client.SetValue(key, false)
s.Equal(false, value())
}

func (s *configSuite) TestGetDurationProperty() {
key := MatchingLongPollExpirationInterval
interval := s.cln.GetDurationProperty(key, time.Second)
s.Equal(time.Second, interval())
key := testGetDurationPropertyKey
value := s.cln.GetDurationProperty(key, time.Second)
s.Equal(time.Second, value())
s.client.SetValue(key, time.Minute)
s.Equal(time.Minute, value())
}

func (s *configSuite) TestGetIntPropertyFilteredByDomain() {
key := testGetIntPropertyFilteredByDomainKey
domain := "testDomain"
value := s.cln.GetIntPropertyFilteredByDomain(key, 10)
s.Equal(10, value(domain))
s.client.SetValue(key, 50)
s.Equal(50, value(domain))
}

func (s *configSuite) TestGetDurationPropertyFilteredByDomain() {
key := testGetDurationPropertyFilteredByDomainKey
domain := "testDomain"
value := s.cln.GetDurationPropertyFilteredByDomain(key, time.Second)
s.Equal(time.Second, value(domain))
s.client.SetValue(key, time.Minute)
s.Equal(time.Minute, value(domain))
}
Loading

0 comments on commit 1733b61

Please sign in to comment.