Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to fetch query data when a template variable of assets was selected as multiple items or 'All' #178

Closed
nyamad opened this issue Apr 28, 2023 · 4 comments · Fixed by #205

Comments

@nyamad
Copy link

nyamad commented Apr 28, 2023

What happened:

I have dashboards depending on template variables which store list of multiple assets of SiteWise for repeating panels.

For plugin version 1.7.0 or 1.8.0, if the variable's Multi-value or All option was enabled and I used them, panels did not render correct values due to the query data issue.

What you expected to happen:

Same as behavior as plugin version 1.5.1 (see screenshots)

How to reproduce it (as minimally and precisely as possible):

  1. On AWS IoT Sitewise, create an asset model like Example model with any property like foo
  2. Create two or more assets based on Example model, like Asset-A and Asset-B.
  3. Edit those assets to set any value to foo.
  4. On Grafana, go to any dashboard and create a variable like a assets using a SiteWise datasource, then select List assets in the Query type field and Example model in the Model ID field. Then check both of Multi-value and Include All option options, and click Apply.
  5. Add a panel, then:
    • On Query tab:
      • Select a SiteWise datasource
      • Select Get property value as Query type
      • Select ${assets} as Asset
      • Select foo as Property
    • Select Stat as visualization:
      • Select assets as Repeat by variable
      • Select foo as Fields in Value Options section
    • Click Apply and close the panel.
  6. Click assets variable dropdown on the dashboard:
    • Select only Asset-A -> The panel was rendered as expected.
    • Select Asset-A and Asset-B -> Two panels were rendered, but values of them are not correct (shown as 'No data').
    • Select All -> Panels show error as attached screenshot.

Screenshots

Plugin version 1.8.0:

  • Single item was selected:
    • v1 8 0-select-a-value
  • Two items were selected:
    • v1 8 0-select-two-values
  • 'All' was selected:
    • v1 8 0_select-All

Plugin version 1.5.1 (expected behavior)

  • Single item was selected:
    • v1 5 1_select-a-value
  • Two items were selected:
    • v1 5 1_select-two-values
  • 'All' was selected:
    • v1 5 1_select-All

Anything else we need to know?:

Environment:

  • Grafana version: 9.4.7 or 9.5.1
  • Plugin version: 1.7.0 or 1.8.0 (1.5.1 is OK)
  • OS Grafana is installed on: Ubuntu 22.04
  • User OS & Browser: Windows 10 & Chrome
  • Others:

Thanks in advance,

@nyamad nyamad added datasource/Sitewise type/bug Something isn't working labels Apr 28, 2023
@idastambuk
Copy link
Contributor

Hi @nyamad Thanks for reporting this!

I've been able to reproduce something similar; however, I'm getting back some data in all of the panels (even though it's the same number - so there's definitely a bug there, but maybe a different one).

To help us in debugging this, can you please paste (or attach a file with) the payload for your requests to /api/ds/query?ds_type=grafana-iot-sitewise-datasource for both queries in example "Asset A + Asset B" and "all", from the Network tab of your dev tools? More specifically, I need the queries[0] object from each of them. It would be super helpful, thanks!

@nyamad
Copy link
Author

nyamad commented May 1, 2023

Hello @idastambuk san,

Thank you for your confirmation and message.

I've captured payloads of requests as follows.

Selecting Asset-A and Asset-B

For first panel:

{
  "queries": [
    {
      "assetIds": [
        "f619580e-5d3a-43df-9644-9ad496c96cdf",
        "d8de088e-e659-4fad-9eda-702ff11aaf18"
      ],
      "datasource": {
        "type": "grafana-iot-sitewise-datasource",
        "uid": "ad22b52d-1bf0-4574-a0a9-a5a26d112c86"
      },
      "maxPageAggregations": 1,
      "propertyId": "7a33a814-5cb3-4a43-a85c-f2b2fb0269c6",
      "queryType": "PropertyValue",
      "refId": "A",
      "propertyAlias": "",
      "region": "",
      "datasourceId": 18,
      "intervalMs": 20000,
      "maxDataPoints": 940
    }
  ],
  "range": {
    "from": "2023-05-01T03:43:13.852Z",
    "to": "2023-05-01T09:43:13.852Z",
    "raw": {
      "from": "now-6h",
      "to": "now"
    }
  },
  "from": "1682912593852",
  "to": "1682934193852"
}

For second panel:

{
  "queries": [
    {
      "assetIds": [
        "f619580e-5d3a-43df-9644-9ad496c96cdf",
        "d8de088e-e659-4fad-9eda-702ff11aaf18"
      ],
      "datasource": {
        "type": "grafana-iot-sitewise-datasource",
        "uid": "ad22b52d-1bf0-4574-a0a9-a5a26d112c86"
      },
      "maxPageAggregations": 1,
      "propertyId": "7a33a814-5cb3-4a43-a85c-f2b2fb0269c6",
      "queryType": "PropertyValue",
      "refId": "A",
      "propertyAlias": "",
      "region": "",
      "datasourceId": 18,
      "intervalMs": 20000,
      "maxDataPoints": 940
    }
  ],
  "range": {
    "from": "2023-05-01T03:43:13.911Z",
    "to": "2023-05-01T09:43:13.912Z",
    "raw": {
      "from": "now-6h",
      "to": "now"
    }
  },
  "from": "1682912593911",
  "to": "1682934193912"
}

Selecting 'All'

{
  "queries": [
    {
      "assetIds": [
        "$__all"
      ],
      "datasource": {
        "type": "grafana-iot-sitewise-datasource",
        "uid": "ad22b52d-1bf0-4574-a0a9-a5a26d112c86"
      },
      "maxPageAggregations": 1,
      "propertyId": "7a33a814-5cb3-4a43-a85c-f2b2fb0269c6",
      "queryType": "PropertyValue",
      "refId": "A",
      "propertyAlias": "",
      "region": "",
      "datasourceId": 18,
      "intervalMs": 20000,
      "maxDataPoints": 940
    }
  ],
  "range": {
    "from": "2023-05-01T03:57:22.682Z",
    "to": "2023-05-01T09:57:22.682Z",
    "raw": {
      "from": "now-6h",
      "to": "now"
    }
  },
  "from": "1682913442682",
  "to": "1682935042682"
}
{
  "queries": [
    {
      "assetIds": [
        "$__all"
      ],
      "datasource": {
        "type": "grafana-iot-sitewise-datasource",
        "uid": "ad22b52d-1bf0-4574-a0a9-a5a26d112c86"
      },
      "maxPageAggregations": 1,
      "propertyId": "7a33a814-5cb3-4a43-a85c-f2b2fb0269c6",
      "queryType": "PropertyValue",
      "refId": "A",
      "propertyAlias": "",
      "region": "",
      "datasourceId": 18,
      "intervalMs": 20000,
      "maxDataPoints": 940
    }
  ],
  "range": {
    "from": "2023-05-01T03:57:22.731Z",
    "to": "2023-05-01T09:57:22.732Z",
    "raw": {
      "from": "now-6h",
      "to": "now"
    }
  },
  "from": "1682913442731",
  "to": "1682935042732"
}

(FYR) Selecting only Asset-A

{
  "queries": [
    {
      "assetIds": [
        "f619580e-5d3a-43df-9644-9ad496c96cdf"
      ],
      "datasource": {
        "type": "grafana-iot-sitewise-datasource",
        "uid": "ad22b52d-1bf0-4574-a0a9-a5a26d112c86"
      },
      "maxPageAggregations": 1,
      "propertyId": "7a33a814-5cb3-4a43-a85c-f2b2fb0269c6",
      "queryType": "PropertyValue",
      "refId": "A",
      "propertyAlias": "",
      "region": "",
      "datasourceId": 18,
      "intervalMs": 10000,
      "maxDataPoints": 1888
    }
  ],
  "range": {
    "from": "2023-05-01T03:56:00.193Z",
    "to": "2023-05-01T09:56:00.193Z",
    "raw": {
      "from": "now-6h",
      "to": "now"
    }
  },
  "from": "1682913360193",
  "to": "1682934960193"
}

I hope these would be helpful. If more information is needed, please ask me again.

@idastambuk
Copy link
Contributor

Hi @nyamad thanks a lot, that helps! We will add it to our backlog.

For anyone that picks this up: it seems like the assetId fields in all queries are the same - an array of both. I would expect them to be iterated by panels, so that each panel gets its own assetId to query.

Not sure how this feature works exactly though, and if the plugin or grafana is in charge of iterating over the variables.
It might(?) have something to do with the Sitewise plugin supporting multiple asssetIds which somehow breaks the panel repeat flow. (since the problem started after 1.6.0)

@misiek303
Copy link

I have exactly the same issue
Grafana: 9.5.2
SWE Plugin: 1.9.1

Any progress or workaround for it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
4 participants