From 331dbe34d7f0c4a424226052bd2baa115052bfdc Mon Sep 17 00:00:00 2001 From: Leo Balduf Date: Thu, 8 Sep 2016 11:40:30 -0400 Subject: [PATCH] http: add scrape address length to context --- frontend/http/frontend.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/http/frontend.go b/frontend/http/frontend.go index 6f976cf..2760c00 100644 --- a/frontend/http/frontend.go +++ b/frontend/http/frontend.go @@ -8,11 +8,13 @@ import ( "net/http" "time" + log "github.com/Sirupsen/logrus" "github.com/julienschmidt/httprouter" "github.com/prometheus/client_golang/prometheus" "github.com/tylerb/graceful" "github.com/chihaya/chihaya/frontend" + "github.com/chihaya/chihaya/middleware" ) func init() { @@ -163,7 +165,17 @@ func (t *Frontend) scrapeRoute(w http.ResponseWriter, r *http.Request, _ httprou return } - resp, err := t.logic.HandleScrape(context.Background(), req) + host, _, err := net.SplitHostPort(r.RemoteAddr) + if err != nil { + log.Errorln("http: unable to determine remote address for scrape:", err) + WriteError(w, err) + return + } + + ip := net.ParseIP(host) + ctx := context.WithValue(context.Background(), middleware.ScrapeIsIPv6Key, len(ip) == net.IPv6len) + + resp, err := t.logic.HandleScrape(ctx, req) if err != nil { WriteError(w, err) return