jdbranham / grafana-diagram

A Grafana plugin to visualize metrics in a diagram using flow charts, gantt charts, sequence diagrams, or class diagrams
https://jdbranham.github.io/grafana-diagram/
Apache License 2.0
451 stars 86 forks source link

Grafana templating feature & grafana-diagram #28

Open teo96 opened 7 years ago

teo96 commented 7 years ago

Hi & congrats for the work done, love your plugin

I try to user grafana-diagram with the templating feature of Grafana

In my dashboard I have variable named 'servers'. I use this variable in others panels using $servers I created the diagram panel with the "Repeat Panel" option filled with $servers But it seems $servers is not recognize as a variable.

Is the templating feature supported and so how to use it ? If not do you plan to add it ?

jdbranham commented 7 years ago

Thanks @teo96 I haven't worked with the templating functionality yet, but variable replacement for the metric queries /targets should work.

Do you get any JavaScript errors in the browser console?

teo96 commented 7 years ago

No error, just a warn "couldnt find a diagram node with id/text : server1 Data are received, legend displays correct values

Diagram graph LR $servers[$servers]

Metric aliasByNode(sumSeries($servers.cpu., *), 0)

Full JS log

diagramControl.js:138 received data
diagramControl.js:139 [Object]
diagramControl.js:141 mapped dataList to series
diagramControl.js:142 [a]
diagramControl.js:221 setting values for series
diagramControl.js:222 a {datapoints: Array[2160], label: "server1", id: "server1", alias: "server1", color: undefined…}
diagramControl.js:272 applying overrides for seriesItem
diagramControl.js:273 server1
diagramControl.js:274 []
diagramControl.js:276 comparing:
diagramControl.js:277 undefined
diagramControl.js:254 Getting gradient for value
diagramControl.js:255 Object {thresholds: Array[2], colorMap: Array[3]}
diagramControl.js:256 198.22940598379597
diagramControl.js:394 updating svg style
diagramControl.js:409 finding targetElement
diagramControl.js:420 finding element that contains text node: server1
diagramControl.js:433 couldnt not find a diagram node with id/text: server1
jdbranham commented 7 years ago

Thanks @teo96 I see how we can resolve this. I think there is a variable replacement method available in the core. I'll add this to the next release.

teo96 commented 7 years ago

Hi @jdbranham

I deployed and tested your patch but can't make it works

Error during the graph parsing when i select only 1 value in my variable

Parse error on line 2: graph LR {myserver1}[{myserv ---------^ Expecting 'SEMI', 'NEWLINE', 'SPACE', 'EOF', 'DIR', 'DOWN', 'subgraph', 'MINUS', 'STYLE', 'LINKSTYLE', 'CLASSDEF', 'CLASS', 'CLICK', 'NUM', 'COMMA', 'ALPHA', 'COLON', 'BRKT', 'DOT', 'PUNCTUATION', 'UNICODE_TEXT', 'PLUS', 'EQUALS', 'MULT', got 'DIAMOND_START'

If i select 2/All values :

Parse error on line 2: graph LR {myserve1,myserver ---------^ Expecting 'SEMI', 'NEWLI ...

jdbranham commented 7 years ago

Does your variable value contain the braces? Or do they get inserted when the graph is rendering? Can you show me an example of your diagram definition, query, and template variables?

teo96 commented 7 years ago

No braces are added by grafana everytime variables are used

Diagram graph LR $servers[$servers]

Metric aliasByNode(sumSeries($servers.cpu., *), 0)

Variable Same as this one on play.grafana.org http://play.grafana.org/dashboard/db/graphite-templated-nested?editview=templating

jdbranham commented 6 years ago

Confirmed the problem is only for multi-valued variables. The latest version handles single valued vars correctly

jdbranham commented 3 years ago

Multi-value variable expansion is not compatible, because it creates invalid Mermaid syntax.
One way to resolve this, and create enhanced definitions, is to introduce an abstraction between the Mermaid syntax and the diagram definition.
This could be powerful, as we could introduce more dynamic functionality in the diagram, but would also add complexity.