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

Update request Error when using API Data Source as Update Action #343

Closed
inemov opened this issue Feb 9, 2024 · 2 comments · Fixed by #361
Closed

Update request Error when using API Data Source as Update Action #343

inemov opened this issue Feb 9, 2024 · 2 comments · Fixed by #361
Assignees
Labels
enhancement New feature or request

Comments

@inemov
Copy link

inemov commented Feb 9, 2024

The error comes when update request is sent from the panel, and it seems returned by the grafana server, not by remote (datasource) server. Below is the error text. Bold shown customized payload.

Request
{"status":500,"statusText":"Internal Server Error","data":{"message":"Query data error","traceID":"00000000000000000000000000000000"},"config":{"method":"POST","url":"api/ds/query","data":{"queries":[{"datasourceId":2,"refId":"A","databaseName":"xxxx","tagId":"HS-201","metric":"MV","value":1}]},"retry":0,"headers":{"X-Grafana-Org-Id":1},"hideFromInspector":false}}

This is Update Request configuration:
image

This is Request Payload with "Code" option selected:

const payload = {};

elements.forEach((element) => {
  if (!element.value) {
    return;
  }

  payload[element.id] = element.value;
})

/**
 * Data Source payload
 */
return {
  "databaseName": "xxxx",
  "tagId": "HS-201",
  "metric": "MV",
  "value": Number(payload.switch),
};

This is request headers:
image

This is request payload:
image

This is response:
image

@mikhail-vl mikhail-vl added the question Further information is requested label Feb 9, 2024
@asimonok
Copy link
Collaborator

asimonok commented Feb 9, 2024

@inemov the problem with the data source. Currently, the panel supports only backend data sources (which query data through the POST /ds/query).

We will add a supporting of frontend data sources in the near future.

As a workaround, you can use custom code for update request
Screenshot 2024-02-09 at 16 00 19

const update = async () => {
  const payload = {};

  elements.forEach((element) => {
    if (!element.value) {
      return;
    }

    payload[element.id] = element.value;
  })

  context.grafana.backendService.post('your request')
};

return update();

@asimonok asimonok added enhancement New feature or request and removed question Further information is requested labels Feb 9, 2024
@inemov
Copy link
Author

inemov commented Feb 9, 2024

Hi @asimonok. Thanks for your investigation!
Glad to hear there is plan to add the feature. Although update request via code is a good temporary workaround, registered datasource has advantage of keeping authentication hidden and credentials safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

3 participants