From 7a913f77d31126ed0dc05ca90faa69c625ceafdc Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 15 Aug 2016 08:54:35 +0200 Subject: [PATCH 01/16] feat(cli): add default plugin folder for MAC OS closes #5806 --- pkg/cmd/grafana-cli/main.go | 32 +--------------- pkg/cmd/grafana-cli/utils/grafana_path.go | 46 +++++++++++++++++++++++ 2 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 pkg/cmd/grafana-cli/utils/grafana_path.go diff --git a/pkg/cmd/grafana-cli/main.go b/pkg/cmd/grafana-cli/main.go index 131d9189022..fbdec792322 100644 --- a/pkg/cmd/grafana-cli/main.go +++ b/pkg/cmd/grafana-cli/main.go @@ -8,39 +8,11 @@ import ( "github.com/codegangsta/cli" "github.com/grafana/grafana/pkg/cmd/grafana-cli/commands" "github.com/grafana/grafana/pkg/cmd/grafana-cli/logger" + "github.com/grafana/grafana/pkg/cmd/grafana-cli/utils" ) var version = "master" -func getGrafanaPluginDir() string { - currentOS := runtime.GOOS - defaultNix := "/var/lib/grafana/plugins" - - if currentOS == "windows" { - return "../data/plugins" - } - - pwd, err := os.Getwd() - - if err != nil { - logger.Error("Could not get current path. using default") - return defaultNix - } - - if isDevenvironment(pwd) { - return "../data/plugins" - } - - return defaultNix -} - -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 main() { setupLogging() @@ -54,7 +26,7 @@ func main() { cli.StringFlag{ Name: "pluginsDir", Usage: "path to the grafana plugin directory", - Value: getGrafanaPluginDir(), + Value: utils.GetGrafanaPluginDir(runtime.GOOS), EnvVar: "GF_PLUGIN_DIR", }, cli.StringFlag{ diff --git a/pkg/cmd/grafana-cli/utils/grafana_path.go b/pkg/cmd/grafana-cli/utils/grafana_path.go new file mode 100644 index 00000000000..fa6dc46d783 --- /dev/null +++ b/pkg/cmd/grafana-cli/utils/grafana_path.go @@ -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" + } +} From 7ce13ef0754e3fe8a25364e9fa2fc68ea2276615 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 15 Aug 2016 09:13:49 +0200 Subject: [PATCH 02/16] docs(changelog): add note about fixing #5806 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 083de33599e..199221cd4a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * **Templating**: Fixed issue when combining row & panel repeats, fixes [#5790](https://github.com/grafana/grafana/issues/5790) * **Drag&Drop**: Fixed issue with drag and drop in latest Chrome(51+), fixes [#5767](https://github.com/grafana/grafana/issues/5767) * **Internal Metrics**: Fixed issue with dots in instance_name when sending internal metrics to Graphitge, fixes [#5739](https://github.com/grafana/grafana/issues/5739) +* **Grafana-CLI**: Add default plugin path for MAC OS, fixes [#5806](https://github.com/grafana/grafana/issues/5806) # 3.1.1 (2016-08-01) * **IFrame embedding**: Fixed issue of using full iframe height, fixes [#5605](https://github.com/grafana/grafana/issues/5606) From cd9bd5be17438c20a89485530c802a091fdf269c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 15 Aug 2016 09:15:20 +0200 Subject: [PATCH 03/16] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 199221cd4a1..79d0057870b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ # 3.1.2 (unreleased) * **Templating**: Fixed issue when combining row & panel repeats, fixes [#5790](https://github.com/grafana/grafana/issues/5790) * **Drag&Drop**: Fixed issue with drag and drop in latest Chrome(51+), fixes [#5767](https://github.com/grafana/grafana/issues/5767) -* **Internal Metrics**: Fixed issue with dots in instance_name when sending internal metrics to Graphitge, fixes [#5739](https://github.com/grafana/grafana/issues/5739) +* **Internal Metrics**: Fixed issue with dots in instance_name when sending internal metrics to Graphite, fixes [#5739](https://github.com/grafana/grafana/issues/5739) * **Grafana-CLI**: Add default plugin path for MAC OS, fixes [#5806](https://github.com/grafana/grafana/issues/5806) # 3.1.1 (2016-08-01) From 2b2e015d62201a1b321c3f6373b1cee4cb1623e7 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 15 Aug 2016 08:54:35 +0200 Subject: [PATCH 04/16] feat(cli): add default plugin folder for MAC OS closes #5806 --- pkg/cmd/grafana-cli/main.go | 32 +--------------- pkg/cmd/grafana-cli/utils/grafana_path.go | 46 +++++++++++++++++++++++ 2 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 pkg/cmd/grafana-cli/utils/grafana_path.go diff --git a/pkg/cmd/grafana-cli/main.go b/pkg/cmd/grafana-cli/main.go index 131d9189022..fbdec792322 100644 --- a/pkg/cmd/grafana-cli/main.go +++ b/pkg/cmd/grafana-cli/main.go @@ -8,39 +8,11 @@ import ( "github.com/codegangsta/cli" "github.com/grafana/grafana/pkg/cmd/grafana-cli/commands" "github.com/grafana/grafana/pkg/cmd/grafana-cli/logger" + "github.com/grafana/grafana/pkg/cmd/grafana-cli/utils" ) var version = "master" -func getGrafanaPluginDir() string { - currentOS := runtime.GOOS - defaultNix := "/var/lib/grafana/plugins" - - if currentOS == "windows" { - return "../data/plugins" - } - - pwd, err := os.Getwd() - - if err != nil { - logger.Error("Could not get current path. using default") - return defaultNix - } - - if isDevenvironment(pwd) { - return "../data/plugins" - } - - return defaultNix -} - -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 main() { setupLogging() @@ -54,7 +26,7 @@ func main() { cli.StringFlag{ Name: "pluginsDir", Usage: "path to the grafana plugin directory", - Value: getGrafanaPluginDir(), + Value: utils.GetGrafanaPluginDir(runtime.GOOS), EnvVar: "GF_PLUGIN_DIR", }, cli.StringFlag{ diff --git a/pkg/cmd/grafana-cli/utils/grafana_path.go b/pkg/cmd/grafana-cli/utils/grafana_path.go new file mode 100644 index 00000000000..fa6dc46d783 --- /dev/null +++ b/pkg/cmd/grafana-cli/utils/grafana_path.go @@ -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" + } +} From 0524d0c625529f5109f75bcd3953173d38e616fe Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 9 Aug 2016 11:07:26 +0200 Subject: [PATCH 05/16] fix(metrics): replaces . with _ in instance name closes #5739 --- circle.yml | 2 +- conf/defaults.ini | 2 +- conf/sample.ini | 8 ++++---- pkg/metrics/graphite.go | 9 +++++++-- pkg/metrics/graphite_test.go | 31 +++++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 pkg/metrics/graphite_test.go diff --git a/circle.yml b/circle.yml index ee19b50ee46..28c36763d9e 100644 --- a/circle.yml +++ b/circle.yml @@ -23,7 +23,7 @@ test: # GO VET - go vet ./pkg/... # Go test - - godep go test -v ./pkg/... + - godep go test ./pkg/... # js tests - npm test - npm run coveralls diff --git a/conf/defaults.ini b/conf/defaults.ini index c087fcf1ab1..94c653e74be 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -353,7 +353,7 @@ enabled = true interval_seconds = 60 # Send internal Grafana metrics to graphite -; [metrics.graphite] +[metrics.graphite] ; address = localhost:2003 ; prefix = prod.grafana.%(instance_name)s. diff --git a/conf/sample.ini b/conf/sample.ini index 811f4bbcc51..88247c57297 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -297,15 +297,15 @@ check_for_updates = true # Metrics available at HTTP API Url /api/metrics [metrics] # Disable / Enable internal metrics -;enabled = true +enabled = true # Publish interval ;interval_seconds = 10 -# Send internal metrics to Graphite -; [metrics.graphite] +# Send internal metrics to Graphite. %instance_name% in prefix will be replaced with the value of instance_name +[metrics.graphite] ; address = localhost:2003 -; prefix = prod.grafana.%(instance_name)s. +; prefix = service.grafana.%instance_name% #################################### Internal Grafana Metrics ########################## # Url used to to import dashboards directly from Grafana.net diff --git a/pkg/metrics/graphite.go b/pkg/metrics/graphite.go index a232b97905e..a384b7f9d28 100644 --- a/pkg/metrics/graphite.go +++ b/pkg/metrics/graphite.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "net" + "strings" "time" "github.com/grafana/grafana/pkg/log" @@ -20,14 +21,18 @@ type GraphitePublisher struct { func CreateGraphitePublisher() (*GraphitePublisher, error) { graphiteSection, err := setting.Cfg.GetSection("metrics.graphite") if err != nil { - return nil, nil + return nil, err } publisher := &GraphitePublisher{} publisher.prevCounts = make(map[string]int64) publisher.protocol = "tcp" publisher.address = graphiteSection.Key("address").MustString("localhost:2003") - publisher.prefix = graphiteSection.Key("prefix").MustString("service.grafana.%(instance_name)s") + + safeInstanceName := strings.Replace(setting.InstanceName, ".", "_", -1) + prefix := graphiteSection.Key("prefix").MustString("service.grafana.%instance_name%") + + publisher.prefix = strings.Replace(prefix, "%instance_name%", safeInstanceName, -1) return publisher, nil } diff --git a/pkg/metrics/graphite_test.go b/pkg/metrics/graphite_test.go new file mode 100644 index 00000000000..764214fcb10 --- /dev/null +++ b/pkg/metrics/graphite_test.go @@ -0,0 +1,31 @@ +package metrics + +import ( + "testing" + + "github.com/grafana/grafana/pkg/setting" + + . "github.com/smartystreets/goconvey/convey" +) + +func TestGraphitePublisher(t *testing.T) { + + Convey("Test graphite prefix", t, func() { + err := setting.NewConfigContext(&setting.CommandLineArgs{ + HomePath: "../../", + Args: []string{ + "cfg:metrics.graphite.prefix=service.grafana.%instance_name%", + "cfg:metrics.graphite.address=localhost:2003", + }, + }) + So(err, ShouldBeNil) + + setting.InstanceName = "hostname.with.dots.com" + publisher, err2 := CreateGraphitePublisher() + + So(err2, ShouldBeNil) + So(publisher, ShouldNotBeNil) + + So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com") + }) +} From 2c1b893c5577528ee2911ea9601c8ff533fdd661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 10 Aug 2016 08:06:10 +0200 Subject: [PATCH 06/16] feat(metrics): minor fix for internal metrics fix PR #5758 --- conf/defaults.ini | 4 ++-- conf/sample.ini | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 94c653e74be..8c3fb36dded 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -353,9 +353,9 @@ enabled = true interval_seconds = 60 # Send internal Grafana metrics to graphite -[metrics.graphite] +; [metrics.graphite] ; address = localhost:2003 -; prefix = prod.grafana.%(instance_name)s. +; prefix = service.grafana.%(instance_name)s. [grafana_net] url = https://grafana.net diff --git a/conf/sample.ini b/conf/sample.ini index 88247c57297..de407cd1ad5 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -303,7 +303,7 @@ enabled = true ;interval_seconds = 10 # Send internal metrics to Graphite. %instance_name% in prefix will be replaced with the value of instance_name -[metrics.graphite] +; [metrics.graphite] ; address = localhost:2003 ; prefix = service.grafana.%instance_name% From ebecc5e5a0e025f4b64ae59dccaba844e8cf37bf Mon Sep 17 00:00:00 2001 From: bergquist Date: Wed, 10 Aug 2016 11:15:27 +0200 Subject: [PATCH 07/16] fix(metrics): make metrics cfg backwards compatible --- conf/defaults.ini | 2 +- conf/sample.ini | 4 ++-- pkg/metrics/graphite.go | 8 ++++++-- pkg/metrics/graphite_test.go | 40 ++++++++++++++++++++++++++++-------- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 8c3fb36dded..2c70d039e6b 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -355,7 +355,7 @@ interval_seconds = 60 # Send internal Grafana metrics to graphite ; [metrics.graphite] ; address = localhost:2003 -; prefix = service.grafana.%(instance_name)s. +; prefix = service.grafana.%(instance_name)s [grafana_net] url = https://grafana.net diff --git a/conf/sample.ini b/conf/sample.ini index de407cd1ad5..ab6c125e848 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -302,10 +302,10 @@ enabled = true # Publish interval ;interval_seconds = 10 -# Send internal metrics to Graphite. %instance_name% in prefix will be replaced with the value of instance_name +# Send internal metrics to Graphite ; [metrics.graphite] ; address = localhost:2003 -; prefix = service.grafana.%instance_name% +; prefix = service.grafana.%(instance_name)s #################################### Internal Grafana Metrics ########################## # Url used to to import dashboards directly from Grafana.net diff --git a/pkg/metrics/graphite.go b/pkg/metrics/graphite.go index a384b7f9d28..2b3da3e490c 100644 --- a/pkg/metrics/graphite.go +++ b/pkg/metrics/graphite.go @@ -30,9 +30,13 @@ func CreateGraphitePublisher() (*GraphitePublisher, error) { publisher.address = graphiteSection.Key("address").MustString("localhost:2003") safeInstanceName := strings.Replace(setting.InstanceName, ".", "_", -1) - prefix := graphiteSection.Key("prefix").MustString("service.grafana.%instance_name%") + prefix := graphiteSection.Key("prefix").Value() - publisher.prefix = strings.Replace(prefix, "%instance_name%", safeInstanceName, -1) + if prefix == "" { + prefix = "service.grafana.%(instance_name)s" + } + + publisher.prefix = strings.Replace(prefix, "%(instance_name)s", safeInstanceName, -1) return publisher, nil } diff --git a/pkg/metrics/graphite_test.go b/pkg/metrics/graphite_test.go index 764214fcb10..31620bdd161 100644 --- a/pkg/metrics/graphite_test.go +++ b/pkg/metrics/graphite_test.go @@ -10,22 +10,46 @@ import ( func TestGraphitePublisher(t *testing.T) { - Convey("Test graphite prefix", t, func() { - err := setting.NewConfigContext(&setting.CommandLineArgs{ + Convey("Test graphite prefix replacement", t, func() { + var err error + err = setting.NewConfigContext(&setting.CommandLineArgs{ HomePath: "../../", - Args: []string{ - "cfg:metrics.graphite.prefix=service.grafana.%instance_name%", - "cfg:metrics.graphite.address=localhost:2003", - }, }) + + So(err, ShouldBeNil) + + sec, err := setting.Cfg.NewSection("metrics.graphite") + sec.NewKey("prefix", "service.grafana.%(instance_name)s") + sec.NewKey("address", "localhost:2003") + So(err, ShouldBeNil) setting.InstanceName = "hostname.with.dots.com" - publisher, err2 := CreateGraphitePublisher() + publisher, err := CreateGraphitePublisher() - So(err2, ShouldBeNil) + So(err, ShouldBeNil) So(publisher, ShouldNotBeNil) So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com") }) + + 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, ShouldNotBeNil) + + So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com") + So(publisher.address, ShouldEqual, "localhost:2003") + }) } From 41790c67098504c7b8454c5c7c6aa7e06154abad Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 11 Aug 2016 17:00:09 +0200 Subject: [PATCH 08/16] fix(metrics): hide none existing metrics settings --- pkg/metrics/graphite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/metrics/graphite.go b/pkg/metrics/graphite.go index 2b3da3e490c..20b985e22ed 100644 --- a/pkg/metrics/graphite.go +++ b/pkg/metrics/graphite.go @@ -21,7 +21,7 @@ type GraphitePublisher struct { func CreateGraphitePublisher() (*GraphitePublisher, error) { graphiteSection, err := setting.Cfg.GetSection("metrics.graphite") if err != nil { - return nil, err + return nil, nil } publisher := &GraphitePublisher{} From cf6736d480c65df05f6bf4b073fab486d6c61a29 Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 12 Aug 2016 08:06:54 +0200 Subject: [PATCH 09/16] fix(metrics): add ending dot for graphite prefix --- conf/defaults.ini | 2 +- conf/sample.ini | 2 +- pkg/metrics/graphite.go | 2 +- pkg/metrics/graphite_test.go | 9 +++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 2c70d039e6b..8c3fb36dded 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -355,7 +355,7 @@ interval_seconds = 60 # Send internal Grafana metrics to graphite ; [metrics.graphite] ; address = localhost:2003 -; prefix = service.grafana.%(instance_name)s +; prefix = service.grafana.%(instance_name)s. [grafana_net] url = https://grafana.net diff --git a/conf/sample.ini b/conf/sample.ini index ab6c125e848..d82412fa26e 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -305,7 +305,7 @@ enabled = true # Send internal metrics to Graphite ; [metrics.graphite] ; address = localhost:2003 -; prefix = service.grafana.%(instance_name)s +; prefix = service.grafana.%(instance_name)s. #################################### Internal Grafana Metrics ########################## # Url used to to import dashboards directly from Grafana.net diff --git a/pkg/metrics/graphite.go b/pkg/metrics/graphite.go index 20b985e22ed..bbd5696c85d 100644 --- a/pkg/metrics/graphite.go +++ b/pkg/metrics/graphite.go @@ -33,7 +33,7 @@ func CreateGraphitePublisher() (*GraphitePublisher, error) { prefix := graphiteSection.Key("prefix").Value() if prefix == "" { - prefix = "service.grafana.%(instance_name)s" + prefix = "service.grafana.%(instance_name)s." } publisher.prefix = strings.Replace(prefix, "%(instance_name)s", safeInstanceName, -1) diff --git a/pkg/metrics/graphite_test.go b/pkg/metrics/graphite_test.go index 31620bdd161..8ecee9449a5 100644 --- a/pkg/metrics/graphite_test.go +++ b/pkg/metrics/graphite_test.go @@ -19,8 +19,8 @@ func TestGraphitePublisher(t *testing.T) { So(err, ShouldBeNil) sec, err := setting.Cfg.NewSection("metrics.graphite") - sec.NewKey("prefix", "service.grafana.%(instance_name)s") - sec.NewKey("address", "localhost:2003") + sec.NewKey("prefix", "service.grafana.%(instance_name)s.") + sec.NewKey("address", "localhost:2001") So(err, ShouldBeNil) @@ -30,7 +30,8 @@ func TestGraphitePublisher(t *testing.T) { So(err, ShouldBeNil) So(publisher, ShouldNotBeNil) - So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com") + So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.") + So(publisher.address, ShouldEqual, "localhost:2001") }) Convey("Test graphite publisher default values", t, func() { @@ -49,7 +50,7 @@ func TestGraphitePublisher(t *testing.T) { So(err, ShouldBeNil) So(publisher, ShouldNotBeNil) - So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com") + So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.") So(publisher.address, ShouldEqual, "localhost:2003") }) } From f7a9102523a202b9090ff8761d87630b9f0f4b47 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 15 Aug 2016 09:37:24 +0200 Subject: [PATCH 10/16] feat(metrics): improve graphite settings Fixes the broken support for overriding settings with ENV variables. closes #5769 --- conf/defaults.ini | 7 ++++--- conf/sample.ini | 9 +++++---- pkg/metrics/graphite.go | 7 ++++++- pkg/metrics/graphite_test.go | 28 ++++++++++++++++++++++++---- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 8c3fb36dded..5e7f138690c 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -353,9 +353,10 @@ enabled = true interval_seconds = 60 # Send internal Grafana metrics to graphite -; [metrics.graphite] -; address = localhost:2003 -; prefix = service.grafana.%(instance_name)s. +[metrics.graphite] +# Enable by setting the address setting (ex localhost:2003) +address = +prefix = service.grafana.%(instance_name)s. [grafana_net] url = https://grafana.net diff --git a/conf/sample.ini b/conf/sample.ini index d82412fa26e..4ebf2d46fef 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -300,12 +300,13 @@ check_for_updates = true enabled = true # Publish interval -;interval_seconds = 10 +interval_seconds = 10 # Send internal metrics to Graphite -; [metrics.graphite] -; address = localhost:2003 -; prefix = service.grafana.%(instance_name)s. +[metrics.graphite] +# Enable by setting the address setting (ex localhost:2003) +address = +prefix = service.grafana.%(instance_name)s. #################################### Internal Grafana Metrics ########################## # Url used to to import dashboards directly from Grafana.net diff --git a/pkg/metrics/graphite.go b/pkg/metrics/graphite.go index bbd5696c85d..17031ed2931 100644 --- a/pkg/metrics/graphite.go +++ b/pkg/metrics/graphite.go @@ -24,10 +24,15 @@ func CreateGraphitePublisher() (*GraphitePublisher, error) { return nil, nil } + address := graphiteSection.Key("address").String() + if address == "" { + return nil, nil + } + publisher := &GraphitePublisher{} publisher.prevCounts = make(map[string]int64) publisher.protocol = "tcp" - publisher.address = graphiteSection.Key("address").MustString("localhost:2003") + publisher.address = address safeInstanceName := strings.Replace(setting.InstanceName, ".", "_", -1) prefix := graphiteSection.Key("prefix").Value() diff --git a/pkg/metrics/graphite_test.go b/pkg/metrics/graphite_test.go index 8ecee9449a5..320aa3be82b 100644 --- a/pkg/metrics/graphite_test.go +++ b/pkg/metrics/graphite_test.go @@ -34,6 +34,29 @@ func TestGraphitePublisher(t *testing.T) { 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{ @@ -48,9 +71,6 @@ func TestGraphitePublisher(t *testing.T) { publisher, err := CreateGraphitePublisher() So(err, ShouldBeNil) - So(publisher, ShouldNotBeNil) - - So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.") - So(publisher.address, ShouldEqual, "localhost:2003") + So(publisher, ShouldBeNil) }) } From 31952098780e39c50e624180438a2fdd42c832be Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 9 Aug 2016 14:21:01 +0200 Subject: [PATCH 11/16] tech(circle): rearrange build order --- circle.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/circle.yml b/circle.yml index 28c36763d9e..ef11d6b038e 100644 --- a/circle.yml +++ b/circle.yml @@ -18,15 +18,13 @@ dependencies: test: override: - # FMT - test -z "$(gofmt -s -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)" - # GO VET - go vet ./pkg/... - # Go test - - godep go test ./pkg/... - # js tests + # JS tests - npm test - npm run coveralls + # GO tests + - godep go test -v ./pkg/... deployment: master: From 08932b8ebc972658cbec09b0e7e5e8568697d4b4 Mon Sep 17 00:00:00 2001 From: Claudius Zingerli Date: Mon, 15 Aug 2016 17:56:46 +0200 Subject: [PATCH 12/16] InfluxDB data source: Removed 'required' attribute from User/Password (#5820) --- public/app/plugins/datasource/influxdb/partials/config.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/partials/config.html b/public/app/plugins/datasource/influxdb/partials/config.html index 8c09c637906..27b28ba59de 100644 --- a/public/app/plugins/datasource/influxdb/partials/config.html +++ b/public/app/plugins/datasource/influxdb/partials/config.html @@ -14,11 +14,11 @@
User - +
Password - +
From de714e339836c40549870368de7311c8dc5b3b2f Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 16 Aug 2016 15:54:13 +0200 Subject: [PATCH 13/16] tech(docker): add default db for postgres --- docker/blocks/postgres/fig | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/blocks/postgres/fig b/docker/blocks/postgres/fig index c7458cbe400..33499688810 100644 --- a/docker/blocks/postgres/fig +++ b/docker/blocks/postgres/fig @@ -3,5 +3,6 @@ postgrestest: environment: POSTGRES_USER: grafana POSTGRES_PASSWORD: password + POSTGRES_DATABASE: grafana ports: - "5432:5432" From a5f0f508eaf5d25cbcec504883696479a312e9ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 16 Aug 2016 22:31:26 +0200 Subject: [PATCH 14/16] feat(inspector): fixed error handling, showing response body when data proxy returns text/html body --- public/app/core/controllers/inspect_ctrl.js | 8 ++++++-- public/app/core/services/backend_srv.ts | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/public/app/core/controllers/inspect_ctrl.js b/public/app/core/controllers/inspect_ctrl.js index 2adc62f0039..0f8582ef5ce 100644 --- a/public/app/core/controllers/inspect_ctrl.js +++ b/public/app/core/controllers/inspect_ctrl.js @@ -7,7 +7,7 @@ define([ function (angular, _, $, coreModule) { 'use strict'; - coreModule.default.controller('InspectCtrl', function($scope) { + coreModule.default.controller('InspectCtrl', function($scope, $sanitize) { var model = $scope.inspector; function getParametersFromQueryString(queryString) { @@ -32,7 +32,11 @@ function (angular, _, $, coreModule) { if (_.isString(model.error.data)) { $scope.response = $("
" + model.error.data + "
").text(); } else if (model.error.data) { - $scope.response = angular.toJson(model.error.data, true); + if (model.error.data.response) { + $scope.response = $sanitize(model.error.data.response); + } else { + $scope.response = angular.toJson(model.error.data, true); + } } else if (model.error.message) { $scope.message = model.error.message; } diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index 17299f452a3..fdc2b6cb974 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -138,7 +138,8 @@ export class BackendSrv { //populate error obj on Internal Error if (_.isString(err.data) && err.status === 500) { err.data = { - error: err.statusText + error: err.statusText, + response: err.data, }; } From 159ea69e5dab55baa479382002710dc9f16b7092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 17 Aug 2016 09:42:40 +0200 Subject: [PATCH 15/16] fix(OpenTSDB): correct content-type, fixes #4965 --- public/app/plugins/datasource/opentsdb/datasource.js | 5 ----- public/app/plugins/panel/graph/graph.js | 7 +++++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/public/app/plugins/datasource/opentsdb/datasource.js b/public/app/plugins/datasource/opentsdb/datasource.js index dacf4081563..54605a4f7e2 100644 --- a/public/app/plugins/datasource/opentsdb/datasource.js +++ b/public/app/plugins/datasource/opentsdb/datasource.js @@ -129,11 +129,6 @@ function (angular, _, dateMath) { }; this._addCredentialOptions(options); - - // In case the backend is 3rd-party hosted and does not suport OPTIONS, urlencoded requests - // go as POST rather than OPTIONS+POST - options.headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; - return backendSrv.datasourceRequest(options); }; diff --git a/public/app/plugins/panel/graph/graph.js b/public/app/plugins/panel/graph/graph.js index 0a6a2bc0e45..185aaf0d692 100755 --- a/public/app/plugins/panel/graph/graph.js +++ b/public/app/plugins/panel/graph/graph.js @@ -251,11 +251,14 @@ function (angular, $, moment, _, kbn, GraphTooltip) { function callPlot(incrementRenderCounter) { try { $.plot(elem, sortedSeries, options); - delete ctrl.error; - delete ctrl.inspector; + if (ctrl.renderError) { + delete ctrl.error; + delete ctrl.inspector; + } } catch (e) { console.log('flotcharts error', e); ctrl.error = e.message || "Render Error"; + ctrl.renderError = true; ctrl.inspector = {error: ctrl.error}; } From 093563ac37665cef722aeb7032d45f223429a4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 17 Aug 2016 10:01:55 +0200 Subject: [PATCH 16/16] fix(metrics): restored prefix default to prod.grafana.. --- conf/defaults.ini | 4 ++-- conf/sample.ini | 10 +++++----- docs/sources/installation/configuration.md | 2 +- pkg/metrics/graphite_test.go | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 5e7f138690c..896689857ea 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -350,13 +350,13 @@ global_session = -1 # Metrics available at HTTP API Url /api/metrics [metrics] enabled = true -interval_seconds = 60 +interval_seconds = 10 # Send internal Grafana metrics to graphite [metrics.graphite] # Enable by setting the address setting (ex localhost:2003) address = -prefix = service.grafana.%(instance_name)s. +prefix = prod.grafana.%(instance_name)s. [grafana_net] url = https://grafana.net diff --git a/conf/sample.ini b/conf/sample.ini index 4ebf2d46fef..96d2bb92a1c 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -297,18 +297,18 @@ check_for_updates = true # Metrics available at HTTP API Url /api/metrics [metrics] # Disable / Enable internal metrics -enabled = true +;enabled = true # Publish interval -interval_seconds = 10 +;interval_seconds = 10 # Send internal metrics to Graphite [metrics.graphite] # Enable by setting the address setting (ex localhost:2003) -address = -prefix = service.grafana.%(instance_name)s. +;address = +;prefix = prod.grafana.%(instance_name)s. #################################### Internal Grafana Metrics ########################## # Url used to to import dashboards directly from Grafana.net [grafana_net] -url = https://grafana.net +;url = https://grafana.net diff --git a/docs/sources/installation/configuration.md b/docs/sources/installation/configuration.md index 931d123c68b..af3bb796e2d 100644 --- a/docs/sources/installation/configuration.md +++ b/docs/sources/installation/configuration.md @@ -466,7 +466,7 @@ Enable metrics reporting. defaults true. Available via HTTP API `/api/metrics`. ### interval_seconds -Flush/Write interval when sending metrics to external TSDB. Defaults to 60s. +Flush/Write interval when sending metrics to external TSDB. Defaults to 10s. ## [metrics.graphite] Include this section if you want to send internal Grafana metrics to Graphite. diff --git a/pkg/metrics/graphite_test.go b/pkg/metrics/graphite_test.go index 320aa3be82b..2f866ddd7b6 100644 --- a/pkg/metrics/graphite_test.go +++ b/pkg/metrics/graphite_test.go @@ -19,7 +19,7 @@ func TestGraphitePublisher(t *testing.T) { So(err, ShouldBeNil) sec, err := setting.Cfg.NewSection("metrics.graphite") - sec.NewKey("prefix", "service.grafana.%(instance_name)s.") + sec.NewKey("prefix", "prod.grafana.%(instance_name)s.") sec.NewKey("address", "localhost:2001") So(err, ShouldBeNil) @@ -30,7 +30,7 @@ func TestGraphitePublisher(t *testing.T) { So(err, ShouldBeNil) So(publisher, ShouldNotBeNil) - So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.") + So(publisher.prefix, ShouldEqual, "prod.grafana.hostname_with_dots_com.") So(publisher.address, ShouldEqual, "localhost:2001") }) @@ -53,7 +53,7 @@ func TestGraphitePublisher(t *testing.T) { So(err, ShouldBeNil) So(publisher, ShouldNotBeNil) - So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.") + So(publisher.prefix, ShouldEqual, "prod.grafana.hostname_with_dots_com.") So(publisher.address, ShouldEqual, "localhost:2001") })