func newdefaultClient() MemcacheClient { serverSelector := new(memcache.ServerList) client := memcache.NewFromSelector(serverSelector) // Listen for config changes ch := config.SubscribeChanges() go func() { for _ = range ch { loadFromConfig(serverSelector, client) } }() loadFromConfig(serverSelector, client) // Log on init hosts := config.AtPath("hailo", "service", "memcache", "servers").AsHostnameArray(11211) operationTimeout := config.AtPath("hailo", "service", "memcache", "timeouts", "dialTimeout"). AsDuration(defaultDialTimeout) dialTimeout := config.AtPath("hailo", "service", "memcache", "timeouts", "operationTimeout"). AsDuration(defaultOperationTimeout) log.Infof("[Memcache] Initialising Memcache client to hosts %v: dial timeout %v, op timeout: %v", hosts, dialTimeout, operationTimeout) return client }
// newAWsMgr returns a new AWS mgr instance // configPath determines where the awsAccounts config is stored in the config service in respect to your service // For example hailo/service/foo/awsAccounts. func newAwsMgr(configPath ...string) *AwsMgr { m := &AwsMgr{ Accounts: loadAccConfig(configPath...), sts: sts.NewSTSConnectionManager(), } ch := config.SubscribeChanges() hash, _ := config.LastLoaded() // Launch our config updater go func() { for _ = range ch { newHash, _ := config.LastLoaded() if hash != newHash { hash = newHash accs := loadAccConfig(configPath...) m.Lock() if len(accs) > 0 { m.Accounts = accs log.Debugf("[AWS Manager] Updating AWS Accounts:%v", m.Accounts) } m.Unlock() } } }() log.Debugf("[AWS Manager] Accounts: %v", m.Accounts) return m }
// New will mint a new Instrumentation - getting statsd connection details from the config service and then looking out // for any changes. func New() *Instrumentation { ch := config.SubscribeChanges() addr := loadStatsdAddr() inst := &Instrumentation{ namespace: "default", confHash: addr, statsd: loadStatsd(addr), registry: metrics.NewRegistry(), savedTimers: make(map[string]metrics.Timer), savedCounters: make(map[string]metrics.Counter), savedGauges: make(map[string]metrics.Gauge), launched: time.Now(), instRuntime: false, instRusage: false, } inst.StartRuntime() inst.StartRusage() // Launch listener for config changes go func() { for _ = range ch { inst.mtx.Lock() if addr := loadStatsdAddr(); addr != inst.confHash { // @todo close old statsd here -- but no way to do this yet inst.statsd = loadStatsd(addr) } inst.mtx.Unlock() } }() return inst }
// NewTimeout mints a blank timeout container from which we can calculate timeouts to use for requests func NewTimeout(c Client) *Timeout { t := &Timeout{ endpoints: make(map[string]map[string]time.Duration), client: c, } // trigger occasional background reloads of timeouts go func() { ticker := time.NewTicker(loadTimeoutsInterval) for { <-ticker.C t.reloadSlas() } }() // keep watch on config updates ch := config.SubscribeChanges() go func() { for { <-ch t.loadFromConfig() } }() t.loadFromConfig() return t }
// NewGlobalLocker returns a global leader which is basically just a region leader pinned to one region based on // config. func NewGlobalLeader(id string) Leader { for { if config.AtPath("leaders", "isLeader").AsBool() { break } <-config.SubscribeChanges() } return RegionLeader(id) }
// Try to connect, then kick off listener for config changes func setup() { ch := config.SubscribeChanges() go func() { for _ = range ch { reconnectDefault() } }() reconnectDefault() didSetup = true }
func setup() { ch := config.SubscribeChanges() go func() { for { <-ch loadEndpointConfig() } }() loadEndpointConfig() }
func init() { // Ensure we update config when required ch := config.SubscribeChanges() go func() { for { <-ch loadFromConfig() } }() loadFromConfig() }
// try to connect, then kick off listener for config changes func setup() { ch := config.SubscribeChanges() go func() { for { <-ch reconnectDefault() } }() reconnectDefault() }
func (rs *RedisDedupeClient) changeConfigSubscriber() { ch := config.SubscribeChanges() // Listen for config changes go func() { for { <-ch rs.connect() } }() }
func (e *gocqlExecutor) watchConfig() { configCh := config.SubscribeChanges() retryCh := make(chan struct{}) for { select { case <-configCh: e.reloadSession(retryCh) case <-retryCh: e.reloadSession(retryCh) } } }
// NewConnection mints a new Graphite connection which listens for config changes func NewConnection() *Connection { conn := &Connection{} ch := config.SubscribeChanges() go func() { for { <-ch conn.loadConfig() } }() conn.loadConfig() return conn }
// run is our main healthcheck loop func (r *results) run() { for { select { // Listen for config changes and update the healthcheck when needed case <-config.SubscribeChanges(): // Allow healthcheck parameters to be overridden in config config.AtPath("hailo", "platform", "healthcheck", r.hc.Id).AsStruct(r.hc) case <-runNow: r.collect() case <-time.After(r.hc.Interval): r.collect() } } }
func (s *DefaultSubscriber) configLoop() { // Wait 5 mins for config to load. If we cannot load config by the // then there's most likely a major issue and we should panic. if !config.WaitUntilLoaded(5 * time.Minute) { panic("Waiting 5 mins for config to load") } s.loadFromConfig() ch := config.SubscribeChanges() for { select { case <-ch: s.loadFromConfig() case <-s.stop: return } } }
// setup is a one-time action that loads PUB hosts from config and sets up a config subscriber func (p *HostpoolPublisher) setup() { // Wait 5 mins for config to load. If we cannot load config by the // then there's most likely a major issue and we should panic. if !config.WaitUntilLoaded(5 * time.Minute) { panic("Waiting 5 mins for config to load") } ch := config.SubscribeChanges() p.loadFromConfig() go func() { for { <-ch for { if err := p.loadFromConfig(); err != nil { log.Warnf("Failed to load NSQ PUB config: %v", err) time.Sleep(configRetryDelay) } else { break } } } }() }
// newConfigServiceValidator initiates a validator that loads public key location from config service func newConfigServiceValidator() validator { v := &validatorImpl{} v.hash = crypto.SHA1 ch := config.SubscribeChanges() immediate := make(chan bool) go func() { for { select { case <-ch: case <-immediate: } v.loadFromConfig() } }() // push immediate message down to force background reload immediate <- true return v }
// New will mint a new Tracer - getting phosphor connection details // from the config service and then looking out for any changes. func New() *Tracer { ch := config.SubscribeChanges() addr := loadPhosphorAddr() tr := &Tracer{ confHash: addr, phosphor: loadPhosphor(addr), } // launch listener for config changes go func() { for _ = range ch { addr := loadPhosphorAddr() tr.Lock() if addr != tr.confHash { tr.phosphor.Close() tr.phosphor = loadPhosphor(addr) } tr.Unlock() } }() return tr }