Skip to content

Conversation

juho9000
Copy link
Contributor

@juho9000 juho9000 commented Jun 5, 2024

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 juho9000 force-pushed the feature/cel-json-body branch from 45e8b9c to 2f2d0fb Compare June 5, 2024 12:25
@juho9000
Copy link
Contributor Author

juho9000 commented Jun 17, 2024

@roidelapluie @mem Ping :)

Copy link
Contributor

@mem mem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor comments.

@mem
Copy link
Contributor

mem commented Jul 23, 2024

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.

@juho9000 juho9000 force-pushed the feature/cel-json-body branch 2 times, most recently from 0c9b9a0 to f9a0036 Compare August 1, 2024 12:56
@juho9000
Copy link
Contributor Author

juho9000 commented Aug 1, 2024

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 juho9000 requested a review from mem August 1, 2024 13:06
@zetaab
Copy link

zetaab commented Aug 7, 2024

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

@juho9000 juho9000 force-pushed the feature/cel-json-body branch from f9a0036 to b9b903b Compare August 8, 2024 10:13
@juho9000 juho9000 force-pushed the feature/cel-json-body branch 3 times, most recently from fbb6791 to 9131539 Compare August 29, 2024 08:36
@juho9000 juho9000 force-pushed the feature/cel-json-body branch 2 times, most recently from 3101080 to 2b1939d Compare September 3, 2024 07:40
@zetaab
Copy link

zetaab commented Sep 3, 2024

@mem @roidelapluie any comments to this PR?

@juho9000
Copy link
Contributor Author

juho9000 commented Oct 1, 2024

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

@zetaab
Copy link

zetaab commented Dec 9, 2024

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

@juho9000 juho9000 force-pushed the feature/cel-json-body branch 3 times, most recently from a07544b to 704e04a Compare December 17, 2024 11:33
@juho9000 juho9000 force-pushed the feature/cel-json-body branch from 704e04a to 730f1ac Compare January 7, 2025 08:41
@juho9000
Copy link
Contributor Author

juho9000 commented Jan 23, 2025

@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 juho9000 force-pushed the feature/cel-json-body branch 2 times, most recently from 46b9342 to d6df03c Compare January 23, 2025 13:21
@juho9000 juho9000 force-pushed the feature/cel-json-body branch from d6df03c to 41ed81a Compare February 26, 2025 12:32
@juho9000
Copy link
Contributor Author

bernie

juho9000 added 3 commits March 3, 2025 12:10
Signed-off-by: Juho Majasaari <juho.majasaari@iki.fi>
Signed-off-by: Juho Majasaari <juho.majasaari@iki.fi>
Signed-off-by: Juho Majasaari <juho.majasaari@iki.fi>
@juho9000 juho9000 force-pushed the feature/cel-json-body branch from 41ed81a to e60ce42 Compare March 3, 2025 10:11
@juho9000 juho9000 requested review from electron0zero and dgl March 4, 2025 07:40
@juho9000 juho9000 force-pushed the feature/cel-json-body branch from e60ce42 to 8bb2ecb Compare March 4, 2025 08:50
juho9000 added 6 commits March 5, 2025 14:39
Signed-off-by: Juho Majasaari <juho.majasaari@iki.fi>
Signed-off-by: Juho Majasaari <juho.majasaari@iki.fi>
Signed-off-by: Juho Majasaari <juho.majasaari@iki.fi>
Signed-off-by: Juho Majasaari <juho.majasaari@iki.fi>
Signed-off-by: Juho Majasaari <juho.majasaari@iki.fi>
Signed-off-by: Juho Majasaari <juho.majasaari@iki.fi>
@juho9000 juho9000 force-pushed the feature/cel-json-body branch from 8bb2ecb to ce74f98 Compare March 5, 2025 12:39
@juho9000 juho9000 requested a review from dgl March 6, 2025 09:55
Copy link
Member

@dgl dgl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started reviewing if JSON types other than objects would work, in the end I wrote some tests and made them work.

(This will probably need gofmt before committing, I should just have pushed a commit...)

Co-authored-by: David Leadbeater <dgl@dgl.cx>
Signed-off-by: Juho Majasaari <juho.majasaari@iki.fi>
@juho9000 juho9000 force-pushed the feature/cel-json-body branch from 6f0ca3a to edca4bb Compare March 7, 2025 10:10
@juho9000 juho9000 requested a review from dgl March 7, 2025 10:20
Copy link
Member

@dgl dgl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, after comment resolved. Thanks! I'll leave final review to a maintainer though.

Signed-off-by: Juho Majasaari <juho.majasaari@iki.fi>
@electron0zero
Copy link
Member

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

@electron0zero electron0zero merged commit f2078be into prometheus:master Mar 13, 2025
5 checks passed
SuperQ added a commit that referenced this pull request Jun 26, 2025
* [FEATURE] Support matching JSON body with CEL expressions #1255
* [BUGFIX] Fix condition when local dns lookup should happen #1272
* [BUGFIX] Stop scrape logger spam #1381

Signed-off-by: SuperQ <superq@gmail.com>
@SuperQ SuperQ mentioned this pull request Jun 26, 2025
SuperQ added a commit that referenced this pull request Jun 30, 2025
* [FEATURE] Support matching JSON body with CEL expressions #1255
* [BUGFIX] Fix condition when local dns lookup should happen #1272
* [BUGFIX] Stop scrape logger spam #1381

Signed-off-by: SuperQ <superq@gmail.com>
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

Successfully merging this pull request may close these issues.

5 participants