pg_exporter: predicate queries feature (WIP)#47
Merged
Conversation
**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 pgsty#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;
eef9d3c to
03465d7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIP:
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_statementsonly if the extension is installed in the current DB.The new syntax is added at query level in the configuration and looks like this: