Skip to content

Commit f7a9102

Browse files
committed
feat(metrics): improve graphite settings
Fixes the broken support for overriding settings with ENV variables. closes grafana#5769
1 parent cf6736d commit f7a9102

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

conf/defaults.ini

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,10 @@ enabled = true
353353
interval_seconds = 60
354354

355355
# Send internal Grafana metrics to graphite
356-
; [metrics.graphite]
357-
; address = localhost:2003
358-
; prefix = service.grafana.%(instance_name)s.
356+
[metrics.graphite]
357+
# Enable by setting the address setting (ex localhost:2003)
358+
address =
359+
prefix = service.grafana.%(instance_name)s.
359360

360361
[grafana_net]
361362
url = https://grafana.net

conf/sample.ini

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,13 @@ check_for_updates = true
300300
enabled = true
301301

302302
# Publish interval
303-
;interval_seconds = 10
303+
interval_seconds = 10
304304

305305
# Send internal metrics to Graphite
306-
; [metrics.graphite]
307-
; address = localhost:2003
308-
; prefix = service.grafana.%(instance_name)s.
306+
[metrics.graphite]
307+
# Enable by setting the address setting (ex localhost:2003)
308+
address =
309+
prefix = service.grafana.%(instance_name)s.
309310

310311
#################################### Internal Grafana Metrics ##########################
311312
# Url used to to import dashboards directly from Grafana.net

pkg/metrics/graphite.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ func CreateGraphitePublisher() (*GraphitePublisher, error) {
2424
return nil, nil
2525
}
2626

27+
address := graphiteSection.Key("address").String()
28+
if address == "" {
29+
return nil, nil
30+
}
31+
2732
publisher := &GraphitePublisher{}
2833
publisher.prevCounts = make(map[string]int64)
2934
publisher.protocol = "tcp"
30-
publisher.address = graphiteSection.Key("address").MustString("localhost:2003")
35+
publisher.address = address
3136

3237
safeInstanceName := strings.Replace(setting.InstanceName, ".", "_", -1)
3338
prefix := graphiteSection.Key("prefix").Value()

pkg/metrics/graphite_test.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@ func TestGraphitePublisher(t *testing.T) {
3434
So(publisher.address, ShouldEqual, "localhost:2001")
3535
})
3636

37-
Convey("Test graphite publisher default values", t, func() {
37+
Convey("Test graphite publisher default prefix", t, func() {
3838
var err error
3939
err = setting.NewConfigContext(&setting.CommandLineArgs{
4040
HomePath: "../../",
4141
})
4242

4343
So(err, ShouldBeNil)
4444

45-
_, err = setting.Cfg.NewSection("metrics.graphite")
45+
sec, err := setting.Cfg.NewSection("metrics.graphite")
46+
sec.NewKey("address", "localhost:2001")
47+
48+
So(err, ShouldBeNil)
4649

4750
setting.InstanceName = "hostname.with.dots.com"
4851
publisher, err := CreateGraphitePublisher()
@@ -51,6 +54,23 @@ func TestGraphitePublisher(t *testing.T) {
5154
So(publisher, ShouldNotBeNil)
5255

5356
So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.")
54-
So(publisher.address, ShouldEqual, "localhost:2003")
57+
So(publisher.address, ShouldEqual, "localhost:2001")
58+
})
59+
60+
Convey("Test graphite publisher default values", t, func() {
61+
var err error
62+
err = setting.NewConfigContext(&setting.CommandLineArgs{
63+
HomePath: "../../",
64+
})
65+
66+
So(err, ShouldBeNil)
67+
68+
_, err = setting.Cfg.NewSection("metrics.graphite")
69+
70+
setting.InstanceName = "hostname.with.dots.com"
71+
publisher, err := CreateGraphitePublisher()
72+
73+
So(err, ShouldBeNil)
74+
So(publisher, ShouldBeNil)
5575
})
5676
}

0 commit comments

Comments
 (0)