From c193482171f7d9a0694ea9fe2bc4c415ed92e912 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 10 May 2023 14:59:26 -0400 Subject: [PATCH] better slice size management? (#324) --- controller/metrics.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/controller/metrics.go b/controller/metrics.go index d4582002..0dda77b0 100644 --- a/controller/metrics.go +++ b/controller/metrics.go @@ -39,7 +39,7 @@ func (h *getAccountMetricsHandler) Handle(params metadata.GetAccountMetricsParam } duration = v } - slice := duration / 30 + slice := sliceSize(duration) query := fmt.Sprintf("from(bucket: \"%v\")\n", h.cfg.Bucket) + fmt.Sprintf("|> range(start: -%v)\n", duration) + @@ -109,7 +109,7 @@ func (h *getEnvironmentMetricsHandler) Handle(params metadata.GetEnvironmentMetr } duration = v } - slice := duration / 30 + slice := sliceSize(duration) query := fmt.Sprintf("from(bucket: \"%v\")\n", h.cfg.Bucket) + fmt.Sprintf("|> range(start: -%v)\n", duration) + @@ -189,7 +189,7 @@ func (h *getShareMetricsHandler) Handle(params metadata.GetShareMetricsParams, p } duration = v } - slice := duration / 30 + slice := sliceSize(duration) query := fmt.Sprintf("from(bucket: \"%v\")\n", h.cfg.Bucket) + fmt.Sprintf("|> range(start: -%v)\n", duration) + @@ -239,3 +239,16 @@ func runFluxForRxTxArray(query string, queryApi api.QueryAPI) (rx, tx, timestamp } return rx, tx, timestamps, nil } + +func sliceSize(duration time.Duration) time.Duration { + switch duration { + case 30 * 24 * time.Hour: + return 24 * time.Hour + case 7 * 24 * time.Hour: + return 20 * time.Minute + case 24 * time.Hour: + return 5 * time.Minute + default: + return duration + } +}