Support matching JSON body with CEL expressions
This PR implements parsing a JSON response from the body and checking the result using a CEL query. Looking for feedback on this.
Sample usage:
modules:
http_2xx:
prober: http
http:
fail_if_body_json_not_matches_cel: "body.foo.bar == 'baz'"
If response is {"foo": { "bar": "qux" } } the probe fails. fail_if_body_json_matches_cel is also implemented and should work as expected.
@roidelapluie @mem Ping :)
Thank you for this, this seems useful!
Question, I have no experience with CEL... is it possible to use it to match HTML, too? I see in the code that Eval takes a map[string]any, but I couldn't spot how that any is handled.
The reason I'm asking is because I'm trying to figure out if it's possible to extend this to more inputs, or if it needs to be restricted to JSON.
Thank you for this, this seems useful!
Question, I have no experience with CEL... is it possible to use it to match HTML, too? I see in the code that Eval takes a
map[string]any, but I couldn't spot how thatanyis handled.The reason I'm asking is because I'm trying to figure out if it's possible to extend this to more inputs, or if it needs to be restricted to JSON.
I atleast do not know how CEL could be used to match HTML in any sane way. You might want to check this out https://github.com/google/cel-spec/blob/master/doc/langdef.md#json-data-conversion
Thanks for your comments and suggestions so far. Really hoping we can get this merged. I think that having the ability to validate JSON responses would be an awesome addition to blackbox exporter. :)
@mem kindly ping :) we are interested about this feature and would like to see it as well
@mem @roidelapluie any comments to this PR?
@electron0zero @mem I haven't heard from any of the maintainers in a while. I fixed or clarified everything that was mentioned in the review comments. The initial message I got was that this seems useful, but it seems that it's forgotten now. Any update? I'd love to get this merged in order to avoid maintaining my own fork. :)
ping @electron0zero @mem could you give some opinion about this?
@mem I'm willing to donate you a sixpack in exchange for a review at this point. Please either review this or close it if it's not going to make its way into blackbox exporter.
@juho9000 took some time to review. feel free to drop in #prometheus-exporters-dev in CNCF slack if you want to discuss something offline or in more details.
thank you for your contribution , and patience with the review process :bow: