Skip to content

Commit 0a1b4ee

Browse files
Add config.storage_client documentation
This patch adds documentation for the `config.storage_client` module. The module allows one to connect to a remote config.storage cluster and use it as a key-value storage. Examples for working both with Tarantool config.storage server API and Tarantool config.storage client API are provided side by side since they share quite the same API. The examples on connecting to a config.storage instance via iproto has been changed to an example on connecting to multiple config.storage instances using the config.storage client.
1 parent 959c606 commit 0a1b4ee

File tree

3 files changed

+399
-113
lines changed

3 files changed

+399
-113
lines changed
Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,84 @@
1-
net_box = require('net.box')
2-
local conn = net_box.connect('127.0.0.1:4401')
31
local log = require('log')
4-
conn:watch('config.storage:/myapp/config/all', function(key, value)
5-
log.info("Configuration stored by the '/myapp/config/all' key is changed")
6-
end)
2+
config = require('config')
3+
4+
storage_client = config.storage_client.connect({
5+
{
6+
uri = '127.0.0.1:4401',
7+
login = 'sampleuser',
8+
password = '123456',
9+
},
10+
{
11+
uri = '127.0.0.1:4402',
12+
login = 'sampleuser',
13+
password = '123456',
14+
},
15+
{
16+
uri = '127.0.0.1:4403',
17+
login = 'sampleuser',
18+
password = '123456',
19+
},
20+
})
21+
22+
function register_watchers()
23+
storage_client:watch('/myapp/config/all', function(_, revision)
24+
log.info("Configuration stored by the '/myapp/config/all' key is " ..
25+
"changed. New revision number is %d.", revision)
26+
end)
27+
end
28+
29+
register_watchers()
30+
31+
function connect_to_configured_storage()
32+
-- `config.storage.endpoints` configuration section can be
33+
-- passed directly as `connect()` options to connect to the
34+
-- configured config.storage cluster.
35+
local endpoints = config:get('config.storage.endpoints')
36+
local storage_client = config.storage_client.connect(endpoints)
37+
38+
return storage_client
39+
end
40+
41+
function put_config()
42+
local fio = require('fio')
43+
local cluster_config_handle = fio.open('../../source.yaml')
44+
local cluster_config = cluster_config_handle:read()
45+
local response = storage_client:put('/myapp/config/all', cluster_config)
46+
cluster_config_handle:close()
47+
48+
return response
49+
end
50+
51+
function get_config_by_path()
52+
local response = storage_client:get('/myapp/config/all')
53+
54+
return response
55+
end
56+
57+
function get_config_by_prefix()
58+
local response = storage_client:get('/myapp/')
59+
60+
return response
61+
end
62+
63+
function make_txn_request()
64+
-- Execute an atomic request on the config.storage cluster.
65+
local response = storage_client:txn({
66+
predicates = { { 'value', '==', 'v0', '/myapp/config/all' } },
67+
on_success = { { 'put', '/myapp/config/all', 'v1' } },
68+
on_failure = { { 'get', '/myapp/config/all' } }
69+
})
70+
71+
return response
72+
end
73+
74+
function delete_config()
75+
local response = storage_client:delete('/myapp/config/all')
76+
77+
return response
78+
end
79+
80+
function delete_all_configs()
81+
local response = storage_client:delete('/')
82+
83+
return response
84+
end

doc/platform/configuration/configuration_etcd.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ In the example below, the following options are specified:
260260
- ``timeout`` specifies the interval (in seconds) to perform the status check of a configuration storage.
261261
- ``reconnect_after`` specifies how much time to wait (in seconds) before reconnecting to a configuration storage.
262262

263+
You might use :ref:`config.storage_client <config_storage_client_api_reference>` API for connecting and controlling a remote config.storage cluster.
264+
263265
You can find the full example here: `config_storage <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/config_storage>`_.
264266

265267

0 commit comments

Comments
 (0)