graphite_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package metrics
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/setting"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestGraphitePublisher(t *testing.T) {
  8. Convey("Test graphite prefix replacement", t, func() {
  9. var err error
  10. err = setting.NewConfigContext(&setting.CommandLineArgs{
  11. HomePath: "../../",
  12. })
  13. So(err, ShouldBeNil)
  14. sec, err := setting.Cfg.NewSection("metrics.graphite")
  15. sec.NewKey("prefix", "service.grafana.%(instance_name)s.")
  16. sec.NewKey("address", "localhost:2003")
  17. So(err, ShouldBeNil)
  18. setting.InstanceName = "hostname.with.dots.com"
  19. publisher, err := CreateGraphitePublisher()
  20. So(err, ShouldBeNil)
  21. So(publisher, ShouldNotBeNil)
  22. So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.")
  23. })
  24. Convey("Test graphite publisher default values", t, func() {
  25. var err error
  26. err = setting.NewConfigContext(&setting.CommandLineArgs{
  27. HomePath: "../../",
  28. })
  29. So(err, ShouldBeNil)
  30. _, err = setting.Cfg.NewSection("metrics.graphite")
  31. setting.InstanceName = "hostname.with.dots.com"
  32. publisher, err := CreateGraphitePublisher()
  33. So(err, ShouldBeNil)
  34. So(publisher, ShouldNotBeNil)
  35. So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.")
  36. So(publisher.address, ShouldEqual, "localhost:2003")
  37. })
  38. }