Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[prometheus-postgres-exporter] Use non default database in multi-targets #5069

Conversation

thomas-may
Copy link
Contributor

@thomas-may thomas-may commented Dec 16, 2024

What this PR does / why we need it

This PR introduces the ability to select the database to connect to in a multi-target configuration and have the servicemonitor correctly scrape databases that do not match username.

The multi-target configuration section is completed with the new optional parameter databaseName as follows:

serviceMonitor:
  enabled: true
   # Use multipleTarget mode
  multipleTarget:
    enabled: true
    targets:
      - endpoint: pg01.local
        name: pg01
      - endpoint: pg02.local
        name: pg02
        databaseName: mydb     # <== New optional parameter for selecting database

This configuration produces the following servicemonitor resource:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
# ... [redacted]
spec:
  endpoints:
  - metricRelabelings:
    # ... [redacted]
    params:
      auth_module:
      - client.pg01
      target:
      - pg01.local:5432
    path: /probe
    port: http
  - metricRelabelings:
    # ... [redacted]
    params:
      auth_module:
      - client.pg02
      target:
      - pg02.local:5432/mydb     # <== Target references the database in its path
    path: /probe
    port: http
  # ... [redacted]

Special notes for your reviewer

The multi-target feature is currently in beta, but such configuration would be needed for any users relying on a Postgres user dedicated to monitoring purposes, without a database matching its name.

Currently, a workaround is to keep the servicemonitor of this chart disabled and define a custom servicemonitor.

Checklist

  • DCO signed
  • Chart Version bumped
  • Title of the PR starts with chart name (e.g. [prometheus-couchdb-exporter])

@thomas-may thomas-may force-pushed the chg/pg_exporter_multitarget_set_db_name branch 2 times, most recently from b2c730a to 556beac Compare December 18, 2024 09:13
Signed-off-by: Thomas BRIEN <thomas.brien1990@gmail.com>
@thomas-may thomas-may force-pushed the chg/pg_exporter_multitarget_set_db_name branch from 904d861 to 71f64f6 Compare December 18, 2024 09:34
@thomas-may thomas-may requested a review from zanhsieh December 18, 2024 09:36
@zanhsieh zanhsieh merged commit de0ad7b into prometheus-community:main Dec 19, 2024
4 checks passed
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.

3 participants