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

pg_exporter: predicate queries feature (WIP) #47

Merged
merged 2 commits into from
Jun 19, 2024

Conversation

ringerc
Copy link
Collaborator

@ringerc ringerc commented Jun 17, 2024

WIP:

  • has a TODO about adding name of failing predicate query to metric set
  • defines the TTL field but does not implement it
  • lacks test cover

Add "predicate queries" to decide whether a given metric query should be scraped at runtime. Implements #41

These can be used to express complex conditions that may change over time, such as "collect this metric set if the foo extension is installed and is at least version 2.1", "collect this metric only when running on (some specific vendor postgres flavour)" or "only try to collect this if this specific table exists and has this specific column".

This helps with maintaining a single configuration to support multiple postgres versions, vendor flavours, access privilege levels, installed extensions and extension versions, etc. E.g. you can selectively query pg_stat_statements only if the extension is installed in the current DB.

The new syntax is added at query level in the configuration and looks like this:

  rowcount_in_foo_table:
    predicate_queries:
      - name: foo_table exists
        predicate_query: |
          SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'foo')
    query: |
      SELECT count(1) FROM public.foo;

@ringerc ringerc marked this pull request as draft June 17, 2024 23:10
**WIP**:

* has a TODO about adding name of failing predicate query to metric set
* defines the TTL field but does not implement it
* lacks test cover

Add "predicate queries" to decide whether a given metric query should
be scraped at runtime. Fixes Vonng#41.

These can be used to express complex conditions that may change over
time, such as "collect this metric set if the foo extension is installed
and is at least version 2.1", "collect this metric only when running on
(some specific vendor postgres flavour)" or "only try to collect this if
this specific table exists and has this specific column".

This helps with maintaining a single configuration to support multiple
postgres versions, vendor flavours, access privilege levels, installed
extensions and extension versions, etc. E.g. you can selectively query
`pg_stat_statements` only if the extension is installed in the current
DB.

The new syntax is added at query level in the configuration and looks
like this:

  rowcount_in_foo_table:
    predicate_queries:
      - name: foo_table exists
        predicate_query: |
          SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'foo')
    query: |
      SELECT count(1) FROM public.foo;
@Vonng Vonng marked this pull request as ready for review June 19, 2024 03:20
@Vonng Vonng merged commit 1973832 into Vonng:master Jun 19, 2024
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.

None yet

2 participants