graphite_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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", "prod.grafana.%(instance_name)s.")
  16. sec.NewKey("address", "localhost:2001")
  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, "prod.grafana.hostname_with_dots_com.")
  23. So(publisher.address, ShouldEqual, "localhost:2001")
  24. })
  25. Convey("Test graphite publisher default prefix", t, func() {
  26. var err error
  27. err = setting.NewConfigContext(&setting.CommandLineArgs{
  28. HomePath: "../../",
  29. })
  30. So(err, ShouldBeNil)
  31. sec, err := setting.Cfg.NewSection("metrics.graphite")
  32. sec.NewKey("address", "localhost:2001")
  33. So(err, ShouldBeNil)
  34. setting.InstanceName = "hostname.with.dots.com"
  35. publisher, err := CreateGraphitePublisher()
  36. So(err, ShouldBeNil)
  37. So(publisher, ShouldNotBeNil)
  38. So(publisher.prefix, ShouldEqual, "prod.grafana.hostname_with_dots_com.")
  39. So(publisher.address, ShouldEqual, "localhost:2001")
  40. })
  41. Convey("Test graphite publisher default values", t, func() {
  42. var err error
  43. err = setting.NewConfigContext(&setting.CommandLineArgs{
  44. HomePath: "../../",
  45. })
  46. So(err, ShouldBeNil)
  47. _, err = setting.Cfg.NewSection("metrics.graphite")
  48. setting.InstanceName = "hostname.with.dots.com"
  49. publisher, err := CreateGraphitePublisher()
  50. So(err, ShouldBeNil)
  51. So(publisher, ShouldBeNil)
  52. })
  53. }