Closed marevers closed 3 weeks ago
@dewey is this something you want to support? It comes in very handy in our case. If so, please let me know. I will rebase so you can merge.
Hey @marevers, I unfortunately don't have much time to put towards this project, so I'm focusing on smaller PRs that I can review without much context. Thanks for pinging me again on this one.
I think it would be valuable to have, could you go ahead and rebase please? Then I'll go ahead and merge it as it sounds like it's working in production for you without negative effects.
@dewey Thanks, we are running this in production now for a while and it works well. Fixed the conflict and formatting.
I've released a new version and the Docker image is pushing right now. Thanks for the contribution!
This PR adds a new function to the exporter which allows you to deal with dynamic database / schema structures. E.g. you have a multi-tenant PostgreSQL database which has multiple schemas. These schemas contain the same tables and you want to run a collection of queries over each relevant schema without knowing them by name.
Under the job configuration, you can add the following:
This will retrieve a list of schemas according to the query specified and then run any query in the job that has the given placeholder (
{{SCHEMA_NAME}}
) in a loop, once for every result of the aforementioned query. Before running the query, the placeholder is replaced by the value retrieved. The value is also added to a Prometheus label configured underiterator.label
to ensure non-duplicate results.It is safe to combine both queries with and without an iterator placeholder in the same job if iterator is specified. Queries without the placeholder will be ran normally.
This is an easier option than using something like dynamic SQL, because it requires no changes to the original query and does not suffer from the performance implications that dynamic SQL can often have.