better slice size management? (#324)

This commit is contained in:
Michael Quigley 2023-05-10 14:59:26 -04:00
parent 43e6c56ec1
commit c193482171
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -39,7 +39,7 @@ func (h *getAccountMetricsHandler) Handle(params metadata.GetAccountMetricsParam
} }
duration = v duration = v
} }
slice := duration / 30 slice := sliceSize(duration)
query := fmt.Sprintf("from(bucket: \"%v\")\n", h.cfg.Bucket) + query := fmt.Sprintf("from(bucket: \"%v\")\n", h.cfg.Bucket) +
fmt.Sprintf("|> range(start: -%v)\n", duration) + fmt.Sprintf("|> range(start: -%v)\n", duration) +
@ -109,7 +109,7 @@ func (h *getEnvironmentMetricsHandler) Handle(params metadata.GetEnvironmentMetr
} }
duration = v duration = v
} }
slice := duration / 30 slice := sliceSize(duration)
query := fmt.Sprintf("from(bucket: \"%v\")\n", h.cfg.Bucket) + query := fmt.Sprintf("from(bucket: \"%v\")\n", h.cfg.Bucket) +
fmt.Sprintf("|> range(start: -%v)\n", duration) + fmt.Sprintf("|> range(start: -%v)\n", duration) +
@ -189,7 +189,7 @@ func (h *getShareMetricsHandler) Handle(params metadata.GetShareMetricsParams, p
} }
duration = v duration = v
} }
slice := duration / 30 slice := sliceSize(duration)
query := fmt.Sprintf("from(bucket: \"%v\")\n", h.cfg.Bucket) + query := fmt.Sprintf("from(bucket: \"%v\")\n", h.cfg.Bucket) +
fmt.Sprintf("|> range(start: -%v)\n", duration) + 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 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
}
}