Beispiel #1
0
func TestCollectorLogsErrors(t *testing.T) {
	testLogger := test_utils.BuildLogger()
	testLogger = testLogger.WithField("collector", "Test")

	channel := make(chan metric.Metric)
	config := make(map[string]interface{})

	testCol := collector.NewTest(channel, 123, testLogger)
	testCol.Configure(config)

	timeout := time.Duration(5 * time.Second)
	h := handler.NewTest(channel, 10, 10, timeout, testLogger)

	hook := NewLogErrorHook([]handler.Handler{h})
	testLogger.Logger.Hooks.Add(hook)

	go testCol.Collect()
	testLogger.Error("testing Error log")

	select {
	case m := <-h.Channel():
		assert.Equal(t, "fullerite.collector_errors", m.Name)
		assert.Equal(t, 1.0, m.Value)
		assert.Equal(t, "Test", m.Dimensions["collector"])
		return
	case <-time.After(1 * time.Second):
		t.Fail()
	}
}
Beispiel #2
0
func TestCanSendMetrics(t *testing.T) {
	logrus.SetLevel(logrus.PanicLevel)

	channel := make(chan metric.Metric, 5)
	timeout := time.Duration(5 * time.Second)
	log := logrus.WithFields(logrus.Fields{"app": "fullerite", "pkg": "handler"})
	h := handler.NewTest(channel, 10, 10, timeout, log)
	c := config.Config{
		Collectors: []string{"coll1", "coll2", "coll3"},
	}
	h.InitListeners(c)

	checkEmission(t, "coll1", h, true)
	checkEmission(t, "coll2", h, true)
	checkEmission(t, "coll3", h, true)
}