Example #1
0
// 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,
	}

	inst.StartRuntime()

	// 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
}
Example #2
0
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
}
Example #3
0
// Try to connect, then kick off listener for config changes
func setup() {
	ch := config.SubscribeChanges()
	go func() {
		for _ = range ch {
			reconnectDefault()
		}
	}()
	reconnectDefault()
	didSetup = true
}
Example #4
0
func init() {
	// Ensure we update config when required
	ch := config.SubscribeChanges()
	go func() {
		for {
			<-ch
			loadFromConfig()
		}
	}()
	loadFromConfig()
}
Example #5
0
// 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()
		}
	}
}
Example #6
0
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:
			break
		}
	}
}
Example #7
0
// 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
				}
			}
		}
	}()
}
Example #8
0
// 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
}
Example #9
0
// 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
}