divinity666 / ruby-grafana-reporter

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

grafana_panel_query_table: undefined method `each' for nil:NilClass stmt.each do #42

Closed ilmarietto123 closed 4 months ago

ilmarietto123 commented 1 year ago

Describe the issue Hi and thanks for your great work! I have this error trying to get tables:

ERROR -- : GrafanaReporterError: The datasource request to 'InfluxDB' (Grafana::InfluxDbDatasource) failed with an internal error: undefined method `each' for nil:NilClass
      stmt.each do |value|
          ^^^^^

I can get images, titles and descriptions from panels, but not tables. Attached log and pdf. If you need other info, I'm available.

Json of panel:

{
  "datasource": {
    "type": "influxdb",
    "uid": "0_MsV2Y4k"
  },
  "description": "",
  "fieldConfig": {
    "defaults": {
      "custom": {
        "align": "left",
        "cellOptions": {
          "type": "auto"
        },
        "inspect": false
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "purple",
            "value": null
          }
        ]
      },
      "color": {
        "mode": "fixed"
      },
      "displayName": "Produzione giornaliera",
      "unit": "kwatth"
    },
    "overrides": [
      {
        "matcher": {
          "id": "byName",
          "options": "Time"
        },
        "properties": [
          {
            "id": "unit",
            "value": "time:DD-MM-YYYY"
          }
        ]
      }
    ]
  },
  "gridPos": {
    "h": 33,
    "w": 24,
    "x": 0,
    "y": 36
  },
  "id": 13,
  "options": {
    "showHeader": false,
    "footer": {
      "show": true,
      "reducer": [
        "sum"
      ],
      "countRows": false,
      "fields": "",
      "enablePagination": false
    },
    "sortBy": []
  },
  "pluginVersion": "9.4.7",
  "targets": [
    {
      "datasource": {
        "type": "influxdb",
        "uid": "0_MsV2Y4k"
      },
      "query": "import \"timezone\" \r\noption location=timezone.location(name: \"Europe/Rome\")\r\n\r\nfrom(bucket: \"Fotovoltaico_1h\")\r\n  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n  |> filter(fn: (r) => r[\"_measurement\"] == \"fotovoltaico\")\r\n  |> filter(fn: (r) => r[\"_field\"] == \"W_Tot\")\r\n  |> filter(fn: (r) => r[\"aggregate\"] == \"mean\")\r\n  |> aggregateWindow(every: 24h, fn: sum, createEmpty: false)\r\n  |> timeShift(duration:-1s)\r\n  |> yield(name: \"sum\")",
      "refId": "A"
    }
  ],
  "title": "Fotovoltaico - Produzione giornaliera",
  "type": "table"
}

Application call

Template file (if applicable)

|=== include::grafana_panel_query_table:13[dashboard="UZFkI2L4z",verbose_log="true",query="A"] |===


**Configuration file**
 - created with configuration wizard version: yes, wizard
 - relevant part of configuration file (remember to X-out personal information as e.g. api_key):

This configuration has been built with the configuration wizard.

grafana: default: host: http://172.29.0.9:3000 api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

grafana-reporter:

Specifies how often the reporter shall check for newer versions [number of days].

You may set check-for-updates to 0 to disable

check-for-updates: 1 report-class: GrafanaReporter::Asciidoctor::Report templates-folder: ./templates reports-folder: ./reports report-retention: 720 webservice-port: 8815

you may want to configure the following webhook callbacks to get informed on certain events

callbacks:

all:

- <>

- ...

on_before_create:

- <>

- ...

on_after_cancel:

- <>

- ...

on_after_finish:

- <>

- ...

default-document-attributes: imagesdir: ./images

feel free to add here additional asciidoctor document attributes which are applied to all your templates



**Environment (please complete the following information):**
 - OS [Alpine]: 
 - Grafana version: 9.4.7 (docker)
 - Environment: docker
 - Ruby Version, if source or gem environment [e.g. 2.3.7]: 3.1.4p223 (asciidoctor/docker-asciidoctor)
 - Reporter version [0.6.3]: 

[ruby grafana reporter error.log](https://github.com/divinity666/ruby-grafana-reporter/files/11415753/ruby.grafana.reporter.error.log)
[document.pdf](https://github.com/divinity666/ruby-grafana-reporter/files/11415789/document.pdf)
divinity666 commented 1 year ago

Thanks for using the reporter and the very detailed error report!

It looks like I could find the error by looking in your input data. Is it possible for you to modify the reporter rb file, so that we can test the change immediately?

If so, please check line ~989, which should look like this: return panel_query_target['query'] if panel_query_target['rawQuery']

Please change it to: return panel_query_target['query'] if panel_query_target['query']

and test again.

Let me know the results. If that is working fine, I will soon provide a fixed version.

Thanks for your support!

ilmarietto123 commented 1 year ago

Hi Divinity666, I changed the line in .rb file, restarted asciidoctor container and requested the same test report. Now I got this:

D, [2023-05-11T10:41:08.483624 #7] DEBUG -- : HTTP response body: Authentication to data source failed

E, [2023-05-11T10:41:08.483890 #7] ERROR -- : GrafanaError: The datasource request returned with an unsupported response format (received: Authentication to data source failed). (Grafana::UnsupportedQueryResponseReceivedError)

Attached log and report files. Waiting for further instructions, thanks! document 20230511 1045.pdf ruby grafana error log 20230511 1045.log

divinity666 commented 1 year ago

Obviously you are using InfluxDB with authentication configured, right? Today, I did not test it with authenticaiton, which seems to be the root cause...

Could you test if it works without authentication, just to see, if this works as expected then? If I find some time, I can have a look at the authentication.

ilmarietto123 commented 1 year ago

Ok, I looked but I didn't manage how to disable authentication. Can you give me a hint? Should I work on a copy of influx container? I can't stop or mess the recording of 3 energy meters through Telegraf.

ilmarietto123 commented 1 year ago

Hi Divinity, I duplicated the influx container and added the new data source to grafana so I have some data to mess with. I spent some time trying to disable the influx authentication but no luck. I found this, if I understand correctly, it is no more possible to disable it in influx 2.7: https://docs.influxdata.com/influxdb/v2.7/reference/faq/#can-i-use-influxdb-with-authentication-disabled Anyway, if you have some time and you need some test, just ask. Thanks.

divinity666 commented 1 year ago

Ok, understood. I will have to add support for InfluxDB authenticaton then with a next release.

Please be patient.

divinity666 commented 4 months ago

New Grafana proxy interface is now supported for InfluxDB in latest release.