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

Using propertyAlias to query does not work #211

Closed
oliverschenk opened this issue Aug 15, 2023 · 5 comments
Closed

Using propertyAlias to query does not work #211

oliverschenk opened this issue Aug 15, 2023 · 5 comments

Comments

@oliverschenk
Copy link

oliverschenk commented Aug 15, 2023

What happened:
When using the Grafana AWS IoT SiteWise data source and choosing a Query Type of Get property value, then selecting the Asset and Property from the drop-down boxes works fine.

Using the Property Alias text box instead does not. It returns an error:

failed to fetch query data: InvalidRequestException: Entries size failed to satisfy constraint: Must be at least 1 entry per request.

What you expected to happen:

As per the docs, the query should work by using either:

a) The assetID and propertyID; or
b) The propertyAlias

(a) works fine, (b) does not

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

In AWS SiteWise:

  1. Create a new Model and set Name to GrafanaTest
  2. In measurement definitions set Name to DI02 and Data type to INTEGER
  3. Click Create Model
  4. Create a new Asset
  5. Select model GrafanaTest
  6. Set Name to GrafanaTestAsset1
  7. Click Create Asset
  8. In new asset, click Edit button
  9. In Measurement DI02 set property alias to /GrafanaTestAsset1/DI02
  10. Click Save button

Write some data to this new property:

  1. In notepad create a JSON file with the following:
{
   "entries": [ 
      {
         "entryId": "6f236b80-c015-4598-816c-18f5954c14ec",
         "propertyAlias": "/GrafanaTestAsset1/DI02",
         "propertyValues": [ 
            { 
               "quality": "GOOD",
               "timestamp": { 
                  "offsetInNanos": 0,
                  "timeInSeconds": 1692066526
               },
               "value": {
                  "integerValue": 1
               }
            }
         ]
      }
   ]
}
  1. In the CLI use the following command. Replace the path with your own path to the above JSON file.
aws iotsitewise batch-put-asset-property-value --cli-input-json "file://<path_to_your_batchputpropertyvalue.json>"
  1. You should see the updated value in SiteWise:
    image

In Grafana:

  1. Create a new dashboard
  2. Add a panel
  3. Set AWS IoT SiteWise as the data source
  4. Select Query Type = Get property value
  5. Input /GrafanaTestAsset1/DI02 into Property Alias field
  6. Error appears

image

Try setting using Asset/Propert ID:

  1. Set Asset to GrafanaTestAsset1
  2. Set Property to DI02
  3. Panel updates correctly with 1 data point (value = 1).

image

Why do I want to do this?
Because the SiteWise IoT driver in Grafana does not support populating the "Alarms" listed in an Asset. It only lists Measurements, Attributes, Transforms and Metrics (as far as I can see). In order to get access to alarms, I have set a property alias on each Alarm.

I tried manually setting the property ID based on the alarm property ID, but this also didn't work. I can't seem to populate any Grafana dashboard, because alarms return string values, not numeric values.

Screenshots

Running the command manually via the CLI works fine.

aws iotsitewise get-asset-property-value --property-alias /GrafanaTestAsset1/DI02
{
    "propertyValue": {
        "value": {
            "integerValue": 1
        },
        "timestamp": {
            "timeInSeconds": 1692066526,
            "offsetInNanos": 0
        },
        "quality": "GOOD"
    }
}

Query Result

This is the full detail of a Grafana query in the inspector. You can see it populates propertyAlias and not propertyId and assetIds, which is correct, but I think maybe something in the underlying logic that converts this into an AWS SiteWise API call doesn't quite get the "entries" part right?

{
  "request": {
    "url": "api/ds/query",
    "method": "POST",
    "data": {
      "queries": [
        {
          "datasource": {
            "type": "grafana-iot-sitewise-datasource",
            "uid": "b0gBbh34z"
          },
          "refId": "A",
          "hide": false,
          "maxPageAggregations": 1,
          "queryType": "PropertyValue",
          "propertyAlias": "/GrafanaTestAsset1/DI02",
          "region": "",
          "propertyId": "",
          "assetIds": [],
          "datasourceId": 1,
          "intervalMs": 30000,
          "maxDataPoints": 813
        }
      ],
      "range": {
        "from": "2023-08-14T20:19:17.756Z",
        "to": "2023-08-15T02:19:17.756Z",
        "raw": {
          "from": "now-6h",
          "to": "now"
        }
      },
      "from": "1692044357756",
      "to": "1692065957756"
    },
    "hideFromInspector": false
  },
  "response": {
    "results": {
      "A": {
        "error": "failed to fetch query data: InvalidRequestException: Entries size failed to satisfy constraint: Must be at least 1 entry per request.",
        "status": 500,
        "frames": [],
        "refId": "A"
      }
    }
  }
}

Anything else we need to know?:

Environment:

  • Grafana version: 9.4
  • Plugin version: 1.7.0 (SiteWise Iot) 1.8.1 (AWS Data Sources)
  • OS Grafana is installed on: AWS Managed Grafana
  • User OS & Browser: Windows 11 / Chrome
  • Others:
@iwysiu
Copy link
Contributor

iwysiu commented Aug 15, 2023

Hi @oliverschenk ! Thanks for the bug report and the detailed repro, I managed to reproduce it and I'll take a look at it

@iwysiu
Copy link
Contributor

iwysiu commented Aug 15, 2023

I tried to reproduce it using the most recent version of the Sitewise datasource (v1.10.3), and it was fixed. @oliverschenk can you try using v1.10.3 and see if you're still having this issue?

@iwysiu iwysiu moved this from Incoming to Waiting in AWS Datasources Aug 15, 2023
@oliverschenk
Copy link
Author

oliverschenk commented Aug 15, 2023

Hi @iwysiu - I tried for half an hour to figure out how to update a plugin in Amazon Grafana. I looked in the console for an update button or feature and I looked in the Grafana plugins page, but I can't any way to update plugins. Are the plugin versions in Amazon Grafana fixed and can't be updated? Do I have to rebuild a new instance? The documentation doesn't seem to mention how to update a plugin.

I have a suspicion that Managed Grafana is not keeping up-to-date with the latest plugin versions and you can't update the plugins, even the AWS plugins... do you know how soon the plugins will be updated in Managed Grafana?

@iwysiu
Copy link
Contributor

iwysiu commented Aug 16, 2023

Hi @oliverschenk ! Yeah, sorry that I missed that you were using Amazon Managed Grafana. I've asked our AWS contact when they'll be able to update the SiteWise plugin and I'll tell you what they respond.

@iwysiu
Copy link
Contributor

iwysiu commented Oct 17, 2023

While AWS never got back to me, I'm assuming that it's been updated by now, as it's been 2 months. If the problem persists, please reply on this issue and I'll reopen it!

@iwysiu iwysiu closed this as completed Oct 17, 2023
@github-project-automation github-project-automation bot moved this from Waiting to Done in AWS Datasources Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants