Use environment variables in SQL queries #1032
|
Hi! Is it possible to use a secret from Vault in an SQL query? In this usage, it is as if the value is not resolved, but substituted as it is. At the same time, it works in the jobs section as a login and password for DSN |
Replies: 1 comment 2 replies
|
Hey @ScareCrowZV, it's not possible to expand env variables in the query field for the time being. It's only applied to the connection strings (have a look: link). Currently, queries must be defined because there’s no dynamic preprocessing involved; they’re simply passed through. What's currently possible and might potentially work for you is the following composition:
This approach allows for sufficient flexibility, but also makes users responsible for necessary data retrieval (security, integrity and relevance). Give it a try. 👍 Overall, I try to avoid adding additional pre-processing and dealing with external systems to the utility, as it immediately affects the performance on scale and requires extra handling to be done. Having said that, I have some feature in mind that should enable histogram metrics, and to avoid writing unpleasant queries I want to introduce a limited set of macro functions. Looking up the env variable might be a thing too. I don't want unexpected automatic env expansion in the queries, but explicitly requested ones feel better to me. I don't have ETA for that yet. I'd appreciate if you could also describe your use case if you may. 👍 |
Hey @ScareCrowZV, it's not possible to expand env variables in the query field for the time being. It's only applied to the connection strings (have a look: link).
Currently, queries must be defined because there’s no dynamic preprocessing involved; they’re simply passed through.
What's currently possible and might potentially work for you is the following composition:
sql_exporter relies upon
sql_exporter.ymland provided collector files (they might be external files too);a user prepares a simple configuration generator in their favourite language that populates a collector file (with queries, etc) fetching data from user-known locations (e.g. vault, s3, local filesystem, etc);
up…