Best way to store tree JSON structure of some configuration into the KV?

710 views
Skip to first unread message

Igor Spasić

unread,
Mar 25, 2016, 6:53:19 AM3/25/16
to Consul
I have a tree-like configuration structure: N roots, each root has its children and grandchildren (so only 3 levels including the root).

What would be the best way to store this?

+ Using one key per root and storing all the root tree as json object
+ Using key per 1-level children - and storing all grandchildren as json
+ or storing each grand children per key

In other words:

+ /foo {json}
+ /foo/bar {json}
+ /foo/bar/zar {json}

This is configuration, so querying is important.

Roman Rusakov

unread,
Mar 25, 2016, 7:12:40 AM3/25/16
to Consul
Hello Igor,

We maybe use something similar to your configuration.
it may be not the answer you want but we store it like so:
main configuration is in git in json (could have nested KV inside)
push it to consul KV with great module git2consul - https://github.com/Cimpress-MCP/git2consul
so in consul KV we have nice tree view of all our settings but in git we have human readable and the more important easy to edit json configuration files.
from the other side we use python consul lib + jsonmerge to have ability to override some default settings on the lower level.
about 10-20 lines of code to compile json back from KV on client side if needed
Also tree KV structure could easily be using with consul-template or whatever without any additional scripting.
But you will need some script to parse json if you will store it in value.

Hope this helps
Thanks,
Roman


пятница, 25 марта 2016 г., 11:53:19 UTC+1 пользователь Igor Spasić написал:
Reply all
Reply to author
Forward
0 new messages