func TestCollectorPrefix(t *testing.T) { logrus.SetLevel(logrus.ErrorLevel) c := make(map[string]interface{}) c["interval"] = 1 c["prefix"] = "px." collector := collector.New("Test") collector.SetInterval(1) collector.Configure(c) collectorChannel := map[string]chan metric.Metric{ "Test": make(chan metric.Metric), } testHandler := handler.New("Log") testHandler.SetCollectorChannels(collectorChannel) var wg sync.WaitGroup wg.Add(2) go func() { defer wg.Done() collector.Channel() <- metric.New("hello") close(collector.Channel()) }() go func() { defer wg.Done() testMetric := <-collectorChannel["Test"] assert.Equal(t, "px.hello", testMetric.Name) }() readFromCollector(collector, []handler.Handler{testHandler}) wg.Wait() }
func newHandler(name string, c config.Config, dps int) handler.Handler { h := handler.New(name) h.SetInterval(1) h.SetMaxBufferSize(dps) h.Configure(c.Handlers[name]) return h }
func startHandler(name string, globalConfig config.Config, config map[string]interface{}) handler.Handler { log.Debug("Starting handler ", name) handler := handler.New(name) // apply any global configs handler.SetInterval(globalConfig.Interval) handler.SetPrefix(globalConfig.Prefix) handler.SetDefaultDimensions(globalConfig.DefaultDimensions) // now apply the handler level configs handler.Configure(config) go handler.Run() return handler }
func startHandler(name string, globalConfig config.Config, instanceConfig map[string]interface{}) handler.Handler { log.Info("Starting handler ", name) handlerInst := handler.New(name) if handlerInst == nil { return nil } // apply any global configs handlerInst.SetInterval(config.GetAsInt(globalConfig.Interval, handler.DefaultInterval)) handlerInst.SetPrefix(globalConfig.Prefix) handlerInst.SetDefaultDimensions(globalConfig.DefaultDimensions) // now apply the handler level configs handlerInst.Configure(instanceConfig) go handlerInst.Run() return handlerInst }
func createHandler(name string, globalConfig config.Config, instanceConfig map[string]interface{}) handler.Handler { handlerInst := handler.New(name) if handlerInst == nil { return nil } // apply any global configs handlerInst.SetInterval(config.GetAsInt(globalConfig.Interval, handler.DefaultInterval)) handlerInst.SetPrefix(globalConfig.Prefix) handlerInst.SetDefaultDimensions(globalConfig.DefaultDimensions) // now apply the handler level configs handlerInst.Configure(instanceConfig) // now run a listener channel for each collector handlerInst.InitListeners(globalConfig) return handlerInst }
func startHandlers(c Config) (handlers []handler.Handler) { log.Info("Starting handlers...") for name, config := range c.Handlers { handler := handler.New(name) // apply any global configs handler.SetInterval(c.Interval) handler.SetPrefix(c.Prefix) handler.SetDefaultDimensions(c.DefaultDimensions) // now apply the handler level configs handler.Configure(&config) handlers = append(handlers, handler) log.Info("Running ", handler) go handler.Run() } return handlers }
func buildHandler(name string) handler.Handler { log.Println("Building handler", name) handler := handler.New(name) return handler }