Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH 0/3] Syslog destination
@ 2018-07-13 10:29 Olga Arkhangelskaia
  2018-07-13 10:29 ` [tarantool-patches] [PATCH 1/3] Configurable syslog destination Olga Arkhangelskaia
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Olga Arkhangelskaia @ 2018-07-13 10:29 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Olga Arkhangelskaia

This series adds support of configurable destionation for syslog.
The option is called server. Possible options are ip4 and unix socket:
syslog:server=unix:/path/to/socket,identity=myinstance
syslog:server=ip4:port,identity=tarantool_myinstance

If server option is not set, but syslog is used in log configuration - 
default sockets for syslogd are used: /dev/log or /var/run/syslog.

This series is upon fix #3205. That will be slightly changed later.

Closes #3487

--OKriw/gh-3487-syslog-conf-dest

Olga Arkhangelskaia (3):
  Configurable syslog destination
  Syslog remote destination test
  Syslog destination test unix socket

 src/say.c                           | 76 +++++++++++++++++++++++++++++++++----
 src/say.h                           |  7 ++++
 test/app-tap/syslog_remote.test.lua | 33 ++++++++++++++++
 test/app-tap/syslog_socket.test.lua | 33 ++++++++++++++++
 4 files changed, 141 insertions(+), 8 deletions(-)
 create mode 100755 test/app-tap/syslog_remote.test.lua
 create mode 100755 test/app-tap/syslog_socket.test.lua

-- 
2.14.3 (Apple Git-98)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tarantool-patches] [PATCH 1/3] Configurable syslog destination
  2018-07-13 10:29 [tarantool-patches] [PATCH 0/3] Syslog destination Olga Arkhangelskaia
@ 2018-07-13 10:29 ` Olga Arkhangelskaia
  2018-07-13 13:12   ` Vladimir Davydov
  2018-07-13 10:29 ` [tarantool-patches] [PATCH 2/3] Syslog remote destination test Olga Arkhangelskaia
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Olga Arkhangelskaia @ 2018-07-13 10:29 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Olga Arkhangelskaia

Added server option to syslog configuration.
Server option is responsible for log destination. At the momemt
there is two ways of usage:server=unix:/path/to/socket or
server=ipv4:port. If port is not set default udp port 514 is used.
If logging to syslog is set, however there is no sever options -
default location is used: Linux /dev/log and Mac /var/run/syslog.

Signed-off-by: Olga Arkhangelskaia <arkholga@tarantool.org>
---
 src/say.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 src/say.h |  7 ++++++
 2 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/src/say.c b/src/say.c
index 43124083c..aa820175c 100644
--- a/src/say.c
+++ b/src/say.c
@@ -451,7 +451,7 @@ log_file_init(struct log *log, const char *init_str)
 }
 
 /**
- * Connect to syslogd using UNIX socket.
+ * Connect to UNIX socket.
  * @param path UNIX socket path.
  * @retval not 0 Socket descriptor.
  * @retval    -1 Socket error.
@@ -473,16 +473,50 @@ syslog_connect_unix(const char *path)
 	return fd;
 }
 
+/**
+ * Connect to remote syslogd using server:port.
+ * @param ip:port pair.
+ * @retval not 0 Socket descriptor.
+ * @retval    -1 Socket error.
+ */
+static int
+syslog_connect_remote(const char *remote, const char *portnum)
+{
+	/* IPv4 */
+	struct sockaddr_in in;
+	in_addr_t addr = inet_addr(remote);
+	int fd = socket(AF_INET, SOCK_DGRAM, 0);
+	if (fd < 0)
+		return -1;
+	memset(&in, 0, sizeof(in));
+	in.sin_family = AF_INET;
+	in.sin_port = htons(atoi(portnum));
+	in.sin_addr.s_addr = addr;
+	if (connect(fd, (struct sockaddr *) &in, sizeof(in)) != 0) {
+		close(fd);
+		return -1;
+	}
+	return fd;
+}
+
 static inline int
 log_syslog_connect(struct log *log)
 {
+
 	/*
-	 * Try two locations: '/dev/log' for Linux and
+	 * If server option is not se use '/dev/log' for Linux and
 	 * '/var/run/syslog' for Mac.
 	 */
-	log->fd = syslog_connect_unix("/dev/log");
-	if (log->fd < 0)
-		log->fd = syslog_connect_unix("/var/run/syslog");
+	if (strncmp(log->addr_type, "default", sizeof("default")) == 0) {
+		log->fd = syslog_connect_unix("/dev/log");
+			if (log->fd < 0)
+				log->fd = syslog_connect_unix("/var/run/syslog");
+	} else if (strncmp(log->addr_type, "unix", sizeof("unix")) == 0) {
+		log->fd = syslog_connect_unix(log->addr_path);
+	} else {
+		log->fd = syslog_connect_remote(log->addr_type,
+				                log->addr_path);
+	}
 	return log->fd;
 }
 
@@ -498,6 +532,14 @@ log_syslog_init(struct log *log, const char *init_str)
 	if (say_parse_syslog_opts(init_str, &opts) < 0)
 		return -1;
 
+	if (opts.addr_type == NULL &&
+	    opts.addr_path == NULL) {
+		log->addr_type = strdup("default");
+	} else {
+		log->addr_type = strdup(opts.addr_type);
+		log->addr_path = strdup(opts.addr_path);
+	}
+
 	if (opts.identity == NULL)
 		log->syslog_ident = strdup("tarantool");
 	else
@@ -1044,6 +1086,8 @@ say_syslog_facility_by_name(const char *facility)
 int
 say_parse_syslog_opts(const char *init_str, struct say_syslog_opts *opts)
 {
+	opts->addr_type = NULL;
+	opts->addr_path = NULL;
 	opts->identity = NULL;
 	opts->facility = syslog_facility_MAX;
 	opts->copy = strdup(init_str);
@@ -1051,8 +1095,9 @@ say_parse_syslog_opts(const char *init_str, struct say_syslog_opts *opts)
 		diag_set(OutOfMemory, strlen(init_str), "malloc", "opts->copy");
 		return -1;
 	}
-	char *ptr = opts->copy;
-	const char *option, *value;
+	char *ptr = opts->copy; 
+	const char *option, *value, *srv_str;
+	char *srv_ptr, *srv_opt;
 
 	/* strsep() overwrites the separator with '\0' */
 	while ((option = strsep(&ptr, ","))) {
@@ -1060,7 +1105,22 @@ say_parse_syslog_opts(const char *init_str, struct say_syslog_opts *opts)
 			break;
 
 		value = option;
-		if (say_parse_prefix(&value, "identity=")) {
+		srv_str = say_parse_prefix(&value, "server=");
+		if (srv_str != NULL) {
+			if (opts->addr_path != NULL ||
+			    opts->addr_type != NULL)
+				goto duplicate;
+			if (say_parse_prefix(&srv_str, "unix:")) {
+				opts->addr_type = strdup("unix");
+				opts->addr_path = srv_str;
+			} else {
+				srv_ptr = strdup(srv_str);
+				srv_opt = srv_ptr;
+				opts->addr_type = strsep(&srv_ptr,":");
+				opts->addr_path = srv_ptr;
+				free(srv_opt);
+			}
+		} else if (say_parse_prefix(&value, "identity=")) {
 			if (opts->identity != NULL)
 				goto duplicate;
 			opts->identity = value;
diff --git a/src/say.h b/src/say.h
index ad3ba3417..6bee2cc90 100644
--- a/src/say.h
+++ b/src/say.h
@@ -162,6 +162,11 @@ struct log {
 	int rotating_threads;
 	enum syslog_facility syslog_facility;
 	struct rlist in_log_list;
+	/* Server options. Either ip/port pair or unix socket address.*/
+	struct {
+		char *addr_type;
+		char *addr_path;
+	};
 };
 
 /**
@@ -390,6 +395,8 @@ say_parse_logger_type(const char **str, enum say_logger_type *type);
 
 /** Syslog logger initialization params */
 struct say_syslog_opts {
+	const char *addr_type;
+	const char *addr_path;
 	const char *identity;
 	enum syslog_facility facility;
 	/* Input copy (content unspecified). */
-- 
2.14.3 (Apple Git-98)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tarantool-patches] [PATCH 2/3] Syslog remote destination test
  2018-07-13 10:29 [tarantool-patches] [PATCH 0/3] Syslog destination Olga Arkhangelskaia
  2018-07-13 10:29 ` [tarantool-patches] [PATCH 1/3] Configurable syslog destination Olga Arkhangelskaia
@ 2018-07-13 10:29 ` Olga Arkhangelskaia
  2018-07-13 13:27   ` Vladimir Davydov
  2018-07-13 10:29 ` [tarantool-patches] [PATCH 3/3] Syslog destination test unix socket Olga Arkhangelskaia
  2018-07-13 12:42 ` [tarantool-patches] [PATCH 0/3] Syslog destination Vladimir Davydov
  3 siblings, 1 reply; 8+ messages in thread
From: Olga Arkhangelskaia @ 2018-07-13 10:29 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Olga Arkhangelskaia

Adds syslog remote destination test in app-tap.
Test creates server, sets appropriate log level and redirects logs to it.
If log level received by the server is the same - test passes.

Usage: test-run.py syslog

Signed-off-by: Olga Arkhangelskaia <arkholga@tarantool.org>
---
 test/app-tap/syslog_remote.test.lua | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100755 test/app-tap/syslog_remote.test.lua

diff --git a/test/app-tap/syslog_remote.test.lua b/test/app-tap/syslog_remote.test.lua
new file mode 100755
index 000000000..c7bb773fa
--- /dev/null
+++ b/test/app-tap/syslog_remote.test.lua
@@ -0,0 +1,33 @@
+#!/usr/bin/env tarantool
+
+local tap = require('tap')
+local socket = require('socket')
+local os = require('os')
+local test = tap.test("syslog_remote")
+
+test:plan(1)
+local addr = '127.0.0.1'
+local port = 8888
+
+local function start_server()
+	test:diag("Starting server")
+	local server = socket.tcp_server(addr, port, function() end)
+
+	local sc = socket('AF_INET', 'SOCK_DGRAM', 'udp')
+	sc:bind('127.0.0.1', 8888)
+	return server, sc
+end
+
+local function find_log_level()
+	local opt = 'syslog:server='..addr..':'..port..',identity=tarantool'
+	box.cfg{log = opt, log_level = 7}
+	local buf = sc:read(300)
+	test:ok(buf:match('log level 7'))
+end
+
+server,sc = start_server()
+
+test:test('syslog_remote',find_log_level(test))
+sc:close()
+server:shutdown()
+os.exit(test:check() == true)
-- 
2.14.3 (Apple Git-98)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tarantool-patches] [PATCH 3/3] Syslog destination test unix socket
  2018-07-13 10:29 [tarantool-patches] [PATCH 0/3] Syslog destination Olga Arkhangelskaia
  2018-07-13 10:29 ` [tarantool-patches] [PATCH 1/3] Configurable syslog destination Olga Arkhangelskaia
  2018-07-13 10:29 ` [tarantool-patches] [PATCH 2/3] Syslog remote destination test Olga Arkhangelskaia
@ 2018-07-13 10:29 ` Olga Arkhangelskaia
  2018-07-13 13:34   ` Vladimir Davydov
  2018-07-13 12:42 ` [tarantool-patches] [PATCH 0/3] Syslog destination Vladimir Davydov
  3 siblings, 1 reply; 8+ messages in thread
From: Olga Arkhangelskaia @ 2018-07-13 10:29 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Olga Arkhangelskaia

Adds syslog destination unix test in app-tap.
Test redirects logs to newly created unix socket and sets appropriate
log level. If log receives the same level - test passes.
Usage: test-run.py syslog

Signed-off-by: Olga Arkhangelskaia <arkholga@tarantool.org>
---
 test/app-tap/syslog_socket.test.lua | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100755 test/app-tap/syslog_socket.test.lua

diff --git a/test/app-tap/syslog_socket.test.lua b/test/app-tap/syslog_socket.test.lua
new file mode 100755
index 000000000..bc65ffd5e
--- /dev/null
+++ b/test/app-tap/syslog_socket.test.lua
@@ -0,0 +1,33 @@
+#!/usr/bin/env tarantool
+
+local tap = require('tap')
+local socket = require('socket')
+local os = require('os')
+local test = tap.test("syslog_unix")
+
+test:plan(1)
+local function start_server(test, sock_addr)
+    test:diag("Create unix socket")
+    local destination = 'unix:'.. sock_addr
+    local unix_socket = socket('AF_UNIX', 'SOCK_DGRAM',0)
+    unix_socket:bind('unix/', sock_addr)
+    socket.tcp_connect('unix', sock_addr)
+    unix_socket:listen()
+    return unix_socket, destination
+end
+
+local function find_log_level (test, socket, destination)
+	local buf
+	local opt = 'syslog:server='..destination..',identity=tarantool'
+	box.cfg{log = opt, log_level = 7}
+	buf = socket:read(300)
+	test:ok(buf:match('log level 7'))
+end
+
+path = '/tmp/syslog_test.sock'
+sock, dst = start_server(test, path)
+
+test:test('syslog_unix',find_log_level(test, sock, dst))
+sock:close()
+os.remove(path)
+os.exit(test:check() == true)
-- 
2.14.3 (Apple Git-98)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [tarantool-patches] [PATCH 0/3] Syslog destination
  2018-07-13 10:29 [tarantool-patches] [PATCH 0/3] Syslog destination Olga Arkhangelskaia
                   ` (2 preceding siblings ...)
  2018-07-13 10:29 ` [tarantool-patches] [PATCH 3/3] Syslog destination test unix socket Olga Arkhangelskaia
@ 2018-07-13 12:42 ` Vladimir Davydov
  3 siblings, 0 replies; 8+ messages in thread
From: Vladimir Davydov @ 2018-07-13 12:42 UTC (permalink / raw)
  To: Olga Arkhangelskaia; +Cc: tarantool-patches

On Fri, Jul 13, 2018 at 01:29:35PM +0300, Olga Arkhangelskaia wrote:
> This series adds support of configurable destionation for syslog.
> The option is called server. Possible options are ip4 and unix socket:
> syslog:server=unix:/path/to/socket,identity=myinstance
> syslog:server=ip4:port,identity=tarantool_myinstance
> 
> If server option is not set, but syslog is used in log configuration - 
> default sockets for syslogd are used: /dev/log or /var/run/syslog.
> 
> This series is upon fix #3205. That will be slightly changed later.
> 
> Closes #3487
> 
> --OKriw/gh-3487-syslog-conf-dest

Please put hyperlinks to both the branch and the issue in the cover
letter (or in the patch after --- if there's none). In your case it
would be:

https://github.com/tarantool/tarantool/issues/3487
https://github.com/tarantool/tarantool/commits/OKriw/gh-3487-syslog-conf-dest

BTW app-tap/syslog_remote.test.lua fails on Travis:

https://travis-ci.org/tarantool/tarantool/jobs/403493458
https://travis-ci.org/tarantool/tarantool/builds/403493456?utm_source=github_status&utm_medium=notification

Please fix.

Also, please add the email you use for committing patches to your GitHub
profile so that your commits are authored correctly in GitHub.

> 
> Olga Arkhangelskaia (3):
>   Configurable syslog destination

We typically prefix the subjet line with the subsystem name, in your
case it would be 'say: '.

>   Syslog remote destination test
>   Syslog destination test unix socket

In this particular case, it isn't worth submitting tests separately.
Please fold them in the main patch.

> 
>  src/say.c                           | 76 +++++++++++++++++++++++++++++++++----
>  src/say.h                           |  7 ++++
>  test/app-tap/syslog_remote.test.lua | 33 ++++++++++++++++
>  test/app-tap/syslog_socket.test.lua | 33 ++++++++++++++++
>  4 files changed, 141 insertions(+), 8 deletions(-)
>  create mode 100755 test/app-tap/syslog_remote.test.lua
>  create mode 100755 test/app-tap/syslog_socket.test.lua

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [tarantool-patches] [PATCH 1/3] Configurable syslog destination
  2018-07-13 10:29 ` [tarantool-patches] [PATCH 1/3] Configurable syslog destination Olga Arkhangelskaia
@ 2018-07-13 13:12   ` Vladimir Davydov
  0 siblings, 0 replies; 8+ messages in thread
From: Vladimir Davydov @ 2018-07-13 13:12 UTC (permalink / raw)
  To: Olga Arkhangelskaia; +Cc: tarantool-patches

On Fri, Jul 13, 2018 at 01:29:36PM +0300, Olga Arkhangelskaia wrote:
> Added server option to syslog configuration.
> Server option is responsible for log destination. At the momemt
> there is two ways of usage:server=unix:/path/to/socket or
> server=ipv4:port. If port is not set default udp port 514 is used.
> If logging to syslog is set, however there is no sever options -
> default location is used: Linux /dev/log and Mac /var/run/syslog.
> 
> Signed-off-by: Olga Arkhangelskaia <arkholga@tarantool.org>

We don't sign off patches. Please fix your git config.

And we do add a reference to the related GitHub ticket to the commit
message, e.g.

Closes #3487
Needed for #3487
Part of #3487
Follow-up #3487

For more information on preparing and submitting patches, please read:

https://tarantool.io/en/doc/1.9/dev_guide/developer_guidelines/#how-to-write-a-commit-message
https://tarantool.io/en/doc/1.9/dev_guide/developer_guidelines/#how-to-submit-a-patch-for-review

> ---
>  src/say.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
>  src/say.h |  7 ++++++
>  2 files changed, 75 insertions(+), 8 deletions(-)
> 
> diff --git a/src/say.c b/src/say.c
> index 43124083c..aa820175c 100644
> --- a/src/say.c
> +++ b/src/say.c
> @@ -451,7 +451,7 @@ log_file_init(struct log *log, const char *init_str)
>  }
>  
>  /**
> - * Connect to syslogd using UNIX socket.
> + * Connect to UNIX socket.

No point in changing this comment.

>   * @param path UNIX socket path.
>   * @retval not 0 Socket descriptor.
>   * @retval    -1 Socket error.
> @@ -473,16 +473,50 @@ syslog_connect_unix(const char *path)
>  	return fd;
>  }
>  
> +/**
> + * Connect to remote syslogd using server:port.
> + * @param ip:port pair.

If you write a comment for doxygen, please describe each paramter
separately, i.e.

 @param remote server address
 @param port server port

> + * @retval not 0 Socket descriptor.
> + * @retval    -1 Socket error.
> + */
> +static int
> +syslog_connect_remote(const char *remote, const char *portnum)
> +{
> +	/* IPv4 */
> +	struct sockaddr_in in;
> +	in_addr_t addr = inet_addr(remote);

I think you should use getaddrinfo() to resolve the address.

> +	int fd = socket(AF_INET, SOCK_DGRAM, 0);
> +	if (fd < 0)
> +		return -1;
> +	memset(&in, 0, sizeof(in));
> +	in.sin_family = AF_INET;
> +	in.sin_port = htons(atoi(portnum));
> +	in.sin_addr.s_addr = addr;
> +	if (connect(fd, (struct sockaddr *) &in, sizeof(in)) != 0) {
> +		close(fd);
> +		return -1;
> +	}
> +	return fd;
> +}
> +
>  static inline int
>  log_syslog_connect(struct log *log)
>  {
> +
>  	/*
> -	 * Try two locations: '/dev/log' for Linux and
> +	 * If server option is not se use '/dev/log' for Linux and
                                   ^^
                          typo: se => set

>  	 * '/var/run/syslog' for Mac.
>  	 */
> -	log->fd = syslog_connect_unix("/dev/log");
> -	if (log->fd < 0)
> -		log->fd = syslog_connect_unix("/var/run/syslog");
> +	if (strncmp(log->addr_type, "default", sizeof("default")) == 0) {

Comparing strings to determine the socket address looks ugly. Besides,
using strings is troublesome - you have to allocate and free them (which
you forgot BTW). I think you'd better introduce a enum for that.

> +		log->fd = syslog_connect_unix("/dev/log");

> +			if (log->fd < 0)
> +				log->fd = syslog_connect_unix("/var/run/syslog");

Malformed indentation.

> +	} else if (strncmp(log->addr_type, "unix", sizeof("unix")) == 0) {
> +		log->fd = syslog_connect_unix(log->addr_path);
> +	} else {
> +		log->fd = syslog_connect_remote(log->addr_type,
> +				                log->addr_path);
> +	}
>  	return log->fd;
>  }
>  
> @@ -498,6 +532,14 @@ log_syslog_init(struct log *log, const char *init_str)
>  	if (say_parse_syslog_opts(init_str, &opts) < 0)
>  		return -1;
>  
> +	if (opts.addr_type == NULL &&
> +	    opts.addr_path == NULL) {
> +		log->addr_type = strdup("default");
> +	} else {
> +		log->addr_type = strdup(opts.addr_type);
> +		log->addr_path = strdup(opts.addr_path);
> +	}
> +

We handle memory allocation errors gracefully in tarantool code.
Even for strdup() and malloc() although they typically never fail.
Please implement error handling.

>  	if (opts.identity == NULL)
>  		log->syslog_ident = strdup("tarantool");
>  	else
> @@ -1044,6 +1086,8 @@ say_syslog_facility_by_name(const char *facility)
>  int
>  say_parse_syslog_opts(const char *init_str, struct say_syslog_opts *opts)
>  {
> +	opts->addr_type = NULL;
> +	opts->addr_path = NULL;
>  	opts->identity = NULL;
>  	opts->facility = syslog_facility_MAX;
>  	opts->copy = strdup(init_str);
> @@ -1051,8 +1095,9 @@ say_parse_syslog_opts(const char *init_str, struct say_syslog_opts *opts)
>  		diag_set(OutOfMemory, strlen(init_str), "malloc", "opts->copy");
>  		return -1;
>  	}
> -	char *ptr = opts->copy;
> -	const char *option, *value;
> +	char *ptr = opts->copy; 
> +	const char *option, *value, *srv_str;
> +	char *srv_ptr, *srv_opt;
>  
>  	/* strsep() overwrites the separator with '\0' */
>  	while ((option = strsep(&ptr, ","))) {
> @@ -1060,7 +1105,22 @@ say_parse_syslog_opts(const char *init_str, struct say_syslog_opts *opts)
>  			break;
>  
>  		value = option;
> -		if (say_parse_prefix(&value, "identity=")) {
> +		srv_str = say_parse_prefix(&value, "server=");
> +		if (srv_str != NULL) {
> +			if (opts->addr_path != NULL ||
> +			    opts->addr_type != NULL)
> +				goto duplicate;
> +			if (say_parse_prefix(&srv_str, "unix:")) {
> +				opts->addr_type = strdup("unix");
> +				opts->addr_path = srv_str;
> +			} else {
> +				srv_ptr = strdup(srv_str);
> +				srv_opt = srv_ptr;
> +				opts->addr_type = strsep(&srv_ptr,":");
> +				opts->addr_path = srv_ptr;

You don't need to allocate addr_path. Instead you can make it point to
the appropriate position in opts->copy and add '\0' at the end (it's
mutable). We do this in case of 'identity' AFAICS.

> +				free(srv_opt);
> +			}
> +		} else if (say_parse_prefix(&value, "identity=")) {
>  			if (opts->identity != NULL)
>  				goto duplicate;
>  			opts->identity = value;
> diff --git a/src/say.h b/src/say.h
> index ad3ba3417..6bee2cc90 100644
> --- a/src/say.h
> +++ b/src/say.h
> @@ -162,6 +162,11 @@ struct log {
>  	int rotating_threads;
>  	enum syslog_facility syslog_facility;
>  	struct rlist in_log_list;
> +	/* Server options. Either ip/port pair or unix socket address.*/
> +	struct {
> +		char *addr_type;
> +		char *addr_path;
> +	};

As I said above, I think you should turn addr_type into enum.
As for addr_path, there's log::path, which isn't used for socket
destination. You could reuse it instead of introducing a new
member.

>  };
>  
>  /**
> @@ -390,6 +395,8 @@ say_parse_logger_type(const char **str, enum say_logger_type *type);
>  
>  /** Syslog logger initialization params */
>  struct say_syslog_opts {
> +	const char *addr_type;
> +	const char *addr_path;
>  	const char *identity;
>  	enum syslog_facility facility;
>  	/* Input copy (content unspecified). */

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [tarantool-patches] [PATCH 2/3] Syslog remote destination test
  2018-07-13 10:29 ` [tarantool-patches] [PATCH 2/3] Syslog remote destination test Olga Arkhangelskaia
@ 2018-07-13 13:27   ` Vladimir Davydov
  0 siblings, 0 replies; 8+ messages in thread
From: Vladimir Davydov @ 2018-07-13 13:27 UTC (permalink / raw)
  To: Olga Arkhangelskaia; +Cc: tarantool-patches

On Fri, Jul 13, 2018 at 01:29:37PM +0300, Olga Arkhangelskaia wrote:
> Adds syslog remote destination test in app-tap.
> Test creates server, sets appropriate log level and redirects logs to it.
> If log level received by the server is the same - test passes.
> 
> Usage: test-run.py syslog
> 
> Signed-off-by: Olga Arkhangelskaia <arkholga@tarantool.org>
> ---
>  test/app-tap/syslog_remote.test.lua | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
>  create mode 100755 test/app-tap/syslog_remote.test.lua

IMHO better add this test case, as well as the next one, to
box-tap/cfg.test.lua.

> 
> diff --git a/test/app-tap/syslog_remote.test.lua b/test/app-tap/syslog_remote.test.lua
> new file mode 100755
> index 000000000..c7bb773fa
> --- /dev/null
> +++ b/test/app-tap/syslog_remote.test.lua
> @@ -0,0 +1,33 @@
> +#!/usr/bin/env tarantool
> +
> +local tap = require('tap')
> +local socket = require('socket')
> +local os = require('os')
> +local test = tap.test("syslog_remote")
> +
> +test:plan(1)
> +local addr = '127.0.0.1'
> +local port = 8888

The port may be busy. Better use a random one. For example, see

https://github.com/tarantool/tarantool/blob/fbf8be12dbb041026fc7c81018ac5f02a9fc9d18/test/app/socket.test.lua#L357

> +
> +local function start_server()
> +	test:diag("Starting server")
> +	local server = socket.tcp_server(addr, port, function() end)

Why do you need a tcp server? AFAIU all you need is a udp socket bound
to the specified port.

> +
> +	local sc = socket('AF_INET', 'SOCK_DGRAM', 'udp')

> +	sc:bind('127.0.0.1', 8888)

Should be (addr, port)

> +	return server, sc
> +end
> +
> +local function find_log_level()
> +	local opt = 'syslog:server='..addr..':'..port..',identity=tarantool'

There's string.format(), which usually results in cleaner code than
string concatenation.

> +	box.cfg{log = opt, log_level = 7}
> +	local buf = sc:read(300)

> +	test:ok(buf:match('log level 7'))

Better write a specific string to the log (see log.info) and match it.
Matching 'log level 7' took me a while to understand.

> +end
> +
> +server,sc = start_server()
> +
> +test:test('syslog_remote',find_log_level(test))
> +sc:close()
> +server:shutdown()
> +os.exit(test:check() == true)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [tarantool-patches] [PATCH 3/3] Syslog destination test unix socket
  2018-07-13 10:29 ` [tarantool-patches] [PATCH 3/3] Syslog destination test unix socket Olga Arkhangelskaia
@ 2018-07-13 13:34   ` Vladimir Davydov
  0 siblings, 0 replies; 8+ messages in thread
From: Vladimir Davydov @ 2018-07-13 13:34 UTC (permalink / raw)
  To: Olga Arkhangelskaia; +Cc: tarantool-patches

On Fri, Jul 13, 2018 at 01:29:38PM +0300, Olga Arkhangelskaia wrote:
> Adds syslog destination unix test in app-tap.
> Test redirects logs to newly created unix socket and sets appropriate
> log level. If log receives the same level - test passes.
> Usage: test-run.py syslog
> 
> Signed-off-by: Olga Arkhangelskaia <arkholga@tarantool.org>
> ---
>  test/app-tap/syslog_socket.test.lua | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
>  create mode 100755 test/app-tap/syslog_socket.test.lua
> 
> diff --git a/test/app-tap/syslog_socket.test.lua b/test/app-tap/syslog_socket.test.lua
> new file mode 100755
> index 000000000..bc65ffd5e
> --- /dev/null
> +++ b/test/app-tap/syslog_socket.test.lua
> @@ -0,0 +1,33 @@
> +#!/usr/bin/env tarantool
> +
> +local tap = require('tap')
> +local socket = require('socket')
> +local os = require('os')
> +local test = tap.test("syslog_unix")
> +
> +test:plan(1)
> +local function start_server(test, sock_addr)
> +    test:diag("Create unix socket")
> +    local destination = 'unix:'.. sock_addr
> +    local unix_socket = socket('AF_UNIX', 'SOCK_DGRAM',0)

You don't need datagrams here. Please use SOCK_STREAM.

> +    unix_socket:bind('unix/', sock_addr)
> +    socket.tcp_connect('unix', sock_addr)
> +    unix_socket:listen()
> +    return unix_socket, destination
> +end
> +
> +local function find_log_level (test, socket, destination)
> +	local buf
> +	local opt = 'syslog:server='..destination..',identity=tarantool'
> +	box.cfg{log = opt, log_level = 7}
> +	buf = socket:read(300)
> +	test:ok(buf:match('log level 7'))
> +end
> +
> +path = '/tmp/syslog_test.sock'

Better create the socket in the current directory to avoid conflicts.
For example, see

https://github.com/tarantool/tarantool/blob/fbf8be12dbb041026fc7c81018ac5f02a9fc9d18/test/app-tap/console.test.lua#L14

> +sock, dst = start_server(test, path)
> +
> +test:test('syslog_unix',find_log_level(test, sock, dst))
> +sock:close()
> +os.remove(path)
> +os.exit(test:check() == true)

Please also check that an invalid address is handled properly so as to
cover error paths. The same's fair for the previous test case too.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-07-13 13:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-13 10:29 [tarantool-patches] [PATCH 0/3] Syslog destination Olga Arkhangelskaia
2018-07-13 10:29 ` [tarantool-patches] [PATCH 1/3] Configurable syslog destination Olga Arkhangelskaia
2018-07-13 13:12   ` Vladimir Davydov
2018-07-13 10:29 ` [tarantool-patches] [PATCH 2/3] Syslog remote destination test Olga Arkhangelskaia
2018-07-13 13:27   ` Vladimir Davydov
2018-07-13 10:29 ` [tarantool-patches] [PATCH 3/3] Syslog destination test unix socket Olga Arkhangelskaia
2018-07-13 13:34   ` Vladimir Davydov
2018-07-13 12:42 ` [tarantool-patches] [PATCH 0/3] Syslog destination Vladimir Davydov

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