divinity666 / ruby-grafana-reporter

Reporting Service for Grafana
MIT License
66 stars 5 forks source link

grafana_panel_query_value prints undefined method `uid' for nil:NilClass #29

Closed NiklasP36 closed 1 year ago

NiklasP36 commented 1 year ago

Describe the issue Hello, we´re using your ruby grafana reporter and the rendering of the panels in pictures works very good. But we can´t get query data as text from Grafana.

Grafana Version: latest (first test) Grafana Version: 8.5.6 (second test) Grafana Version: 8.3.3 (third test) ruby-grafana-reporter: 0.5.4

Programm Code grafana_panel_query_value:20[query="A"] -> issue

grafana_panel_image::20[width="30%"] -> works

Tests

Logs I, [2022-07-12T08:50:42.012878 #7] INFO -- : 1 report(s) in progress: 75% (running 10 secs) F, [2022-07-12T08:50:43.720076 #7] FATAL -- : undefined method `uid' for nil:NilClass I, [2022-07-12T08:50:47.013342 #7] INFO -- : 1 report(s) in progress: 100% (running 15 secs) I, [2022-07-12T08:50:47.057724 #7] INFO -- : Report creation ended after 15 seconds with status 'finished'

Thank you for this great tool, i hope there is a quick fix for this problem :)

ttm92 commented 1 year ago

Hello ,

Same issue with Grafana Version : v8.3.6 ruby-grafana-reporter: 0.5.4

Logs : F, [2022-07-15T14:13:58.534954 #8] FATAL -- : undefined method `uid' for nil:NilClass

divinity666 commented 1 year ago

Looks like you forgot the configuration of the dashboard you would like to read from.

Try like this:

grafana_panel_query_value:20[query="A",dashboard="<<your_dashboard_uid>>"]

or configure your dashboard at the beginning of your template using this:

:grafana_default_dashboard: <your_dashboard_uid>

NiklasP36 commented 1 year ago

Hi thanks for your answer, I use this code at the beginning of the report. :grafana_default_dashboard:

And this programm code works: grafana_panel_image::20[width="30%"]

But not this: grafana_panel_query_value:20[query="A"]

I have also testet this code: grafana_panel_query_value:20[query="A",dashboard=""]

and got this error message: undefined method `uid' for nil:NilClass datasource = @datasources.select { |_name, ds| ds.uid == datasource_uid }.values.first ^^^^

emanzx commented 1 year ago

I think this is the same problem as me

divinity666 commented 1 year ago

Ok, the error message gave me a hint.

Could you please run the reporter with -d DEBUG and provide the logs? I guess we could come across some unsupported datasource issue, which might not be handled properly.

Would be great to see the logs.

NiklasP36 commented 1 year ago

Hi, here is the Debug log:

I, [2022-07-27T09:13:02.769498 #7]  INFO -- : Server listening on port 8815...
D, [2022-07-27T09:13:45.366545 #7] DEBUG -- : Received request: GET /render?var-template=demo_report&from-date=2022-07-26&to-date=2022-07-27&from=now-24h&to=now HTTP/1.1
D, [2022-07-27T09:13:45.366812 #7] DEBUG -- : query_parameters: {"var-template"=>["demo_report"], "from-date"=>["2022-07-26"], "to-date"=>["2022-07-27"], "from"=>["now-24h"], "to"=>["now"]}
I, [2022-07-27T09:13:45.368513 #7]  INFO -- : 1 report(s) in progress: 0% (running 0 secs)
I, [2022-07-27T09:13:45.368790 #7]  INFO -- : Report started at 2022-07-27 09:13:45 +0000
I, [2022-07-27T09:13:45.368930 #7]  INFO -- : You are running ruby-grafana-reporter version 0.5.4.
D, [2022-07-27T09:13:45.393890 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:45.394131 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
D, [2022-07-27T09:13:45.538495 #7] DEBUG -- : Document attributes: {"convert-backend"=>"pdf", "imagesdir"=>"./images", "pdf-theme"=>"custom-theme.yml", "pdf-themesdir"=>"./templates/theme", "pdf-fontsdir"=>"./templates/fonts", "var-template"=>"demo_report", "from-date"=>"2022-07-26", "to-date"=>"2022-07-27", "from"=>"now-24h", "to"=>"now"}
D, [2022-07-27T09:13:45.538882 #7] DEBUG -- : Template ./templates/demo_report.adoc contains 4 calls of grafana reporter functions.
D, [2022-07-27T09:13:45.541353 #7] DEBUG -- : Processing PanelImageBlockMacro (instance: default, dashboard: <my_dashboard_uid>, panel: 18)
D, [2022-07-27T09:13:45.541699 #7] DEBUG -- : Requesting http://grafana-p36:3000/api/frontend/settings with '' and timeout '60'
D, [2022-07-27T09:13:45.562299 #7] DEBUG -- : Received response #<Net::HTTPOK:0x00007f182ba32d58>
D, [2022-07-27T09:13:45.563329 #7] DEBUG -- : Requesting http://grafana-p36:3000/api/dashboards/uid/<my_dashboard_uid> with '' and timeout '60'
D, [2022-07-27T09:13:45.591158 #7] DEBUG -- : Received response #<Net::HTTPOK:0x00007f182b91d2d8>
D, [2022-07-27T09:13:45.593137 #7] DEBUG -- : Requesting http://grafana-p36:3000/render/d-solo/<my_dashboard_uid>?panelId=18&fullscreen=true&theme=light&timeout=60&var-template=demo_report&from=1658826825000&to=1658913224000 with '' and timeout '60'
D, [2022-07-27T09:13:49.033456 #7] DEBUG -- : Received response #<Net::HTTPOK:0x00007f182bb9e2f0>
W, [2022-07-27T09:13:49.044019 #7]  WARN -- : the literal theme category is deprecated; use the codespan category instead
W, [2022-07-27T09:13:49.044664 #7]  WARN -- : the outline-list theme category is deprecated; use the list category instead
D, [2022-07-27T09:13:49.076292 #7] DEBUG -- : Processing PanelImageInlineMacro (instance: default, dashboard: <my_dashboard_uid>, panel: 20)
D, [2022-07-27T09:13:49.077136 #7] DEBUG -- : Requesting http://grafana-p36:3000/render/d-solo/<my_dashboard_uid>?panelId=20&fullscreen=true&theme=light&timeout=60&var-template=demo_report&from=1658826825000&to=1658913224000 with '' and timeout '60'
D, [2022-07-27T09:13:49.132003 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:49.132239 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
D, [2022-07-27T09:13:49.915963 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:49.916199 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
I, [2022-07-27T09:13:50.368855 #7]  INFO -- : 1 report(s) in progress: 50% (running 5 secs)
D, [2022-07-27T09:13:50.436466 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:50.436701 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
D, [2022-07-27T09:13:51.072971 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:51.073209 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
D, [2022-07-27T09:13:51.755166 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:51.755402 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
D, [2022-07-27T09:13:52.344050 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:52.344291 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
D, [2022-07-27T09:13:52.552667 #7] DEBUG -- : Received response #<Net::HTTPOK:0x00007f182d1c7b30>
D, [2022-07-27T09:13:52.760449 #7] DEBUG -- : Processing PanelImageInlineMacro (instance: default, dashboard: <my_dashboard_uid>, panel: 36)
D, [2022-07-27T09:13:52.761305 #7] DEBUG -- : Requesting http://grafana-p36:3000/render/d-solo/<my_dashboard_uid>?panelId=36&fullscreen=true&theme=light&timeout=60&var-template=demo_report&from=1658826825000&to=1658913224000 with '' and timeout '60'
D, [2022-07-27T09:13:52.860510 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:52.860738 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
D, [2022-07-27T09:13:53.702537 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:53.702775 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
D, [2022-07-27T09:13:54.163460 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:54.163698 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
D, [2022-07-27T09:13:54.678428 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:54.678679 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
I, [2022-07-27T09:13:55.369526 #7]  INFO -- : 1 report(s) in progress: 75% (running 10 secs)
D, [2022-07-27T09:13:55.460297 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:55.460555 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
D, [2022-07-27T09:13:56.201387 #7] DEBUG -- : Received response #<Net::HTTPOK:0x00007f182b6d1f38>
D, [2022-07-27T09:13:56.326955 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:56.327177 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
D, [2022-07-27T09:13:56.572160 #7] DEBUG -- : Processing PanelQueryValueInlineMacro (instance: default, dashboard: <my_dashboard_uid>, panel: 20, query: A)
D, [2022-07-27T09:13:56.572572 #7] DEBUG -- : Requesting http://grafana-p36:3000/api/dashboards/uid/<my_dashboard_uid>  with '' and timeout '60'
D, [2022-07-27T09:13:56.591909 #7] DEBUG -- : Received response #<Net::HTTPOK:0x00007f182ab08d28>
F, [2022-07-27T09:13:56.608989 #7] FATAL -- : undefined method `uid' for nil:NilClass

      datasource = @datasources.select { |_name, ds| ds.uid == datasource_uid }.values.first
                                                       ^^^^
D, [2022-07-27T09:13:56.748251 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:56.748497 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
D, [2022-07-27T09:13:57.454417 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:57.454645 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
I, [2022-07-27T09:13:58.121711 #7]  INFO -- : Report creation ended after 13 seconds with status 'finished'
D, [2022-07-27T09:13:58.222528 #7] DEBUG -- : Received request: GET /view_report?report_id=1000 HTTP/1.1
D, [2022-07-27T09:13:58.222766 #7] DEBUG -- : query_parameters: {"report_id"=>["1000"]}
D, [2022-07-27T09:13:58.222932 #7] DEBUG -- : Returning PDF report at ./reports/gf_pdf_20220727-7-o9x6ri
divinity666 commented 1 year ago

Unfortunately this does not show me the root cause. (I will add some extended log entries in the next release).

Anyway the issue is most likely related to you datasources configuration. If you are willing to share, you might provide the output of http://grafana-p36:3000/api/frontend/settings. Essentially the part datasources will be sufficient to get a deeper understanding.

Somehow there seems to be a configuration, which is not properly handled by the reporter.

divinity666 commented 1 year ago

Please try again with the just released version and provide log with -d DEBUG enabled, which should contain additional information.

NiklasP36 commented 1 year ago

Hi thanks for the update :)

I test if everything works and reply tomorrow.

NiklasP36 commented 1 year ago

hi, it seems to work right now.

I get the values from the query.

Thank you very much :)

divinity666 commented 1 year ago

Thanks for your feedback. Closing the case.