Skip to content

Commit 8715bc2

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

File tree

1 file changed

+86
-5
lines changed

1 file changed

+86
-5
lines changed

doc/reference/reference_lua/config.rst

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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 specified 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 specified 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 taking into account all configuration sources, including environment variables.
98+
- For a remote instance, ``get()`` takes into account only cluster configuration. This means that environment variables are ignored.
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>`) -- a name of a remote instance whose configuration should be obtained
104+
92105
:return: an instance configuration
93106

94107
**Examples:**
@@ -121,10 +134,18 @@ 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. ``version`` can be one of the following values:
142+
143+
* ``v1`` (default): no additional information in the ``meta`` field
144+
* ``v2``: the ``meta`` field includes two fields:
145+
146+
* the ``active`` field includes information for the last successfully applied configuration
147+
* the ``last`` field includes information about the last loaded configuration
148+
128149
:return: a table containing an instance's state
129150

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

211292
.. method:: reload()

0 commit comments

Comments
 (0)