Log geoip stats of proxies by unique IP

Change it so that we log the geoip country code of proxies if they poll
within the current metrics epoch. We make sure we log by unique IP
address
This commit is contained in:
Cecylia Bocovich 2019-06-11 15:43:59 -04:00
parent c782ebdcea
commit 25f059f4c4
2 changed files with 17 additions and 11 deletions

View file

@ -149,6 +149,15 @@ func proxyPolls(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
return
}
log.Println("Received snowflake: ", id)
// Log geoip stats
remoteIP, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
log.Println("Error processing proxy IP: ", err.Error())
} else {
ctx.metrics.UpdateCountryStats(remoteIP)
}
// Wait for a client to avail an offer to the snowflake, or timeout if nil.
offer := ctx.RequestOffer(id)
if nil == offer {
@ -224,15 +233,6 @@ func proxyAnswers(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
return
}
// Get proxy country stats
remoteIP, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
log.Println("Error processing proxy IP: ", err.Error())
} else {
ctx.metrics.UpdateCountryStats(remoteIP)
}
log.Println("Received answer.")
snowflake.answerChannel <- body
}