console: fix a possible divide by 0 error

This is not the only problem we have.
This commit is contained in:
Vincent Bernat
2022-07-09 08:06:23 +02:00
parent d70f59c70f
commit f5e2e85d0d
4 changed files with 28 additions and 28 deletions

View File

@@ -189,7 +189,7 @@ func (c *Component) widgetGraphHandlerFunc(gc *gin.Context) {
params.Points = 200
}
interval := int64((24 * time.Hour).Seconds()) / int64(params.Points)
slot := fmt.Sprintf(`(intDiv(%d, {resolution})*{resolution})`, interval)
slot := fmt.Sprintf(`max2(intDiv(%d, {resolution})*{resolution}, 1)`, interval)
now := c.d.Clock.Now()
query := c.queryFlowsTable(fmt.Sprintf(`
SELECT
@@ -202,7 +202,7 @@ GROUP BY Time
ORDER BY Time WITH FILL
FROM toStartOfInterval({timefilter.Start}, INTERVAL %s second)
TO {timefilter.Stop}
STEP %s`, slot, slot, slot, slot), now.Add(-24*time.Hour), now, time.Duration(interval)*time.Second)
STEP toUInt32(%s)`, slot, slot, slot, slot), now.Add(-24*time.Hour), now, time.Duration(interval)*time.Second)
gc.Header("X-SQL-Query", query)
results := []struct {