Finally found in TDengine documentation: https://www.taosdata.com/docs/en/v2.0/taos-sql
Listed the order of select conditional statements.
SELECT select_expr [, select_expr ...]
FROM {tb_name_list}
[WHERE where_condition]
[SESSION(ts_col, tol_val)]
[STATE_WINDOW(col)]
[INTERVAL(interval_val [, interval_offset]) [SLIDING sliding_val]]
[FILL(fill_mod_and_val)]
[GROUP BY col_list]
[ORDER BY col_list { DESC | ASC }]
[SLIMIT limit_val [SOFFSET offset_val]]
[LIMIT limit_val [OFFSET offset_val]]
[>> export_file];
So the Group by should be put after Interval, here is the correct sql:
select avg(value) as gauge from table1 where ts >= now - 30d and ts <= now interval(30d) group by cluster