Nodegraph throws exception when nodes and edges datasets are empty

how to handle Grafana node graph throwing exception when nodes and edge datasets are empty?

  • What Grafana version and what operating system are you using?
    version 12.2

  • What are you trying to achieve?
    Nodegraph visualization

  • How are you trying to achieve it?
    Querying prometheus metrics using two seperate queries to get two datasets nodes and edges

  • What happened?
    There are instances when my datasets have no data. In such a case the node graph throws exception saying it’s looking for an “id” column.

    I did use a workaround by creating dummy node and edges, so the panel shows “No Connections” instead of throwing exceptions. I just want to know if there’s a better way to handle this.

    Nodes:
    (
    label_replace(
    label_replace(
    vector(0),
    “id”,“no-data”,“”,“”
    ),
    “title”,“No Agents Connected”,“”,“”
    )
    )
    unless
    <my actual query>

    Edges:
    (
    label_replace(
    label_replace(
    label_replace(
    vector(0),
    “id”,“no-edge”,“”,“”
    ),
    “source”,“no-data”,“”,“”
    ),
    “target”,“no-data”,“”,“”
    )
    )
    unless
    <My actual query>

  • What did you expect to happen?
    Show “No Data” when datasets are empty

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

  • Did you follow any online instructions? If so, what is the URL?
    Node graph | Grafana documentation

Try this..

Nodes:

(
label_replace(vector(0), “id”, “no-data”, “”, “”)
|> label_replace(“title”, “No Agents Connected”, “”, “”)
)
unless
(<your_query>)

Edges:

(
label_replace(vector(0), “id”, “no-edge”, “”, “”)
|> label_replace(“source”, “no-data”, “”, “”)
|> label_replace(“target”, “no-data”, “”, “”)
)
unless
(<your_query>)

Thank you, that worked

1 Like