aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugin/metrics/metrics.go5
-rw-r--r--plugin/metrics/metrics_test.go2
-rw-r--r--plugin/metrics/setup.go11
3 files changed, 10 insertions, 8 deletions
diff --git a/plugin/metrics/metrics.go b/plugin/metrics/metrics.go
index 0dabcdf96..df07da0ae 100644
--- a/plugin/metrics/metrics.go
+++ b/plugin/metrics/metrics.go
@@ -36,6 +36,11 @@ type Metrics struct {
zoneMu sync.RWMutex
}
+// New returns a new instance of Metrics with the given address
+func New(addr string) *Metrics {
+ return &Metrics{Addr: addr, zoneMap: make(map[string]bool)}
+}
+
// AddZone adds zone z to m.
func (m *Metrics) AddZone(z string) {
m.zoneMu.Lock()
diff --git a/plugin/metrics/metrics_test.go b/plugin/metrics/metrics_test.go
index 54e7859e8..f3e4ba3d8 100644
--- a/plugin/metrics/metrics_test.go
+++ b/plugin/metrics/metrics_test.go
@@ -13,7 +13,7 @@ import (
)
func TestMetrics(t *testing.T) {
- met := &Metrics{Addr: "localhost:0", zoneMap: make(map[string]bool)}
+ met := New("localhost:0")
if err := met.OnStartup(); err != nil {
t.Fatalf("Failed to start metrics handler: %s", err)
}
diff --git a/plugin/metrics/setup.go b/plugin/metrics/setup.go
index eecfac62c..a0f68a53f 100644
--- a/plugin/metrics/setup.go
+++ b/plugin/metrics/setup.go
@@ -42,10 +42,7 @@ func setup(c *caddy.Controller) error {
}
func prometheusParse(c *caddy.Controller) (*Metrics, error) {
- var (
- met = &Metrics{Addr: addr, zoneMap: make(map[string]bool)}
- err error
- )
+ var met = New(defaultAddr)
defer func() {
uniqAddr.SetAddress(met.Addr)
@@ -73,7 +70,7 @@ func prometheusParse(c *caddy.Controller) (*Metrics, error) {
return met, c.ArgErr()
}
}
- return met, err
+ return met, nil
}
var uniqAddr addrs
@@ -91,8 +88,8 @@ func (a *addrs) SetAddress(addr string) {
a.a[addr] = todo
}
-// Addr is the address the where the metrics are exported by default.
-const addr = "localhost:9153"
+// defaultAddr is the address the where the metrics are exported by default.
+const defaultAddr = "localhost:9153"
const (
todo = 1