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",