Skip to content

Commit

Permalink
config: add warnings on skipped URIs
Browse files Browse the repository at this point in the history
There is a function `find_suitable_uri()` that basically looks for a
URI with non-zero address and port. This patch adds logging that should
ensure that it is easy to understand if a URI was skipped and why.
Note that additional logging is disabled by default and happens only
in sharding and replicaset configuration.

Closes #9644

NO_DOC=internal
NO_TEST=hard to test internal logging
  • Loading branch information
Lord-KA authored and Totktonada committed Apr 15, 2024
1 parent 54e9008 commit bc18a05
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
2 changes: 2 additions & 0 deletions changelogs/unreleased/gh-9644-verbose-uri-error.md
Expand Up @@ -2,3 +2,5 @@

* Added a subject URI to the error that is thrown on configuration
verification (gh-9644).
* Added a warning with the skipped (unsuitable) URI to replicaset
and sharding configuration (gh-9644).
3 changes: 2 additions & 1 deletion src/box/lua/config/applier/box_cfg.lua
Expand Up @@ -36,7 +36,8 @@ local function peer_uris(configdata)
-- A user may configure a custom data flow using
-- `replication.peers` option.
if not is_anon then
local uri = instance_config:instance_uri(iconfig_def, 'peer')
local uri = instance_config:instance_uri(iconfig_def, 'peer',
{log_prefix = "replicaset dataflow configuration: "})
if uri == nil then
log.info('%s: instance %q has no iproto.advertise.peer or ' ..
'iproto.listen URI suitable to create a client socket',
Expand Down
8 changes: 5 additions & 3 deletions src/box/lua/config/configdata.lua
Expand Up @@ -70,9 +70,10 @@ function methods.names(self)
}
end

function methods._instance_uri(self, uri_type, opts)
function methods._instance_uri(self, uri_type, opts, log_opts)
assert(uri_type == 'peer' or uri_type == 'sharding')
return instance_config:instance_uri(choose_iconfig(self, opts), uri_type)
return instance_config:instance_uri(choose_iconfig(self, opts), uri_type,
log_opts)
end

-- Generate a part of a vshard configuration that relates to
Expand All @@ -95,7 +96,8 @@ function methods._instance_sharding(self, opts)
return nil
end
local zone = self:get('sharding.zone', opts)
local uri = self:_instance_uri('sharding', opts)
local uri = self:_instance_uri('sharding', opts,
{log_prefix = "sharding configuration: "})
if uri == nil then
local err = 'No suitable URI provided for instance %q'
error(err:format(opts.instance), 0)
Expand Down
36 changes: 23 additions & 13 deletions src/box/lua/config/instance_config.lua
Expand Up @@ -5,6 +5,7 @@ local uuid = require('uuid')
local urilib = require('uri')
local fio = require('fio')
local file = require('internal.config.utils.file')
local log = require('internal.config.utils.log')

-- List of annotations:
--
Expand Down Expand Up @@ -224,20 +225,29 @@ end
--
-- See the uri_is_suitable_to_connect() method in the instance
-- schema object for details.
local function find_suitable_uri_to_connect(listen)
local function find_suitable_uri_to_connect(listen, opts)
local opts = opts or {}
assert(opts.log_prefix == nil or type(opts.log_prefix) == 'string')

for _, u in ipairs(listen) do
assert(u.uri ~= nil)
local uri = urilib.parse(u.uri)
if uri ~= nil and uri_is_suitable_to_connect(uri) then
-- The urilib.format() call has the second optional
-- argument `write_password`. Let's assume that the
-- given URIs are to listen on them and so have no
-- user/password.
--
-- NB: We need to format the URI back to construct the
-- 'uri' field. urilib.parse() creates separate 'host'
-- and 'service'.
return urilib.format(uri), u.params
if uri ~= nil then
local ok, err = uri_is_suitable_to_connect(uri)
if ok then
-- The urilib.format() call has the second optional
-- argument `write_password`. Let's assume that the
-- given URIs are to listen on them and so have no
-- user/password.
--
-- NB: We need to format the URI back to construct the
-- 'uri' field. urilib.parse() creates separate 'host'
-- and 'service'.
return urilib.format(uri), u.params
elseif opts.log_prefix then
log.warn(("%sunsuitable URI %q: %s")
:format(opts.log_prefix, u.uri, err))
end
end
end
return nil
Expand All @@ -264,7 +274,7 @@ local function find_password(self, iconfig, username)
return nil
end

local function instance_uri(self, iconfig, advertise_type)
local function instance_uri(self, iconfig, advertise_type, opts)
assert(advertise_type == 'peer' or advertise_type == 'sharding')

-- An effective value of iproto.advertise.sharding defaults to
Expand All @@ -288,7 +298,7 @@ local function instance_uri(self, iconfig, advertise_type)
return nil
end
uri = table.copy(uri)
uri.uri, uri.params = find_suitable_uri_to_connect(listen)
uri.uri, uri.params = find_suitable_uri_to_connect(listen, opts)
end
-- No URI found for the given instance.
if uri.uri == nil then
Expand Down

0 comments on commit bc18a05

Please sign in to comment.