raffis / mongodb-query-exporter

Prometheus MongoDB aggregation query exporter
MIT License
95 stars 27 forks source link

feat: dry config with yaml achors, env variable expansion and jmespath querying #274

Open lukasmrtvy opened 4 months ago

lukasmrtvy commented 4 months ago

Hi, usage for more than MongoDB is quite tricky ( especially when it comes to Production, Staging, etc databases, these are usually using the same pipeline ), hence my proposal. Thanks

  1. jmespath support for servers section
  2. env variable support in yaml config
  3. anchors support in yaml config

Related: https://github.com/raffis/mongodb-query-exporter/issues/161 https://github.com/raffis/mongodb-query-exporter/issues/60

1. and 2.

servers:
- name: staging
   uri: mongodb://localhost-staging:${STAGING_PASSWORD}:27017
   database: staging
   collection: my coll
- name: production
   uri: mongodb://localhost-production:${PRODUCTION_PASSWORD}:27017
   database: production
   collection: mycoll
aggregations:
- database: $servers[].database
  collection: $servers[].collection
  servers: [$servers[].name] 
  metrics:
  - name: myapp_example_simplevalue_total
     ... 
  pipeline: |
    [
      {"$count":"total"}
    ]

3.

x-pipeline: &pipeline |
    [
      {"$count":"total"}
    ]

servers:
- name: staging
  uri: mongodb://localhost-staging:${STAGING_PASSWORD}:27017
- name: production
  uri: mongodb://localhost-production:${PRODUCTION_PASSWORD}:27017
aggregations:
- database: staging
  collection: mycoll
  servers: [staging] 
  metrics:
  - name: myapp_example_simplevalue_total
     ... 
  pipeline: |
    <<: *pipeline
- database: production
  collection: mycoll
  servers: [production] 
  metrics:
  - name: myapp_example_simplevalue_total
     ... 
  pipeline: |
    <<: *pipeline