orchestrator/clickhouse: simplify use of QueryRow()

No need to check for errors, this is also done when invoking Scan().
This commit is contained in:
Vincent Bernat
2024-04-05 22:00:06 +02:00
parent 032d28561c
commit 8d96aa070a
3 changed files with 3 additions and 17 deletions

View File

@@ -84,13 +84,8 @@ func (c *Component) widgetFlowRateHandlerFunc(gc *gin.Context) {
query := `SELECT COUNT(*)/300 AS rate FROM flows WHERE TimeReceived > date_sub(minute, 5, now())`
gc.Header("X-SQL-Query", query)
// Do not increase counter for this one.
row := c.d.ClickHouseDB.Conn.QueryRow(ctx, query)
if err := row.Err(); err != nil {
c.r.Err(err).Msg("unable to query database")
gc.JSON(http.StatusInternalServerError, gin.H{"message": "Unable to query database."})
return
}
var result float64
row := c.d.ClickHouseDB.Conn.QueryRow(ctx, query)
if err := row.Scan(&result); err != nil {
c.r.Err(err).Msg("unable to parse result")
gc.JSON(http.StatusInternalServerError, gin.H{"message": "Unable to parse result."})