Skip to content

Add config.storage client and config.storage TTL option #5116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: latest
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,84 @@
net_box = require('net.box')
local conn = net_box.connect('127.0.0.1:4401')
local log = require('log')
conn:watch('config.storage:/myapp/config/all', function(key, value)
log.info("Configuration stored by the '/myapp/config/all' key is changed")
end)
config = require('config')

storage_client = config.storage_client.connect({
{
uri = '127.0.0.1:4401',
login = 'sampleuser',
password = '123456',
},
{
uri = '127.0.0.1:4402',
login = 'sampleuser',
password = '123456',
},
{
uri = '127.0.0.1:4403',
login = 'sampleuser',
password = '123456',
},
})

function register_watchers()
storage_client:watch('/myapp/config/all', function(_, revision)
log.info("Configuration stored by the '/myapp/config/all' key is " ..
"changed. New revision number is %d.", revision)
end)
end

register_watchers()

function connect_to_configured_storage()
-- `config.storage.endpoints` configuration section can be
-- passed directly as `connect()` options to connect to the
-- configured config.storage cluster.
local endpoints = config:get('config.storage.endpoints')
local storage_client = config.storage_client.connect(endpoints)

return storage_client
end

function put_config()
local fio = require('fio')
local cluster_config_handle = fio.open('../../source.yaml', {'O_RDONLY'})
local cluster_config = cluster_config_handle:read()
local response = storage_client:put('/myapp/config/all', cluster_config)
cluster_config_handle:close()

return response
end

function get_config_by_path()
local response = storage_client:get('/myapp/config/all')

return response
end

function get_config_by_prefix()
local response = storage_client:get('/myapp/')

return response
end

function make_txn_request()
-- Execute an atomic request on the config.storage cluster.
local response = storage_client:txn({
predicates = { { 'value', '==', 'v0', '/myapp/config/all' } },
on_success = { { 'put', '/myapp/config/all', 'v1' } },
on_failure = { { 'get', '/myapp/config/all' } }
})

return response
end

function delete_config()
local response = storage_client:delete('/myapp/config/all')

return response
end

function delete_all_configs()
local response = storage_client:delete('/')

return response
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function put_config()
local fio = require('fio')
local cluster_config_handle = fio.open('../../source.yaml')
local cluster_config_handle = fio.open('../../source.yaml', {'O_RDONLY'})
local cluster_config = cluster_config_handle:read()
local response = config.storage.put('/myapp/config/all', cluster_config)
cluster_config_handle:close()
Expand Down
2 changes: 2 additions & 0 deletions doc/platform/configuration/configuration_etcd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ In the example below, the following options are specified:
- ``timeout`` specifies the interval (in seconds) to perform the status check of a configuration storage.
- ``reconnect_after`` specifies how much time to wait (in seconds) before reconnecting to a configuration storage.

You might use :ref:`config.storage_client <config_storage_client_api_reference>` API for connecting and controlling a remote config.storage cluster.

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>`_.


Expand Down
Loading