Respect database config when inserting data (was always using default) #27
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.
Hey team 👋
First off : huge thanks for ClickHouse and kubenetmon maintainers 🙏
Context
In our setup, we’re running a single shared ClickHouse cluster dedicated to kubenetmon.
This cluster is shared across roughly a dozen EKS clusters, and each EKS cluster writes to its own database (one DB per cluster).
This lets us isolate data and manage permissions cleanly : each kubenetmon instance has
INSERTrights only on its own DB.The issue
Currently, even if the
databasefield is set in the configuration, theworker.flush()function always writes to:So all inserts end up in the default database, regardless of what was configured.
In our case, that meant the service tried to write into DBs it didn’t have permissions for, causing errors like:
🧩 This PR in a nutshell
Databasevalue fromClickHouseOptionsinto eachworkerworker.flush()to dynamically use that database instead of hardcodingdefaultSo instead of:
INSERT INTO default.network_flows_0 (...)we now correctly get:
INSERT INTO my_cluster_db.network_flows_0 (...)✅ Result
databaseconfiguration field actually effective (previously ignored?)🛠 Notes
To stay robust, the PR uses
fmt.Sprintffor building the query string.If needed, we could add identifier quoting (backticks) or validation to handle special DB names safely.