mirror of https://github.com/grafana/grafana
commit
0951da9c89
@ -0,0 +1,46 @@ |
||||
package utils |
||||
|
||||
import ( |
||||
"os" |
||||
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger" |
||||
) |
||||
|
||||
func GetGrafanaPluginDir(currentOS string) string { |
||||
//currentOS := runtime.GOOS
|
||||
|
||||
if currentOS == "windows" { |
||||
return returnOsDefault(currentOS) |
||||
} |
||||
|
||||
pwd, err := os.Getwd() |
||||
|
||||
if err != nil { |
||||
logger.Error("Could not get current path. using default") |
||||
return returnOsDefault(currentOS) |
||||
} |
||||
|
||||
if isDevenvironment(pwd) { |
||||
return "../data/plugins" |
||||
} |
||||
|
||||
return returnOsDefault(currentOS) |
||||
} |
||||
|
||||
func isDevenvironment(pwd string) bool { |
||||
// if ../conf/defaults.ini exists, grafana is not installed as package
|
||||
// that its in development environment.
|
||||
_, err := os.Stat("../conf/defaults.ini") |
||||
return err == nil |
||||
} |
||||
|
||||
func returnOsDefault(currentOs string) string { |
||||
switch currentOs { |
||||
case "windows": |
||||
return "../data/plugins" |
||||
case "darwin": |
||||
return "/usr/local/var/lib/grafana/plugins" |
||||
default: //"linux"
|
||||
return "/var/lib/grafana/plugins" |
||||
} |
||||
} |
@ -0,0 +1,76 @@ |
||||
package metrics |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"github.com/grafana/grafana/pkg/setting" |
||||
|
||||
. "github.com/smartystreets/goconvey/convey" |
||||
) |
||||
|
||||
func TestGraphitePublisher(t *testing.T) { |
||||
|
||||
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", "service.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, "service.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, "service.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") |
||||
|
||||
setting.InstanceName = "hostname.with.dots.com" |
||||
publisher, err := CreateGraphitePublisher() |
||||
|
||||
So(err, ShouldBeNil) |
||||
So(publisher, ShouldBeNil) |
||||
}) |
||||
} |
Loading…
Reference in new issue