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

Document how to Analyze results of Host DNS #1719

Open
Mahoney opened this issue Jan 13, 2025 · 0 comments
Open

Document how to Analyze results of Host DNS #1719

Mahoney opened this issue Jan 13, 2025 · 0 comments

Comments

@Mahoney
Copy link

Mahoney commented Jan 13, 2025

Describe the rationale for the suggested feature.

Currently the Host DNS analyzere example only shows how to spot wildcard DNS. It does not show how to spot when DNS does or does not resolve.

This is actually a moderately tricky thing to do reliably due to vagaries of jsonCompare and the k8s json path library.

Describe the feature

Add an example of checking a name that will fail if the name does not resolve and pass if it does, as so:

apiVersion: troubleshoot.sh/v1beta2
kind: HostPreflight
metadata:
  name: sample
spec:
  collectors:
    - dns:
        collectorName: valid-check
        hostnames:
          - example.com
          - foo.bar
  analyzers:
    - jsonCompare:
        checkName: Resolves foo.bar
        fileName: host-collectors/dns/valid-check/result.json
        jsonPath: "{$.query['foo\\.bar'][0].record}"
        value: |
          ""
        outcomes:
          - fail:
              when: 'true'
              message: 'Unable to resolve foo.bar'
          - pass:
              when: 'false'
              message: 'Resolved foo.bar'

Additional context

It's surprising that you need to escape the . in foo.bar in the jsonPath expression, because according to the JSONPath specification you should not need to in a string lookup, so it's important to document it here.

A jsonPath expression that does not match anything in the json document returns an empty string, and if the collector does not resolve the name it sets record to an empty string, which makes it hard to distinguish between a broken JSONPath and the name not resolving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant