divinity666 / ruby-grafana-reporter

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

grafana_panel_query_table error when datasource is variables #23

Closed myselfghost closed 1 year ago

myselfghost commented 2 years ago

Environment (please complete the following information):

panel JSON:

{
  "id": 2,
  "gridPos": {
    "h": 19,
    "w": 24,
    "x": 0,
    "y": 0
  },
  "type": "table",
  "title": "Host Reporter",
  "transformations": [
    {
      "id": "seriesToColumns",
      "options": {
        "byField": "instance"
      }
    },
    {
      "id": "organize",
      "options": {
        "excludeByName": {
          "Devops 1": true,
          "Devops 2": true,
          "InstanceId": true,
          "InstanceId 2": true,
          "InstanceName": true,
          "InstanceName 2": true,
          "OsType": true,
          "OsType 2": true,
          "Time": true,
          "Time 2": true,
          "Time 3": true,
          "Time 4": true,
          "alertsource": true,
          "alertsource 2": true,
          "environment": true,
          "environment 2": true,
          "environment 3": true,
          "environment 4": true,
          "idc 1": true,
          "idc 2": true,
          "idc 3": true,
          "idc 4": true,
          "important": true,
          "important 2": true,
          "instanceid": true,
          "instanceid 2": true,
          "instancename 2": true,
          "instancename 3": true,
          "instancename 4": true,
          "job": true,
          "job 2": true,
          "monitor_group": true,
          "monitor_group 2": true,
          "no_disk_warn 1": true,
          "no_disk_warn 2": true,
          "no_mem_warn 1": true,
          "no_mem_warn 2": true,
          "ostype": true,
          "ostype 2": true,
          "system 2": true,
          "system 3": true,
          "system 4": true
        },
        "indexByName": {
          "InstanceId": 1,
          "InstanceName": 2,
          "OsType": 3,
          "Time": 0,
          "Value": 13,
          "alertsource": 4,
          "environment": 6,
          "idc": 7,
          "instance": 5,
          "instanceid": 8,
          "instancename": 9,
          "job": 10,
          "ostype": 11,
          "system": 12
        },
        "renameByName": {
          "Value": "mem_max",
          "Value #A": "mem_max(%)",
          "Value #B": "mem_avg(%)",
          "Value #C": "cpu_max(%)",
          "Value #D": "cpu_avg(%)",
          "instance": "IP"
        }
      }
    }
  ],
  "datasource": {
    "type": "prometheus",
    "uid": "${DS_PROMETHEUS}"
  },
  "pluginVersion": "8.3.5",
  "libraryPanel": {
    "description": "",
    "meta": {
      "connectedDashboards": 1,
      "created": "2022-02-15T09:53:07+08:00",
      "createdBy": {
        "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56",
        "id": 1,
        "name": "admin"
      },
      "folderName": "General",
      "folderUid": "",
      "updated": "2022-03-01T17:22:03+08:00",
      "updatedBy": {
        "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56",
        "id": 1,
        "name": "admin"
      }
    },
    "name": "Host Reporter",
    "type": "table",
    "uid": "okebvgBnz",
    "version": 14
  },
  "description": "",
  "fieldConfig": {
    "defaults": {
      "custom": {
        "align": "center",
        "displayMode": "auto"
      },
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          }
        ]
      },
      "mappings": [],
      "color": {
        "mode": "thresholds"
      },
      "max": 100,
      "min": 0
    },
    "overrides": [
      {
        "matcher": {
          "id": "byName",
          "options": "mem_avg(%)"
        },
        "properties": [
          {
            "id": "thresholds",
            "value": {
              "mode": "percentage",
              "steps": [
                {
                  "color": "green",
                  "value": null
                },
                {
                  "color": "yellow",
                  "value": 80
                }
              ]
            }
          },
          {
            "id": "custom.displayMode",
            "value": "color-background"
          }
        ]
      },
      {
        "matcher": {
          "id": "byName",
          "options": "cpu_avg(%)"
        },
        "properties": [
          {
            "id": "thresholds",
            "value": {
              "mode": "percentage",
              "steps": [
                {
                  "color": "green",
                  "value": null
                },
                {
                  "color": "red",
                  "value": 80
                }
              ]
            }
          },
          {
            "id": "custom.displayMode",
            "value": "color-background"
          }
        ]
      }
    ]
  },
  "options": {
    "showHeader": true,
    "footer": {
      "show": false,
      "reducer": [
        "sum"
      ],
      "fields": ""
    }
  },
  "targets": [
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_PROMETHEUS}"
      },
      "exemplar": false,
      "expr": "100- 100* min_over_time(node_memory_MemAvailable_bytes{idc=\"$idc\",system=~\"$system\"} [30d:5m]) /node_memory_MemTotal_bytes{idc=\"$idc\",system=~\"$system\"}",
      "format": "table",
      "instant": true,
      "interval": "",
      "legendFormat": "",
      "refId": "A"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_PROMETHEUS}"
      },
      "exemplar": false,
      "expr": "100- 100* avg_over_time(node_memory_MemAvailable_bytes{idc=\"$idc\",system=~\"$system\"} [30d:10m]) /node_memory_MemTotal_bytes{idc=\"$idc\",system=~\"$system\"}",
      "format": "table",
      "hide": false,
      "instant": true,
      "interval": "",
      "legendFormat": "",
      "refId": "B"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_PROMETHEUS}"
      },
      "exemplar": false,
      "expr": "100 - min_over_time(avg by(instance,system,idc,environment,instancename) (rate(node_cpu_seconds_total{mode=\"idle\",idc=\"$idc\",system=~\"$system\"}[2m]))[30d:5m]) * 100",
      "format": "table",
      "hide": false,
      "instant": true,
      "interval": "",
      "legendFormat": "",
      "refId": "C"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_PROMETHEUS}"
      },
      "exemplar": false,
      "expr": "100 - avg_over_time(avg by(instance,system,idc,environment,instancename) (rate(node_cpu_seconds_total{mode=\"idle\",idc=\"$idc\",system=~\"$system\"}[2m]))[30d:5m]) * 100",
      "format": "table",
      "hide": false,
      "instant": true,
      "interval": "",
      "legendFormat": "",
      "refId": "D"
    }
  ]
}

tpl:

include::grafana_panel_query_table:2[query="A",dashboard="dH2etRfnk",var-DS_PROMETHEUS="Prometheus-tencent",job="consul-node-exporter",idc="x-cloud",system="A",environment="pro"]

error log:

D, [2022-03-23T09:26:33.954224 #63360] DEBUG -- : Received response #<Net::HTTPOK:0x000000000780e9c0>
D, [2022-03-23T09:26:34.234588 #63360] DEBUG -- : Processing PanelQueryValueInlineMacro (instance: default, dashboard: dH2etRfnk, panel: 2, query: A)
E, [2022-03-23T09:26:34.235547 #63360] ERROR -- : GrafanaError: Datasource with uid '${DS_PROMETHEUS}' does not exist. (Grafana::DatasourceDoesNotExistError)

by the way, how to query="A"、 query="B"、 query="C" at the same time when use grafana_panel_query_table.

divinity666 commented 2 years ago

Thanks for the bug report. I could reproduce and fix the issue. It will be part of the next release.

Multiple query letters are currently not supported.