Skip to content

Commit d16f367

Browse files
committed
Document new 'config' API
1 parent 0714fe3 commit d16f367

File tree

1 file changed

+91
-10
lines changed

1 file changed

+91
-10
lines changed

doc/reference/reference_lua/config.rst

Lines changed: 91 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Module config
88
The ``config`` module provides the ability to work with an instance's configuration.
99
For example, you can determine whether the current instance is up and running without errors after applying the :ref:`cluster's configuration <configuration_overview>`.
1010

11-
By using the ``config.storage`` :ref:`role <configuration_reference_roles_options>`, you can set up a Tarantool-based :ref:`centralized configuration storage <configuration_etcd>` and interact with this storage using the ``config`` module API.
11+
By using the ``config.storage`` :ref:`role <configuration_application_roles>`, you can set up a Tarantool-based :ref:`centralized configuration storage <configuration_etcd>` and interact with this storage using the ``config`` module API.
1212

1313

1414
.. _config_module_loading:
@@ -46,11 +46,17 @@ API Reference
4646
-
4747

4848
* - :ref:`config:get() <config_api_reference_get>`
49-
- Get a configuration applied to the current instance
49+
- Get a configuration applied to the current or remote instance
5050

5151
* - :ref:`config:info() <config_api_reference_info>`
5252
- Get the current instance's state in regard to configuration
5353

54+
* - :ref:`config:instance_uri() <config_api_reference_instance_uri>`
55+
- Get a URI of the current or remote instance
56+
57+
* - :ref:`config:instances() <config_api_reference_instances>`
58+
- List all instances of the cluster
59+
5460
* - :ref:`config:reload() <config_api_reference_reload>`
5561
- Reload the current instance's configuration
5662

@@ -83,12 +89,19 @@ config API
8389

8490
.. _config_api_reference_get:
8591

86-
.. method:: get([param])
92+
.. method:: get([param, opts])
93+
94+
Get a configuration applied to the current or remote instance.
95+
Note that there is the following difference between getting a configuration for the current and remote instance:
8796

88-
Get a configuration applied to the current instance.
89-
Optionally, you can pass a configuration option name to get its value.
97+
- For the current instance, ``get()`` returns an instance configuration considering :ref:`environment variables <configuration_environment_variable>`.
98+
- For a remote instance, ``get()`` only considers a cluster configuration and ignores environment variables.
9099

91100
:param string param: a configuration option name
101+
:param table opts: options to pass. The following options are available:
102+
103+
- ``instance`` (since :doc:`3.1.0 </release/3.1.0>`) -- the name of a remote instance whose configuration should be obtained
104+
92105
:return: an instance configuration
93106

94107
**Examples:**
@@ -104,7 +117,7 @@ config API
104117
too_long_threshold: 0.5
105118
top:
106119
enabled: false
107-
# other configuration values
120+
# Other configuration values
108121
# ...
109122
110123
This example shows how to get an ``iproto.listen`` option value:
@@ -121,10 +134,19 @@ config API
121134

122135
.. _config_api_reference_info:
123136

124-
.. method:: info()
137+
.. method:: info([version])
125138

126139
Get the current instance's state in regard to configuration.
127140

141+
:param string version: (since :doc:`3.1.0 </release/3.1.0>`) the version of the information that should be returned. The ``version`` argument can be one of the following values:
142+
143+
* ``v1`` (default): the ``meta`` field returned by ``info()`` includes information about the last loaded configuration
144+
* ``v2``: the ``meta`` field returned by ``info()`` includes two fields:
145+
146+
* the ``last`` field includes information about the last loaded configuration
147+
* the ``active`` field includes information for the last successfully applied configuration
148+
149+
128150
:return: a table containing an instance's state
129151

130152
The returned state includes the following sections:
@@ -155,7 +177,7 @@ config API
155177
...
156178
157179
* In the example below, the instance's state is ``check_warnings``.
158-
The ``alerts`` section informs that privileges to the ``books`` space for ``sampleuser`` cannot be granted because the ``books`` space has not created yet:
180+
The ``alerts`` section informs that privileges to the ``books`` space for ``sampleuser`` cannot be granted because the ``books`` space has not been created yet:
159181

160182
.. code-block:: console
161183
@@ -205,6 +227,65 @@ config API
205227
alerts: []
206228
...
207229
230+
.. _config_api_reference_instance_uri:
231+
232+
.. method:: instance_uri([uri_type, opts])
233+
234+
**Since:** :doc:`3.1.0 </release/3.1.0>`
235+
236+
Get a URI of the current or remote instance.
237+
238+
:param string uri_type: a URI type. There are the following URI types are supported:
239+
240+
* ``peer`` -- a URI used to advertise the instance to other cluster members. See also: :ref:`iproto.advertise.peer <configuration_reference_iproto_advertise_peer>`.
241+
* ``sharding`` -- a URI used to advertise the current instance to a router and rebalancer. See also: :ref:`iproto.advertise.sharding <configuration_reference_iproto_advertise_sharding>`.
242+
243+
:param table opts: options to pass. The following options are available:
244+
245+
- ``instance`` -- the name of a remote instance whose URI should be obtained
246+
247+
:return: an instance URI
248+
249+
**Example**
250+
251+
The example below shows how to get a URI used to advertise ``storage-b-003`` to other cluster members:
252+
253+
.. code-block:: lua
254+
255+
local config = require('config')
256+
config:instance_uri('peer', { instance = 'storage-b-003' })
257+
258+
259+
.. _config_api_reference_instances:
260+
261+
.. method:: instances()
262+
263+
**Since:** :doc:`3.1.0 </release/3.1.0>`
264+
265+
List all instances of the cluster.
266+
267+
:return: a table containing information about instances
268+
269+
The returned table uses instance names as the keys and contains the following information for each instance:
270+
271+
- ``instance_name`` -- an instance name
272+
- ``replicaset_name`` -- the name of a replica set the instance belongs to
273+
- ``group_name`` -- the name of a group the instance belongs to
274+
275+
**Example**
276+
277+
The example below shows how to use ``instances()`` to get the names of all instances in the cluster, create a connection to each instance using the :ref:`connpool <connpool_module>` module, and log connection URIs using the :ref:`log <log-module>` module:
278+
279+
.. code-block:: lua
280+
281+
local config = require('config')
282+
for instance_name in pairs(config:instances()) do
283+
local connpool = require('experimental.connpool')
284+
local conn = connpool.connect(instance_name)
285+
local log = require('log')
286+
log.info(string.format("Connection URI for '%s': %s:%s", instance_name, conn.host, conn.port))
287+
end
288+
208289
209290
.. _config_api_reference_reload:
210291

@@ -268,7 +349,7 @@ The ``config.storage`` API allows you to interact with a Tarantool-based :ref:`c
268349
* ``data``: a table containing the information about the value:
269350

270351
* ``path``: a path
271-
* ``mod_revision``: a last revision at which this value was modified
352+
* ``mod_revision``: the last revision at which this value was modified
272353
* ``value:``: a value
273354

274355
* ``revision``: a revision after performing the operation
@@ -308,7 +389,7 @@ The ``config.storage`` API allows you to interact with a Tarantool-based :ref:`c
308389
* ``data``: a table containing the information about the value:
309390

310391
* ``path``: a path
311-
* ``mod_revision``: a last revision at which this value was modified
392+
* ``mod_revision``: the last revision at which this value was modified
312393
* ``value:``: a value
313394

314395
* ``revision``: a revision after performing the operation

0 commit comments

Comments
 (0)