The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/metrics/graphite_test.go

77 lines
1.8 KiB

package metrics
import (
"testing"
"github.com/grafana/grafana/pkg/setting"
. "github.com/smartystreets/goconvey/convey"
)
func TestGraphitePublisher(t *testing.T) {
setting.CustomInitPath = "conf/does_not_exist.ini"
Convey("Test graphite prefix replacement", t, func() {
var err error
err = setting.NewConfigContext(&setting.CommandLineArgs{
HomePath: "../../",
})
So(err, ShouldBeNil)
sec, err := setting.Cfg.NewSection("metrics.graphite")
sec.NewKey("prefix", "prod.grafana.%(instance_name)s.")
sec.NewKey("address", "localhost:2001")
So(err, ShouldBeNil)
setting.InstanceName = "hostname.with.dots.com"
publisher, err := CreateGraphitePublisher()
So(err, ShouldBeNil)
So(publisher, ShouldNotBeNil)
So(publisher.prefix, ShouldEqual, "prod.grafana.hostname_with_dots_com.")
So(publisher.address, ShouldEqual, "localhost:2001")
})
Convey("Test graphite publisher default prefix", t, func() {
var err error
err = setting.NewConfigContext(&setting.CommandLineArgs{
HomePath: "../../",
})
So(err, ShouldBeNil)
sec, err := setting.Cfg.NewSection("metrics.graphite")
sec.NewKey("address", "localhost:2001")
So(err, ShouldBeNil)
setting.InstanceName = "hostname.with.dots.com"
publisher, err := CreateGraphitePublisher()
So(err, ShouldBeNil)
So(publisher, ShouldNotBeNil)
So(publisher.prefix, ShouldEqual, "prod.grafana.hostname_with_dots_com.")
So(publisher.address, ShouldEqual, "localhost:2001")
})
Convey("Test graphite publisher default values", t, func() {
var err error
err = setting.NewConfigContext(&setting.CommandLineArgs{
HomePath: "../../",
})
So(err, ShouldBeNil)
_, err = setting.Cfg.NewSection("metrics.graphite")
publisher, err := CreateGraphitePublisher()
So(err, ShouldBeNil)
So(publisher, ShouldBeNil)
})
}