mirror of
				https://github.com/grafana/grafana.git
				synced 2025-02-25 18:55:37 -06:00 
			
		
		
		
	feat(metrics): improve graphite settings
Fixes the broken support for overriding settings with ENV variables. closes #5769
This commit is contained in:
		@@ -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()
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user