Dynatrace / libbuildpack-dynatrace

Common resources used for Dynatrace integration in Cloudfoundry Buildpacks.
Apache License 2.0
1 stars 5 forks source link

skiperrors flag does not work if `apiurl` contains an invalid path #14

Closed Anika-Sol closed 3 years ago

Anika-Sol commented 4 years ago

Hi,

We are using the skiperrors flag to make sure that our cf application is also able to be staged in the case that our Dynatrace managed cluster is not available.

Under normal circumstances (e.g. cluster responds with a 404 or 502) the skiperrors flag works perfectly, but we recently experienced the application staging to fail, even if skiperrors is set to "true".

The scenario: We create a user provided service with the following parameters ("/api" is missing in the path of the apiurl:

     "apitoken": "<token>",
     "apiurl": "<DynatraceManaged cluster URL>/e/<environmentID>",  #missing the "/api" in the path
     "environmentid": "<environmentID>",
     "skiperrors": "true"

We restage the application and get the following error:

Staging app and tracing logs...

  ...

   -----> Go Buildpack version 1.9.8

  ...

          **WARNING** Installing package '.' (default)
   -----> Running: go install -tags cloudfoundry -buildmode pie .
          Dynatrace service credentials found. Setting up Dynatrace OneAgent.
          Downloading '<DynatraceManaged cluster URL>/e/<environmentID>/v1/deployment/installer/agent/unix/paas-sh/latest?bitness=64&include=go&include=process' to '/tmp/paasInstaller.sh'
   -----> Starting Dynatrace OneAgent installer
          **ERROR** After Compile: fork/exec /tmp/paasInstaller.sh: exec format error
   Failed to compile droplet: Failed to run finalize script: exit status 13
   Exit status 223

I think the reason why the skiperrors flag is not working in this case is, that the download URL returns a 200 status code while it should return 404.

When I try the agent link in my browser, I get a 404 status code. But if I try it with curl, I get a 200 OK status code with a HTML response body, telling me that my browser is not supported.

curl --location --request GET '<DynatraceManaged cluster URL>/e/<environmentID>/v1/deployment/installer/agent/unix/paas-sh/latest?bitness=64&include=go&include=process' \
--header 'Authorization: Api-Token <token>'

In this case (200 status code) the request is not discovered as failure and the staging fails in the next step when executing the oneagent installer (which wasn't downloaded).

I guess this behaviour is not intended especially if the user set the skiperrors flag to true, please let me know if you need more details.

arthfl commented 3 years ago

Sorry for the very late answer on this.

Regarding your issue: The skiperrors flag is intended to not interupt deployments in case of networking issues. Which is why the check for it is placed right after the download of the installer: https://github.com/Dynatrace/libbuildpack-dynatrace/blob/master/hook.go#L91 Which is also documented here: https://github.com/Dynatrace/libbuildpack-dynatrace#configuration

If the download endpoint returns a 200, we of course assume everything is alright and continue. We intentionally don't skip over issues with the downloaded installer (or whatever was delivered from the endpoint), because that would potentially bury issues. Like in your case a faulty api-url configuration :-)