json_exporter icon indicating copy to clipboard operation
json_exporter copied to clipboard

WIP: Initial support for CEL

Open mrueg opened this issue 2 years ago • 4 comments

This adds initial support for queries using the common expression language (CEL).

  • [x] Make decision on config format

having additional separate fields

    - name: example_cel_global_value
      cel: '.baz == "bar" ? 1 : 0'
      help: Example of a top-level global value scrape in the json
      labels_cel:
        environment: '.foo'

vs. defining an engine for the query

    - name: example_cel_global_value
      path: '.baz == "bar" ? 1 : 0'
      help: Example of a top-level global value scrape in the json
      engine: cel # default is jsonpath
      labels:
        environment: '.foo'
  • [x] Add support for labels, values and epochTimestamp
  • [ ] Add documentation

See: https://github.com/prometheus-community/json_exporter/issues/263

mrueg avatar Oct 30 '23 19:10 mrueg

@superq @rustycl0ck any thoughts on this? Would love to get some early feedback to see if this is something you'd be interested in adding.

mrueg avatar Oct 31 '23 15:10 mrueg

Thanks a lot for this MR, just tested this branch and it seems to work fine. We used:

    - name: example_cel_global_value
      cel: '.state == "printing" ? 1 : 0'
      help: Example of a top-level global value scrape in the json
      labels:
        environment: beta # static label

This should potentially solve a lot of related issues that need a bit more advance logic, such as: https://github.com/prometheus-community/json_exporter/issues/151

Please add a bit of documentation, then it would be perfect 🚀

sbor23 avatar Nov 07 '23 14:11 sbor23

@sbor23 thanks for testing it! I still need to figure out a couple of things here, I have updated the original messages

mrueg avatar Nov 07 '23 15:11 mrueg

I went ahead with the engine field solution

    - name: example_cel_global_value
      engine: cel
      path: '.counter'
      help: Example of a top-level global value scrape in the json using cel
      valuetype: 'gauge'
      labels:
        environment: "\"beta\"" # static label. Quotes need to be escaped for CEL
        location: "\"planet-\"+.location" # dynamic label. Quotes need to be escaped for CEL

mrueg avatar Nov 16 '23 14:11 mrueg