blackbox_exporter icon indicating copy to clipboard operation
blackbox_exporter copied to clipboard

Support matching JSON body with CEL expressions

Open juho9000 opened this issue 1 year ago • 6 comments

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.

juho9000 avatar Jun 05 '24 12:06 juho9000

@roidelapluie @mem Ping :)

juho9000 avatar Jun 17 '24 11:06 juho9000

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.

mem avatar Jul 23 '24 17:07 mem

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.

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. :)

juho9000 avatar Aug 01 '24 13:08 juho9000

@mem kindly ping :) we are interested about this feature and would like to see it as well

zetaab avatar Aug 07 '24 09:08 zetaab

@mem @roidelapluie any comments to this PR?

zetaab avatar Sep 03 '24 17:09 zetaab

@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. :)

juho9000 avatar Oct 01 '24 14:10 juho9000

ping @electron0zero @mem could you give some opinion about this?

zetaab avatar Dec 09 '24 09:12 zetaab

@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 avatar Jan 23 '25 13:01 juho9000

bernie

juho9000 avatar Feb 26 '25 12:02 juho9000

@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.

electron0zero avatar Feb 26 '25 13:02 electron0zero

thank you for your contribution , and patience with the review process :bow:

electron0zero avatar Mar 13 '25 18:03 electron0zero