Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Olga Arkhangelskaia <arkholga@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: Re: [tarantool-patches] [PATCH v2 1/2] Fixed non-informative error messages for log conf.
Date: Wed, 1 Aug 2018 15:32:34 +0300	[thread overview]
Message-ID: <20180801123234.fspyefhh4zovu54x@esperanza> (raw)
In-Reply-To: <20180801110710.10292-2-arkholga@tarantool.org>

On Wed, Aug 01, 2018 at 02:07:09PM +0300, Olga Arkhangelskaia wrote:
> In case of bad or erroneous options for log configurations
> errors had ambiguous or absent messages. In some cases it lead to
> app crashes.
> 
> Closes #3553
> ---
>  src/box/box.cc            | 66 ++++++++++++++++++++++++++++++-----------------
>  src/say.c                 |  5 ++--
>  test/box-tap/cfg.test.lua |  2 +-
>  3 files changed, 46 insertions(+), 27 deletions(-)

We don't submit tests separately. Please squash patch 2 in this patch.

> 
> diff --git a/src/box/box.cc b/src/box/box.cc
> index 62fd05468..dc607c1ae 100644
> --- a/src/box/box.cc
> +++ b/src/box/box.cc
> @@ -351,17 +351,41 @@ apply_initial_join_row(struct xstream *stream, struct xrow_header *row)
>  
>  /* {{{ configuration bindings */
>  
> +static enum say_format
> +box_check_log_format(const char *log_format)
> +{
> +	enum say_format format = say_format_by_name(log_format);
> +	if (format == say_format_MAX)
> +		tnt_raise(ClientError, ER_CFG, "log_format",
> +			 "expected 'plain' or 'json'");
> +	return format;
> +}
> +
>  static void
> -box_check_say()
> +box_check_format_compatibility(enum say_format format, enum say_logger_type type)

Bad name: what 'format'? tuple format, space format?

>  {
> -	const char *log = cfg_gets("log");
> -	if (log == NULL)
> -		return;
> -	enum say_logger_type type;
> -	if (say_parse_logger_type(&log, &type) < 0) {
> +	if (type == SAY_LOGGER_SYSLOG && format == SF_JSON) {
> +		tnt_raise(ClientError, ER_CFG, "log_format",
> +			  "'json' can't be used with syslog logger");
> +	}
> +}
> +
> +static enum say_logger_type
> +box_check_logger_type(const char **log)

I don't like this function. Its semantics is quite different from other
cfg-related helpers: it modifies the input argument. I don't think
that you really need it. See my comment to box_set_log_format() below.

> +{
> +	enum say_logger_type type = SAY_LOGGER_STDERR;
> +	if (*log != NULL && say_parse_logger_type(log, &type) < 0) {
>  		tnt_raise(ClientError, ER_CFG, "log",
>  			  diag_last_error(diag_get())->errmsg);
>  	}
> +	return type;
> +}
> +
> +static void
> +box_check_say()
> +{
> +	const char *log = cfg_gets("log");
> +	enum say_logger_type type = box_check_logger_type(&log);
>  
>  	if (type == SAY_LOGGER_SYSLOG) {
>  		struct say_syslog_opts opts;
> @@ -377,27 +401,18 @@ box_check_say()
>  	}
>  
>  	const char *log_format = cfg_gets("log_format");
> -	enum say_format format = say_format_by_name(log_format);
> -	if (format == say_format_MAX)
> -		diag_set(ClientError, ER_CFG, "log_format",
> -			 "expected 'plain' or 'json'");
> -	if (type == SAY_LOGGER_SYSLOG && format == SF_JSON) {
> -		tnt_raise(ClientError, ER_ILLEGAL_PARAMS, "log, log_format");
> -	}
> +	enum say_format format = box_check_log_format(log_format);
> +	box_check_format_compatibility(format, type);
> +
>  	int log_nonblock = cfg_getb("log_nonblock");
>  	if (log_nonblock == 1 && type == SAY_LOGGER_FILE) {
> -		tnt_raise(ClientError, ER_ILLEGAL_PARAMS, "log, log_nonblock");
> +		tnt_raise(ClientError, ER_CFG, "log_nonblock",
> +			  "true' can't be used with file logger type");

A single quite (') before "true" is missing.

> +	}
> +	if (log_nonblock == 1 && type == SAY_LOGGER_STDERR) {
> +		tnt_raise(ClientError, ER_CFG, "log_nonblock",
> +			  "'true' can't be used with stderr logger type");

"'true' can't be used with stderr logger type" sounds strange...

Besides, I don't think it's worth differentiating between stderr and
file logger in this case. Why not rewrite it like below?

	if (log_nonblock && (type == SAY_LOGGER_STDERR ||
			     type == SAY_LOGGER_FILE)) {
		tnt_raise(ClientError, ER_CFG, "log_nonblock",
			  "the option is incompatible with file/stderr logger")

>  	}
> -}
> -
> -static enum say_format
> -box_check_log_format(const char *log_format)
> -{
> -	enum say_format format = say_format_by_name(log_format);
> -	if (format == say_format_MAX)
> -		tnt_raise(ClientError, ER_CFG, "log_format",
> -			  "expected 'plain' or 'json'");
> -	return format;
>  }
>  
>  static void
> @@ -745,7 +760,10 @@ box_set_log_level(void)
>  void
>  box_set_log_format(void)
>  {
> +	const char *log = cfg_gets("log");
>  	enum say_format format = box_check_log_format(cfg_gets("log_format"));
> +	static enum say_logger_type type = box_check_logger_type(&log);

When we chatted, we agreed that using box_check_say() for checking
logger format in box_set_log_format() may be not good, because the user
can overwrite box.cfg.log so that cfg_gets() would return NULL even
though the logger type can be in fact set to syslog. Actually, that was
the only reason not to use box_check_say() here.

However, you still call cfg_gets("log") here, which is no better than
simply calling box_check_say(), just costs us more code. I thought you'd
inquire the configured logger type from say.c. Please either do that or
call box_check_say().

If you choose to get the logger type from say.c, you don't need
box_check_logger_type() and box_check_format_compatibility().
The former can be inlined in box_check_say() as it used to be.
The latter can be inlined in box_check_format() - you just need
to add 'type' parameter to that function.

> +	box_check_format_compatibility(format, type);
>  	say_set_log_format(format);

say_set_log_format() has a log of code that becomes dead after
this patch. Please remove it. That function should simply call
log_set_format() on log_default and update log_format variable.

>  }
>  
> diff --git a/src/say.c b/src/say.c
> index ac221dd19..01a0d150d 100644
> --- a/src/say.c
> +++ b/src/say.c
> @@ -541,7 +541,6 @@ log_create(struct log *log, const char *init_str, int nonblock)
>  	if (init_str != NULL) {
>  		enum say_logger_type type;
>  		if (say_parse_logger_type(&init_str, &type)) {
> -			diag_set(IllegalParams, logger_syntax_reminder);
>  			return -1;
>  		}
>  		int rc;
> @@ -989,8 +988,10 @@ say_parse_logger_type(const char **str, enum say_logger_type *type)
>  		*type = SAY_LOGGER_SYSLOG;
>  	else if (strchr(*str, ':') == NULL)
>  		*type = SAY_LOGGER_FILE;
> -	else
> +	else {
> +		diag_set(IllegalParams, logger_syntax_reminder);
>  		return -1;
> +	}
>  	return 0;
>  }
>  
> diff --git a/test/box-tap/cfg.test.lua b/test/box-tap/cfg.test.lua
> index ffafdbe42..ea6f4d646 100755
> --- a/test/box-tap/cfg.test.lua
> +++ b/test/box-tap/cfg.test.lua
> @@ -51,7 +51,7 @@ invalid('vinyl_bloom_fpr', 1.1)
>  
>  local function invalid_combinations(name, val)
>      local status, result = pcall(box.cfg, val)
> -    test:ok(not status and result:match('Illegal'), 'invalid '..name)
> +    test:ok(not status and result:match('Incorrect'), 'incompatible values'..name)

I see why you need to change 'Illegal' to 'Incorrect', but
why change 'invalid ' to 'incompatible values'? Please don't:
'invalid log_format' looks better than 'incompatible valueslog_format'
(yeah, the space is missing).

  reply	other threads:[~2018-08-01 12:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-01 11:07 [tarantool-patches] [PATCH v2 0/2] logger non inf error Olga Arkhangelskaia
2018-08-01 11:07 ` [tarantool-patches] [PATCH v2 1/2] Fixed non-informative error messages for log conf Olga Arkhangelskaia
2018-08-01 12:32   ` Vladimir Davydov [this message]
2018-08-01 11:07 ` [tarantool-patches] [PATCH v2 2/2] box-tap: test to check logger invalid config Olga Arkhangelskaia
2018-08-01 12:39   ` Vladimir Davydov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180801123234.fspyefhh4zovu54x@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=arkholga@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH v2 1/2] Fixed non-informative error messages for log conf.' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox