Grafana面板查询返回0行时出现长转宽序列报错如何解决?
报错性质说明
该报错属于不影响实际使用的良性报错。
触发原因是Grafana 8.1.x版本的饼图面板在处理多查询结果时,当部分查询返回0行空集,后端做长表转宽表的格式转换时,会将缺失的时间维度判定为null值,触发提示。只要存在有效查询返回数据,饼图就能正常渲染,不会影响功能可用性。
报错解决方法
- 方案1:调整单扇区SQL查询逻辑,确保所有查询无匹配数据时也返回数值为0的有效行,而非空集。MySQL示例写法参考:
原查询写法:select count(*) as sector_a from table where org = '${org}' and condition_a
调整后写法:select sum(cnt) as sector_a from ( select count(*) as cnt from table where org = '${org}' and condition_a union all select 0 as cnt ) t - 方案2:将多个独立的扇区查询合并为单条分组查询,避免多空查询场景。示例写法:
select case when condition_a then '扇区A' when condition_b then '扇区B' when condition_c then '扇区C' else '其他' end as sector_name, count(*) as value from table where org = '${org}' group by sector_name - 方案3:将Grafana升级至8.3.0及以上版本,该版本官方已经修复了饼图面板冗余报错提示的问题,空查询场景下不会再弹出该报错。
内容的提问来源于stack exchange,提问作者Classified
相关产品推荐
相关产品推荐

