dconfig

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2017 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetRefreshInterval added in v0.2.0

func SetRefreshInterval(interval time.Duration)

SetRefreshInterval is used to set the refresh interval

Types

type CassandraConfigManager

type CassandraConfigManager struct {
	// contains filtered or unexported fields
}

CassandraConfigManager is an implementation of ConfigManager backed by a config store that's built on top of Cassandra.

func (*CassandraConfigManager) Get

func (cfgMgr *CassandraConfigManager) Get(svc string, version string, sku string, host string) (interface{}, error)

Get returns the config value that best matches the given input criteria. svc param cannot be empty.

func (*CassandraConfigManager) Start

func (cfgMgr *CassandraConfigManager) Start()

Start starts the config manager

func (*CassandraConfigManager) Stop

func (cfgMgr *CassandraConfigManager) Stop()

Stop stops the config manager

func (*CassandraConfigManager) String

func (cfgMgr *CassandraConfigManager) String() string

type ConfigManager

type ConfigManager interface {
	// Get fetches and returns a config object that
	// best matches the specified input criteria. The
	// input parameters refer to the 4 levels in the
	// config hierarchy
	Get(svc string, version string, sku string, host string) (interface{}, error)

	//Start starts the config manager
	Start()

	//Stop stops the running config manager
	Stop()
}

ConfigManager refers to any implementation that vends config, backed by a config store which supports a hierarchial config structure with 4 pre-defined levels : (service, serviceVersion, sku, hostname)

func NewCassandraConfigManager

func NewCassandraConfigManager(mClient m.TChanMetadataService, configTypes map[string]interface{}, logger bark.Logger) ConfigManager

NewCassandraConfigManager constructs and returns an implementation of config managed backed by a store that's built on top of cassandra. The underlying config store supports configuration of key,values in a tree like structure with 4 pre-defined levels:

serviceName.serviceVersion.sku.hostname.key=value

where
   serviceName is the name of the service (ex - inputhost,outputhost, etc)
   serviceVersion identifes software version (ex -  manyrocks, v1.0 etc)
   sku identifies the hardware sku (ex - ec2.m1.12)
   hostname identifies a specific host (ex - cherami14)

The underlying config store supports wildcards to specify default values that apply to a broad category, subject to the following constraints:

(1) serviceName cannot be a wildcard
(2) if sku is a wildcard, hostname MUST also be a wildcard

Config Evaluation:

 In general, the config evaluator ALWAYS returns the most specific config
value that matches the given input constraints. The config levels from
most to least specific are (hostname, sku, serviceVersion, serviceName)

Example config:
     inputhost.*.*.*.maxExtents=111
     inputhost.*.ec2m112.*.maxExtents=222
     inputhost.v1.*.*.maxExtents=333
     inputhost.v1.m1large.*.maxExtents=444

Example Queries:
     Get(inputhost, *, *, *)        = 111
     Get(inputhost, v1, *, *)       = 333
     Get(inputhost, v1, ec2m112, *) = 222 --> BEWARE, defaults applied
     Get(inputhost, v1, m1large, *) = 444

The constructor to this class takes a configTypes param, which is a map of serviceName to configObjects. The config object MUST be of struct type and all members must be PUBLIC. The ConfigObject supports two pre-defined struct tags - name and default. name refers to the name of the config on the underlying store and default refers to the default value for that config param. Following are the data types supported for config params within the struct:

  • Int64

  • Float64

  • String

  • String slice ([]string - raw config value must be a csv)

    Example ConfigObject and config manager initialization

    type InputConfig struct { MaxExtents int64 `name:"max-extents" default:"50"` AdminStatus string `name:"admin-status" default:"enabled"` }

    cfgTypes := []map[string]interface{}{"inputhost": InputConfig{}} cfgMgr := NewCassandraConfigManager(mClient, cfgTypes, logger)

Automatic Refresh:

The returned config manager automatically syncs with the underlying
config store every minute. Callers must AVOID caching the result of
configManager.Get() to be able to respond to config changes.

Future Work:

Notifications to observers on config changes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL