Skip to content

Commit

Permalink
Improve logging for dynamic config
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng authored Nov 17, 2020
1 parent 11fde99 commit f9bb732
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion common/persistence/visibilitySamplingClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
numOfPriorityForList = 1
)

// ErrPersistenceLimitExceededForList is the error indicating QPS limit reached for list visibility.
// ErrPersistenceLimitExceededForList is the error indicating QPS limit reached for list visibility.
var ErrPersistenceLimitExceededForList = &workflow.ServiceBusyError{Message: "Persistence Max QPS Reached for List Operations."}

type visibilitySamplingClient struct {
Expand Down
6 changes: 6 additions & 0 deletions common/service/dynamicconfig/clientInterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ package dynamicconfig

import (
"time"

"github.com/uber/cadence/common/types"
)

// Client allows fetching values from a dynamic configuration system NOTE: This does not have async
Expand All @@ -45,3 +47,7 @@ type Client interface {
// UpdateValue takes value as map and updates by overriding. It doesn't support update with filters.
UpdateValue(name Key, value interface{}) error
}

var notFoundError = &types.EntityNotExistsError{
Message: "unable to find key",
}
9 changes: 7 additions & 2 deletions common/service/dynamicconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/uber/cadence/common/log"
"github.com/uber/cadence/common/log/tag"
"github.com/uber/cadence/common/types"
)

const (
Expand Down Expand Up @@ -65,7 +66,11 @@ func (c *Collection) logError(key Key, err error) {
errCount := atomic.AddInt64(&c.errCount, 1)
if errCount%errCountLogThreshold == 0 {
// log only every 'x' errors to reduce mem allocs and to avoid log noise
c.logger.Warn("Failed to fetch key from dynamic config", tag.Key(key.String()), tag.Error(err))
if _, ok := err.(*types.EntityNotExistsError); ok {
c.logger.Info("dynamic config not set, use default value", tag.Key(key.String()))
} else {
c.logger.Warn("Failed to fetch key from dynamic config", tag.Key(key.String()), tag.Error(err))
}
}
}

Expand All @@ -84,7 +89,7 @@ func (c *Collection) logValue(
c.logger.Info("Dynamic config has changed",
tag.Key(key.String()), tag.Value(value), tag.DefaultValue(loadedValue))
// update the logKeys so that we can capture the changes again
// (ignore the racing condition here because it's just for logging, we need a lock if really need to solve it)
// (ignore the racing condition here because it's just for logging, we need a lock if really need to solve it)
c.logKeys.Store(key, value)
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/service/dynamicconfig/file_based_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (fc *fileBasedClient) getValueWithFilters(key Key, filters map[Filter]inter
}
}
if !found {
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}
return defaultValue, nil
}
Expand Down
15 changes: 7 additions & 8 deletions common/service/dynamicconfig/inMemoryClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package dynamicconfig

import (
"errors"
"sync"
"time"
)
Expand Down Expand Up @@ -53,7 +52,7 @@ func (mc *inMemoryClient) GetValue(key Key, defaultValue interface{}) (interface
if val, ok := mc.globalValues[key]; ok {
return val, nil
}
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}

func (mc *inMemoryClient) GetValueWithFilters(
Expand All @@ -72,7 +71,7 @@ func (mc *inMemoryClient) GetIntValue(name Key, filters map[Filter]interface{},
if val, ok := mc.globalValues[name]; ok {
return val.(int), nil
}
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}

func (mc *inMemoryClient) GetFloatValue(name Key, filters map[Filter]interface{}, defaultValue float64) (float64, error) {
Expand All @@ -82,7 +81,7 @@ func (mc *inMemoryClient) GetFloatValue(name Key, filters map[Filter]interface{}
if val, ok := mc.globalValues[name]; ok {
return val.(float64), nil
}
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}

func (mc *inMemoryClient) GetBoolValue(name Key, filters map[Filter]interface{}, defaultValue bool) (bool, error) {
Expand All @@ -92,7 +91,7 @@ func (mc *inMemoryClient) GetBoolValue(name Key, filters map[Filter]interface{},
if val, ok := mc.globalValues[name]; ok {
return val.(bool), nil
}
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}

func (mc *inMemoryClient) GetStringValue(name Key, filters map[Filter]interface{}, defaultValue string) (string, error) {
Expand All @@ -102,7 +101,7 @@ func (mc *inMemoryClient) GetStringValue(name Key, filters map[Filter]interface{
if val, ok := mc.globalValues[name]; ok {
return val.(string), nil
}
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}

func (mc *inMemoryClient) GetMapValue(
Expand All @@ -114,7 +113,7 @@ func (mc *inMemoryClient) GetMapValue(
if val, ok := mc.globalValues[name]; ok {
return val.(map[string]interface{}), nil
}
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}

func (mc *inMemoryClient) GetDurationValue(
Expand All @@ -126,7 +125,7 @@ func (mc *inMemoryClient) GetDurationValue(
if val, ok := mc.globalValues[name]; ok {
return val.(time.Duration), nil
}
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}

func (mc *inMemoryClient) UpdateValue(key Key, value interface{}) error {
Expand Down
18 changes: 9 additions & 9 deletions common/service/dynamicconfig/nopClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,44 @@ import (
type nopClient struct{}

func (mc *nopClient) GetValue(name Key, defaultValue interface{}) (interface{}, error) {
return nil, errors.New("unable to find key")
return nil, notFoundError
}

func (mc *nopClient) GetValueWithFilters(
name Key, filters map[Filter]interface{}, defaultValue interface{},
) (interface{}, error) {
return nil, errors.New("unable to find key")
return nil, notFoundError
}

func (mc *nopClient) GetIntValue(name Key, filters map[Filter]interface{}, defaultValue int) (int, error) {
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}

func (mc *nopClient) GetFloatValue(name Key, filters map[Filter]interface{}, defaultValue float64) (float64, error) {
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}

func (mc *nopClient) GetBoolValue(name Key, filters map[Filter]interface{}, defaultValue bool) (bool, error) {
if filters[DomainName] == "TestRawHistoryDomain" {
return true, errors.New("unable to find key")
return true, notFoundError
}
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}

func (mc *nopClient) GetStringValue(name Key, filters map[Filter]interface{}, defaultValue string) (string, error) {
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}

func (mc *nopClient) GetMapValue(
name Key, filters map[Filter]interface{}, defaultValue map[string]interface{},
) (map[string]interface{}, error) {
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}

func (mc *nopClient) GetDurationValue(
name Key, filters map[Filter]interface{}, defaultValue time.Duration,
) (time.Duration, error) {
return defaultValue, errors.New("unable to find key")
return defaultValue, notFoundError
}

func (mc *nopClient) UpdateValue(name Key, value interface{}) error {
Expand Down

0 comments on commit f9bb732

Please sign in to comment.