graphite_test.go 1.8 KB

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