Export metrics in setup; so it also works after reload (#1715)

* brr; a sleep

* Shouldnt need a query
This commit is contained in:
Miek Gieben 2018-04-21 18:59:35 +01:00 committed by GitHub
parent acbcad7b4e
commit a466bb6fc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 12 deletions

View file

@ -5,10 +5,8 @@ import (
"net" "net"
"net/http" "net/http"
"os" "os"
"runtime"
"sync" "sync"
"github.com/coredns/coredns/coremain"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics/vars" "github.com/coredns/coredns/plugin/metrics/vars"
"github.com/coredns/coredns/plugin/pkg/log" "github.com/coredns/coredns/plugin/pkg/log"
@ -52,9 +50,6 @@ func New(addr string) *Metrics {
met.MustRegister(vars.ResponseSize) met.MustRegister(vars.ResponseSize)
met.MustRegister(vars.ResponseRcode) met.MustRegister(vars.ResponseRcode)
// Initialize metrics.
buildInfo.WithLabelValues(coremain.CoreVersion, coremain.GitCommit, runtime.Version()).Set(1)
return met return met
} }

View file

@ -2,8 +2,10 @@ package metrics
import ( import (
"net" "net"
"runtime"
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/coremain"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/mholt/caddy" "github.com/mholt/caddy"
@ -39,6 +41,9 @@ func setup(c *caddy.Controller) error {
c.OnRestart(m.OnRestart) c.OnRestart(m.OnRestart)
c.OnFinalShutdown(m.OnFinalShutdown) c.OnFinalShutdown(m.OnFinalShutdown)
// Initialize metrics.
buildInfo.WithLabelValues(coremain.CoreVersion, coremain.GitCommit, runtime.Version()).Set(1)
return nil return nil
} }

View file

@ -5,6 +5,7 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"testing" "testing"
"time"
"github.com/miekg/dns" "github.com/miekg/dns"
) )
@ -93,13 +94,7 @@ func TestReloadMetricsHealth(t *testing.T) {
} }
defer c1.Stop() defer c1.Stop()
// Send query to trigger monitoring to export on the new process time.Sleep(1 * time.Second)
udp, _ := CoreDNSServerPorts(c1, 0)
m := new(dns.Msg)
m.SetQuestion("example.org.", dns.TypeA)
if _, err := dns.Exchange(m, udp); err != nil {
t.Fatal(err)
}
// Health // Health
resp, err := http.Get("http://localhost:53184/health") resp, err := http.Get("http://localhost:53184/health")