troubleshoot icon indicating copy to clipboard operation
troubleshoot copied to clipboard

Extend http analyser to allow inspecting the response body

Open banjoh opened this issue 2 years ago • 1 comments

Describe the rationale for the suggested feature.

The http collector output wraps the response body in a JSON value. There is no clean way to analyse the contents of the body using the http analyser (Not documented in troubleshoot.sh) at the moment. We need to address this by extending the http analyser to allow when values that evaluate against various query implementations such as jsonpath, regex or simple comparisons (==, >= ....)

Describe the feature

Add new when evaluation syntax to allow crafting further queries against the response body. The spec would look like so

Spec

- http:
  checkName: health-check
  collectorName: health-check
  outcomes:
    - pass:
      when: "body == '{\"status\": \"OK\"}'"
      message: ""
    - warn:
      when: "jsonpath($.status) == 'DEGRADED'"
      message: ""
    - error:
      when: "regexMatch(*service is unhealthy*)"
      message: ""

The when operations can be made simpler or different. Its for example not clear from the above spec whether its the body we are comparing with. Alternatives welcome

Collector output

{
  "response": {
    "status": 200,
    "body": "{\"status\": \"DEGRADED\"}",
    "headers": {
    "Connection": "keep-alive",
    "Date": "Fri, 19 Jul 2019 20:13:44 GMT",
    "Server": "nginx/1.8.1",
    "Strict-Transport-Security": "max-age=31536000; includeSubDomains"
    }
  }
}

Describe alternatives you've considered

  • Use our current regex, json and yaml analysers to further examine the output. This looks like a strong alternative. For these to be the acceptable solution, the http collector would need to extract the body from the json output to a format that can be consumed by the yaml & json analysers.

banjoh avatar Jan 19 '23 12:01 banjoh

Related issues/PRs

  • https://github.com/replicatedhq/troubleshoot-specs/pull/37
  • https://github.com/replicatedhq/troubleshoot-specs/pull/36

banjoh avatar Jan 19 '23 12:01 banjoh