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

Can't connect to API when URL contains encoded slash #59

Open
sergejmueller opened this issue Feb 13, 2021 · 13 comments
Open

Can't connect to API when URL contains encoded slash #59

sergejmueller opened this issue Feb 13, 2021 · 13 comments
Labels
type/bug Unexpected behavior or a feature is broken

Comments

@sergejmueller
Copy link

Hello.

Whenever I want to create a data source with the JSON API plugin I get an error message: “JSON API: Cannot connect to API”. But only for URLs that have an encoded slash, e.g. https://streamr.network/api/v1/streams/0x688759bcbb6adf32a07e91f6de84d181b252e655%2Fethereum-gas-prices/data/partitions/0/last - I can request the URL in a browser without errors.

Any idea? Should I encode/escape any character more?
Thank you.

@marcusolsson
Copy link
Contributor

Thank you for letting me know, and for providing an endpoint that I can easily test.

I confirm that I'm able to reproduce this. Indeed it looks like the encoded slash gets decoded.

CleanShot 2021-02-14 at 11 22 55@2x

CleanShot 2021-02-14 at 11 23 41@2x

I don't have a quick fix in mind at this point, but I'll make sure to look into this.

@marcusolsson marcusolsson added the type/bug Unexpected behavior or a feature is broken label Feb 14, 2021
@marcusolsson marcusolsson added this to To do in Grafana Plugins via automation Feb 14, 2021
@marcusolsson marcusolsson moved this from To do to In progress in Grafana Plugins Mar 4, 2021
Grafana Plugins automation moved this from In progress to Done Mar 5, 2021
@sergejmueller
Copy link
Author

@marcusolsson Thank you for fixing the issue. How I get the updated plugin version on grafana.com (Grafana Cloud)?

@marcusolsson
Copy link
Contributor

The fix is available in v1.0.1. You should be able to update it by installing the latest version.

@sergejmueller
Copy link
Author

I know, I can update any plugin on my local Grafana instance. The question is, how I can update a plugin on the Grafana Cloud?
Bildschirmfoto 2021-03-06 um 13 44 41

@marcusolsson
Copy link
Contributor

You should be able to upgrade from the marketplace. If you go to this URL:

https://grafana.com/grafana/plugins/marcusolsson-json-datasource/installation?version=1.0.1

Do you see this button?

Screenshot 2021-03-06 at 13 56 49@2x

@sergejmueller
Copy link
Author

sergejmueller commented Mar 6, 2021

Ah, ok. I see. Updated. (not a user friendly way to update a plugin 😀)

@sergejmueller
Copy link
Author

sergejmueller commented Mar 6, 2021

Marcus, did you test your fix with the url above https://streamr.network/api/v1/streams/0x688759bcbb6adf32a07e91f6de84d181b252e655%2Fethereum-gas-prices/data/partitions/0/last?

After the update i get an error "Stream 0x688759bcbb6adf32a07e91f6de84d181b252e655%2Fstreamr%2Fgrowth%2Fstreams not found."

Encoding issue?

Bildschirmfoto 2021-03-06 um 14 09 45

@marcusolsson
Copy link
Contributor

It looks like it's working as intended, no? Are you sure the resource exists?

@sergejmueller
Copy link
Author

@marcusolsson
Copy link
Contributor

Hm. Weird thing is that you're getting an API error saying that the resource doesn't exist. And the resource name looks correct? Not sure what's happening here.

@sergejmueller
Copy link
Author

sergejmueller commented Mar 7, 2021

The error message says, the stream is not found. The stream is the encoded part of the url: 0x688759bcbb6adf32a07e91f6de84d181b252e655%2Fethereum-gas-prices. If you click the link https://streamr.network/api/v1/streams/0x688759bcbb6adf32a07e91f6de84d181b252e655%2Fethereum-gas-prices/data/partitions/0/last you can see, the browser can resolve the encoded part and the API endpoint returns a valid JSON.

The Grafana JSON plugin (or Grafana Core?) creates a broken request url, so that the API endpoint can't resolve the encoded stream within the requested url.

Let me explain

  • Original URL: https://streamr.network/api/v1/streams/0x688759bcbb6adf32a07e91f6de84d181b252e655%2Fethereum-gas-prices/data/partitions/0/last

  • Builded / Requested URL (from Grafana Query Inspector): api/datasources/proxy/21/api/v1/streams/0x688759bcbb6adf32a07e91f6de84d181b252e655%252Fethereum-gas-prices/data/partitions/0/last

Please compare the encoded slashes:

  • Original URL: %2F (correct)
  • Builded / Requested URL: %252F (wrong because double encoded)

Bildschirmfoto 2021-03-07 um 08 58 45

@marcusolsson marcusolsson reopened this Mar 7, 2021
Grafana Plugins automation moved this from Done to In progress Mar 7, 2021
@marcusolsson
Copy link
Contributor

This is weird. It seems like there's some magic happening in the Grafana proxy.

If I make the request through the proxy, it fails.

http://localhost:3000/api/datasources/proxy/51/api/v1/streams/0x688759bcbb6adf32a07e91f6de84d181b252e655%2Fethereum-gas-prices/data/partitions/0/last

But if I make the request directly from the browser, it succeeds even without the earlier "fix".

https://streamr.network/api/v1/streams/0x688759bcbb6adf32a07e91f6de84d181b252e655%2Fethereum-gas-prices/data/partitions/0/last

I'll have to look closer at what the proxy does with the request. I've reverted the previous commit for now. Thanks for the patience on this.

@jskiweb
Copy link

jskiweb commented Jun 10, 2022

Hi, i know its now 2022, But i did try to setup an json api (http://IP/api/v2/status) and it is not working it says network error, But on the raspberry pi where my grafana is installed , a normal curl request works fine. I did try to setup another api without a slash and it works. Any fix for that?

@marcusolsson marcusolsson removed this from Backlog in Grafana Plugins Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Unexpected behavior or a feature is broken
Projects
Status: No status
Development

No branches or pull requests

4 participants