dynatrace-extensions / dynatrace-extensions-vscode

A VisualStudio Code extension to support all aspects of developing Dynatrace Extensions 2.0
Apache License 2.0
16 stars 7 forks source link

The environment URL entered is not reachable. #222

Closed avinashpodisetti closed 3 months ago

avinashpodisetti commented 4 months ago

Description

Getting following error while connecting to a managed tenant from VSCode.

Workspace setup: Running VS Code on MAC

extension settings:

"https.proxyAuthorization": true,
"dynatraceExtensions.tenantConnectivitySettings": [
    {
        "tenantUrl": "https://dt-managed-notprod.xxxxxxx.com/e/e1f",
        "disableSSLVerification": true
    }
],
"dynatraceExtensions.developerCertkeyLocation": "/Users/lidsc82/Library/Application Support/Code/User/workspaceStorage/6981e38805c4349be598fa9a2cf0e677/DynatracePlatformExtensions.dynatrace-extensions/certificates/developer.pem",
"dynatraceExtensions.rootOrCaCertificateLocation": "/Users/lidsc82/Library/Application Support/Code/User/workspaceStorage/6981e38805c4349be598fa9a2cf0e677/DynatracePlatformExtensions.dynatrace-extensions/certificates/ca.pem",
"dynatraceExtensions.fastDevelopmentMode": true,
"dynatraceExtensions.simulator.defaultMetricsIngestion": true,
"dynatraceExtensions.logging.maxFileSize": 50,
"dynatraceExtensions.logging.level": "DEBUG",
"dynatraceExtensions.simulator.defaultLocation": "REMOTE",
"http.proxyStrictSSL": false,
"workbench.trustedDomains.promptInTrustedWorkspace": true,

Error Message support_archive_mac.zip

{"message":"Request failed with status code 400","name":"AxiosError","stack":"AxiosError: Request failed with status code 400\n at Ba (/Users/lidsc82/.vscode/extensions/dynatraceplatformextensions.dynatrace-extensions-2.6.1-darwin-x64/out/main.js:185:1040)\n at IncomingMessage. (/Users/lidsc82/.vscode/extensions/dynatraceplatformextensions.dynatrace-extensions-2.6.1-darwin-x64/out/main.js:186:8709)\n at IncomingMessage.emit (node:events:529:35)\n at endReadableNT (node:internal/streams/readable:1368:12)\n at processTicksAndRejections (node:internal/process/task_queues:82:21)","config":{"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"adapter":["xhr","http"],"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"env":{},"headers":{"Accept":"application/json, text/plain, /","User-Agent":"axios/1.6.3","Accept-Encoding":"gzip, compress, deflate, br"},"maxRedirects":20,"method":"get","url":"https://dt-managed-notprod.xxxxxxxx.com/e/e1fc94f/api/v1/time"},"code":"ERR_BAD_REQUEST","status":400}

Steps to reproduce

initialized workspace and trying to add environment

Support information

radu-stefan-dt commented 4 months ago

Hi @avinashpodisetti. Thank you for raising this issue and apologies for the late reply.

avinashpodisetti commented 4 months ago

Hi @radu-stefan-dt . Thanks for getting back to me..

radu-stefan-dt commented 3 months ago

Are you able to access any logs on the proxy side about these requests?

From the extension all the configuration is applied correctly. Namely, I can see that the URL is recognized and SSL verification is disabled.

We don't have any handling of the HTTP_PROXY, HTTPS_PROXY environment variables as this was assumed to work with anything running in VSCode without additional processing.

d41k4n commented 3 months ago

I have a similar issue, the only difference is I'm getting a 405 instead of a 400 error:

2024-07-01T16:11:16.181Z [ERROR][utils.conditionCheckers.checkEnvironmentConnected] You must be connected to a Dynatrace Environment to use this command.
2024-07-01T16:11:35.473Z [ERROR][utils.conditionCheckers.checkUrlReachable] {"message":"Request failed with status code 405","name":"AxiosError","stack":"AxiosError: Request failed with status code 405\n    at Ba (/home/xxxxxx/.vscode-server/extensions/dynatraceplatformextensions.dynatrace-extensions-2.6.1/out/main.js:185:1040)\n    at IncomingMessage.<anonymous> (/home/xxxxxx/.vscode-server/extensions/dynatraceplatformextensions.dynatrace-extensions-2.6.1/out/main.js:186:8709)\n    at IncomingMessage.emit (node:events:530:35)\n    at endReadableNT (node:internal/streams/readable:1696:12)\n    at processTicksAndRejections (node:internal/process/task_queues:82:21)","config":{"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"adapter":["xhr","http"],"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"env":{},"headers":{"Accept":"application/json, text/plain, */*","User-Agent":"axios/1.6.3","Accept-Encoding":"gzip, compress, deflate, br"},"maxRedirects":20,"method":"get","url":"https://xxxxxxxxx.live.dynatrace.com/api/v1/time"},"code":"ERR_BAD_REQUEST","status":405}

I'm also using a proxy configured in settings.json as

{
    "http.proxy": "http://localhost:8888",
    "http.proxyAuthorization": null
}

to reach the internet. Other VSC extensions which communicate with the internet work fine in the same workspace (e.g. GitHub Copilot).

After I get the error I can see the following entries in the proxy log e.g.:

{"level":"debug","ts":1719851877.3312619,"msg":"Request started","http_proto":"HTTP/1.1","http_method":"GET","user_agent":"axios/1.6.3","uri":"https://xxxxxxxxx.live.dynatrace.com/api/v1/time"}
{"level":"debug","ts":1719851877.3312619,"msg":"Request completed","http_proto":"HTTP/1.1","http_method":"GET","user_agent":"axios/1.6.3","uri":"https://xxxxxxxxx.live.dynatrace.com/api/v1/time"}

I can reach the same URL https://xxxxxxxxx.live.dynatrace.com/api/v1/time in a VSC terminal window via curl just fine when going through the same proxy e.g.

$ env | grep -i _proxy
https_proxy=http://localhost:8888
HTTPS_PROXY=http://localhost:8888
HTTP_PROXY=http://localhost:8888
http_proxy=http://localhost:8888
$ curl https://xxxxxxxxx.live.dynatrace.com/api/v1/time
1719852903595

but then I get additional/different log entries:

{"level":"debug","ts":1719852264.9799116,"msg":"Request started","http_proto":"HTTP/1.1","http_method":"CONNECT","user_agent":"curl/7.81.0","uri":"xxxxxxxxx.live.dynatrace.com:443"}
{"level":"debug","ts":1719852265.115475,"msg":"CONNECT tunnel opened","http_proto":"HTTP/1.1","http_method":"CONNECT","user_agent":"curl/7.81.0","uri":"xxxxxxxxx.live.dynatrace.com:443"}
{"level":"debug","ts":1719852265.35032,"msg":"Traffic copied successfully","http_proto":"HTTP/1.1","http_method":"CONNECT","user_agent":"curl/7.81.0","uri":"xxxxxxxxx.live.dynatrace.com:443"}
{"level":"debug","ts":1719852265.352512,"msg":"CONNECT tunnel closed","http_proto":"HTTP/1.1","http_method":"CONNECT","user_agent":"curl/7.81.0","uri":"xxxxxxxxx.live.dynatrace.com:443"}
{"level":"debug","ts":1719852265.3564875,"msg":"Request completed","http_proto":"HTTP/1.1","http_method":"CONNECT","user_agent":"curl/7.81.0","uri":"xxxxxxxxx.live.dynatrace.com:443"}

It looks like the extension is talking to the proxy as if it would be the destination host instead of establishing a tunnel via the CONNECT method...

radu-stefan-dt commented 3 months ago

Hi @d41k4n

What you're describing makes sense. The extension creates an Axios client, and then uses it to make requests to the URLs as needed (in your case GET to https://<tenant>/api/v1/time). The VSCode settings for proxies are not processed and added to this client at all, as that was assumed to be handled by VSCode for all extensions.

radu-stefan-dt commented 3 months ago

Judging by the details you shared as well as @avinashpodisetti above, I'm not sure the assumption that VSCode will handle proxy communications on behalf of extensions stands true. This might have to become a feature request for us to process and pass on those settings into the Axios client.

d41k4n commented 3 months ago

Hi @radu-stefan-dt

The VSCode settings for proxies are not processed and added to this client at all, as that was assumed to be handled by VSCode for all extensions.

If this is true then why is the extension even trying to contact the proxy host (which in my case is configured in the VSCode settings) via GET method?

So if I understood correctly the extension is currently lacking all proxy support, correct?

radu-stefan-dt commented 3 months ago

why is the extension even trying to contact the proxy host

I have a feeling Axios might also recognize those environment variables and apply them automatically.

I'm not sure if there is any difference compared to when proxy details are explicitly fed into the Axios client setup.

the extension is currently lacking all proxy support, correct?

Any support is untested and involuntary due to the standard environment variables.

radu-stefan-dt commented 3 months ago

@d41k4n could you please remove the port from the proxy variable?

Instead of:

HTTPS_PROXY=http://localhost:8888
HTTP_PROXY=http://localhost:8888

Use:

HTTPS_PROXY=http://localhost
HTTP_PROXY=http://localhost
d41k4n commented 3 months ago

@radu-stefan-dt

Doesn't help - the only difference is now I'm getting a 400 instead of a 405:

2024-07-05T10:57:27.386Z [ERROR][utils.conditionCheckers.checkUrlReachable] {"message":"Request failed with status code 400","name":"AxiosError","stack":"AxiosError: Request failed with status code 400\n    at Ba (/home/xxxxxx/.vscode-server/extensions/dynatraceplatformextensions.dynatrace-extensions-2.6.1/out/main.js:185:1040)\n    at IncomingMessage.<anonymous> (/home/xxxxxx/.vscode-server/extensions/dynatraceplatformextensions.dynatrace-extensions-2.6.1/out/main.js:186:8709)\n    at IncomingMessage.emit (node:events:530:35)\n    at endReadableNT (node:internal/streams/readable:1696:12)\n    at processTicksAndRejections (node:internal/process/task_queues:82:21)","config":{"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"adapter":["xhr","http"],"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"env":{},"headers":{"Accept":"application/json, text/plain, */*","User-Agent":"axios/1.6.3","Accept-Encoding":"gzip, compress, deflate, br"},"maxRedirects":20,"method":"get","url":"https://xxxxxxxx.live.dynatrace.com/api/v1/time"},"code":"ERR_BAD_REQUEST","status":400}

Btw, this is how I configured the proxy in VSCode:

image

FYI: The env vars "https_proxy" and "http_proxy" are not set anywhere else on the system or in VSCode.

radu-stefan-dt commented 3 months ago

With how things are currently implemented, there is little help I can offer.

I am transferring this into a feature idea under #244