예제 #1
0
func TestServeMux(t *testing.T) {
	buf := bytes.Buffer{}
	logger := log.JSONLoggerTo(&buf)
	recorder, _ := metrics.NewDatadogStatsdRecorder("127.0.0.1:8888", "namespace", "hostname")

	mux := coreapi.ServeMuxWithDefaults(logger, recorder, &monitoring.NoopMonitor{})
	handler := &TestHandler{t: t}
	endpoint := mux.EndpointFor("/test", handler.testHandlerFunc)
	ts := httptest.NewServer(endpoint)
	defer ts.Close()

	data := url.Values{}
	data.Set("test", "foo")
	res, _ := http.PostForm(ts.URL, data)

	if 200 != res.StatusCode {
		t.Errorf("should have status %#v, have status %#v", 200, res.StatusCode)
	}
	assertTimestampWithin(t, &buf)

	tags := endpoint.Metrics().(*metrics.DatadogStatsdRecorder).GetTags()
	if want, have := "url:/test", tags[0]; want != have {
		t.Errorf("want first tag %#v, have %#v", want, have)
	}

}
func TestDatadogStatsdTagKeyValue(t *testing.T) {
	recorder, _ := metrics.NewDatadogStatsdRecorder("127.0.0.1:8125", "namespace", "hostname")
	tagged := recorder.WithTag("tagkey", "tagvalue")
	tagged.MeasureSince("foo", time.Now())
	tags := tagged.(*metrics.DatadogStatsdRecorder).GetTags()

	if want, have := "tagkey:tagvalue", tags[0]; want != have {
		t.Errorf("want %#v tag, have %#v tag", want, have)
	}
}
예제 #3
0
func TestGetTeedMetricsRecorder(t *testing.T) {
	dd, _ := metrics.NewDatadogStatsdRecorder("127.0.0.1:8125", "namespace", "hostname")
	teed := metrics.NewTeedMetricsRecorder(dd)
	tagged := teed.WithTag("key", "")
	tags := (tagged.(*metrics.TeedMetricsRecorder).GetMetrics()[0]).(*metrics.DatadogStatsdRecorder).GetTags()

	if want, have := "key", tags[0]; want != have {
		t.Errorf("want %#v tag, have %#v tag", want, have)
	}
}
func TestDatadogStatsdTagsMakeNewInstance(t *testing.T) {
	recorder, _ := metrics.NewDatadogStatsdRecorder("127.0.0.1:8125", "namespace", "hostname")
	tagged := recorder.WithTag("tagkey", "tagvalue")

	if len(recorder.GetTags()) != 0 {
		t.Error("modified old recorder")
	}

	if len(tagged.(*metrics.DatadogStatsdRecorder).GetTags()) != 1 {
		t.Error("did not modify new recorder")
	}
}
func TestDatadogStatsdMultiTags(t *testing.T) {
	recorder, _ := metrics.NewDatadogStatsdRecorder("127.0.0.1:8125", "namespace", "hostname")
	tagged := recorder.WithTag("tagkey", "tagvalue")
	tagged = tagged.WithTag("anotherkey", "anothervalue")
	tags := tagged.(*metrics.DatadogStatsdRecorder).GetTags()

	if want, have := "tagkey:tagvalue", tags[0]; want != have {
		t.Errorf("want %#v tag, have %#v tag", want, have)
	}

	if want, have := "anotherkey:anothervalue", tags[1]; want != have {
		t.Errorf("want %#v tag, have %#v tag", want, have)
	}
}
예제 #6
0
func TestDatadogStatsdMetricTags(t *testing.T) {
	var dd metrics.MetricsRecorder
	dd, _ = metrics.NewDatadogStatsdRecorder("127.0.0.1:8888", "namespace", "hostname")
	dd = dd.WithTag("foo", "1")
	dd = dd.WithTag("bar", "2")

	tags := dd.(*metrics.DatadogStatsdRecorder).GetTags()

	if want, have := 2, len(tags); want != have {
		t.Errorf("want %#v tags, have %#v tags", want, have)
	}

	if want, have := "foo:1", tags[0]; want != have {
		t.Errorf("want first tag %#v, have %#v", want, have)
	}

	if want, have := "bar:2", tags[1]; want != have {
		t.Errorf("want second tag %#v, have %#v", want, have)
	}
}
func mockNewDogStatsdSink(addr string, tags []string, tagWithHostname bool) *metrics.DatadogStatsdRecorder {
	dog, _ := metrics.NewDatadogStatsdRecorder(addr, "namespace", "hostname")
	return dog
}
예제 #8
0
func TestGetDatadogStatsdMetric(t *testing.T) {
	dd, _ := metrics.NewDatadogStatsdRecorder("127.0.0.1:8888", "namespace", "hostname")
	dd.IncrementCount("countMetric")
	metrics.SetMetricsGlobal(dd)
	metrics.IncrementCount("countMetric")
}