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.
Showing
- changelogs/unreleased/config-retrieve-cluster-config.md 4 additions, 0 deletionschangelogs/unreleased/config-retrieve-cluster-config.md
- src/box/lua/config/applier/box_cfg.lua 1 addition, 1 deletionsrc/box/lua/config/applier/box_cfg.lua
- src/box/lua/config/configdata.lua 109 additions, 59 deletionssrc/box/lua/config/configdata.lua
- src/box/lua/config/init.lua 74 additions, 6 deletionssrc/box/lua/config/init.lua
- test/config-luatest/cluster_config_test.lua 151 additions, 0 deletionstest/config-luatest/cluster_config_test.lua
- test/config-luatest/vars_test.lua 2 additions, 1 deletiontest/config-luatest/vars_test.lua
Loading
Please register or sign in to comment