From 1ed9faa0c22c1ae9ec2043c80e697133688cea40 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Mon, 15 Oct 2018 19:30:10 +0300 Subject: [PATCH] Fix API returning wrong average request time --- coredns_plugin/coredns_stats.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/coredns_plugin/coredns_stats.go b/coredns_plugin/coredns_stats.go index d57ba397..668e6681 100644 --- a/coredns_plugin/coredns_stats.go +++ b/coredns_plugin/coredns_stats.go @@ -242,6 +242,14 @@ func handleStats(w http.ResponseWriter, r *http.Request) { } summed[key] = summedValue } + // don't forget to divide by number of elements in returned slice + if val, ok := summed["avg_processing_time"]; ok { + if flval, flok := val.(float64); flok { + flval /= float64(len(histrical)) + summed["avg_processing_time"] = flval + } + } + summed["stats_period"] = "24 hours" json, err := json.Marshal(summed)