replicatedhq/troubleshoot

JSONCompare Analyzer: Allow outcome message to be templated with collected contents

diamonwiggins opened this issue · 4 comments

Describe the rationale for the suggested feature.

Given the following collected JSON data, a user may want to template the outcome message in the JSONCompare analyzer to include details from the collected contents to provide more context to end users:

{
  "stuff": {
    "status": "ready",
    "info": "this stuff is ready"
  },
  "morestuff": {
    "status": "notready",
    "info": "morestuff is not ready"
  },
}

Describe the feature

Update the JSONCompare analyzer to render a template on the outcome messages using the collected JSON

apiVersion: troubleshoot.sh/v1beta2
kind: Preflight
metadata:
  name: jsonpath-compare-example
spec:
  collectors:
    - data:
        name: example.json
        data: |
          {
            "morestuff": {
              "status": "notready",
              "info": "morestuff is not ready"
            },
          }
  analyzers:
    - jsonCompare:
        checkName: Compare JSONPath Example
        fileName: example.json
        path: "morestuff.status"
        value: |
          ready
        outcomes:
          - fail:
              when: "false"
              message: "Not Ready: {{ .morestuff.info }}"
          - pass:
              when: "true"
              message: "Ready: {{ .morestuff.info }}"

Describe alternatives you've considered

Describe alternative solutions here. Include any workarounds you've considered.

Additional context

Add additional context about the feature request. If the change is substantial, consider attaching files to the issue outlining architectural changes, data flows, file formats etc., anything that helps describe the requested change.

@diamonwiggins will this issue also address #731?

@diamonwiggins will this issue also address #731?

so it sort of addresses some of that, but not this

We'll probably want to do some fancy math in some of the expressions, like counting/filtering (e.g. 10 healthy nodes, 2 Not Ready / Unreachable)

i think something like that would be satisfied by also allowing templating of the message in NodeResources. See - https://troubleshoot.sh/docs/analyze/node-resources/

In general we should think broadly about everywhere we should be allowing for templating in the value or message portions of an analyzer. Seems like a very useful thing

The jsonCompare value field needs to be valid JSON value. ready is not valid JSON but "ready" is

    - jsonCompare:
        value: |
          "ready"

Yup, good call. In my example i've done just that - replicatedhq/troubleshoot.sh#538