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

jsonpath syntax / AND condition #300

Open
nmamn opened this issue Apr 3, 2024 · 2 comments
Open

jsonpath syntax / AND condition #300

nmamn opened this issue Apr 3, 2024 · 2 comments

Comments

@nmamn
Copy link

nmamn commented Apr 3, 2024

Hi, I am trying to parse a simple json and to add a "AND" condition in my filter, but it seems to give me a syntax error.

let's say my json is

  "healthCheck": [
    {
      "service": "APP1",
      "url": "http://app1",
      "status": "OK"
    },
    {
      "service": "APP2",
      "url": "http://app2",
      "status": "OK"
    }
  ]
}

It seems I cannot put something like this in the config :
path: '{.healthCheck[?(@.service == "APP1" && @.status == "OK")]}'
I get an error in the logs :
caller=collector.go:76 level=error msg="Failed to extract json objects for metric" err="unrecognized character in action: U+0026 '&'"

Am I missing something ? this syntax seems perfectly valid in jsonpath, if I test it in https://jsonpath.com/ it just perfectly works.
Is it supported by this exporter ?

Many thanks,

Nicolas

@arokiaputhotta
Copy link

I have the same problem, any help on this?

@maksimse
Copy link

maksimse commented Oct 9, 2024

I think this is due to k8s.io/client-go/util/jsonpath doesn't allow regex in jsonpath.

We have solved this using Prometheus metric_relabel_configs .
@nmamn , it should work like this:

path: "{ .healthCheck[*] }"

and prometheus.yml:

                    metric_relabel_configs:
                      - source_labels: [service]
                        action: drop
                        regex: "^(APP1|APPn|.*APPz.*)$"

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

3 participants