From 18e49155207ba7f1d3b2cca6324881f24af842aa Mon Sep 17 00:00:00 2001 From: Marcel Gaedigk Date: Fri, 5 Aug 2016 15:47:59 +0200 Subject: [PATCH] Fixes a panic with wrong values in e2elatency --- collector/stats.go | 7 +++++++ collector/stats_channel.go | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/collector/stats.go b/collector/stats.go index ce37235..53dfab2 100644 --- a/collector/stats.go +++ b/collector/stats.go @@ -48,6 +48,13 @@ type e2elatency struct { Percentiles []map[string]float64 `json:"percentiles"` } +func (e *e2elatency) percentileValue(idx int) float64 { + if idx >= len(e.Percentiles) { + return 0 + } + return e.Percentiles[idx]["value"] +} + type client struct { ID string `json:"client_id"` Hostname string `json:"hostname"` diff --git a/collector/stats_channel.go b/collector/stats_channel.go index 77efb0b..98abc68 100644 --- a/collector/stats_channel.go +++ b/collector/stats_channel.go @@ -59,7 +59,7 @@ func ChannelStats(namespace string) StatsCollector { }, labels), }, { - val: func(c *channel) float64 { return c.E2eLatency.Percentiles[0]["value"] }, + val: func(c *channel) float64 { return c.E2eLatency.percentileValue(0) }, vec: prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: namespace, Name: "e2e_latency_99p", @@ -67,7 +67,7 @@ func ChannelStats(namespace string) StatsCollector { }, labels), }, { - val: func(c *channel) float64 { return c.E2eLatency.Percentiles[1]["value"] }, + val: func(c *channel) float64 { return c.E2eLatency.percentileValue(1) }, vec: prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: namespace, Name: "e2e_latency_95p",