Skip to content
Snippets Groups Projects
Commit 30a9c1ca authored by Alexander Turenko's avatar Alexander Turenko Committed by Vladimir Davydov
Browse files

config: access config of other cluster members

Fixes #9680

@TarantoolBot document
Title: config: access configuration of other cluster members

## `config:instances()`

List all instances of the cluster.

Returns a table of the following format.

```lua
{
    [<instance_name>] = {
        instance_name = <...>,
        replicaset_name = <...>,
        group_name = <...>,
    },
    <...>
}
```

If an action should be performed for each instance of the given cluster,
it can be written this way:

```lua
for instance_name in pairs(config:instances()) do
    action(instance_name)
end
```

If replicaset/group names matter, the instances may be filtered this
way:

```lua
-- Perform an action for all instances of the given replicaset.
for instance_name, def in pairs(config:instances()) do
    if def.replicaset_name == box.info.replicaset.name then
        action(instance_name)
    end
end
```

## `config:get(<...>, {instance = '<...>'})`

The new `instance` option of the `config:get()` method allows to
retrieve a configuration value of another instance from the given
cluster.

Example:

```lua
-- Collect all the enabled roles within the cluster.
local enabled_roles = {}
for instance_name in pairs(config:instances()) do
    local roles = config:get('roles', {instance = instance_name})
    for _, role in ipairs(roles) do
        enabled_roles[role] = true
    end
end
```

Note: There is a difference between a missing `instance` option and the
`instance` option that is equal to the given instance name. The former
returns an instance configuration taking into account instance
configuration sources (environment variables). The latter takes into
account only cluster configuration, so the environment variables are
ignored.
parent 0502a1f5
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment