diff mbox series

ulogd / JSON output / enhancement proposal

Message ID CAEqktHujVnjWhdvttjmQWMSHb8mXwhV=Fz2en-6amijbHHR0pw@mail.gmail.com
State New
Headers show
Series ulogd / JSON output / enhancement proposal | expand

Commit Message

Gérald Colangelo Dec. 14, 2023, 5:52 p.m. UTC
Hello everyone,

To complete my previous message, here is a patch for
ulogd_output_JSON.c (latest version) that implements a "softfail"
configuration option.
If set to 1, error while connecting to unix socket are ignored during
startup and plugin will attempt to connect next time it will be
triggered.
This may be helpful when the software that must listen on unix socket
takes too long to launch.

Best regards,

Comments

Jeremy Sowden Dec. 15, 2023, 6:01 p.m. UTC | #1
On 2023-12-14, at 18:52:10 +0100, Gérald Colangelo wrote:
> To complete my previous message, here is a patch for
> ulogd_output_JSON.c (latest version) that implements a "softfail"
> configuration option.  If set to 1, error while connecting to unix
> socket are ignored during startup and plugin will attempt to connect
> next time it will be triggered.  This may be helpful when the software
> that must listen on unix socket takes too long to launch.

The JSON plug-in already has support for reopening the socket on receipt
of a signal or in the event of a write failure, so I think it probably
makes sense to build on that.  I'll send a patch.

J.
diff mbox series

Patch

51a52
> #define softfail_ce(x)   (x->ces[JSON_CONF_SOFTFAIL])
53a55,57
> 
> static int json_init_connect(struct ulogd_pluginstance *upi);
> 
61a66,67
> 	int started;
> 	int softfail;
81c87,88
< 	JSON_CONF_MAX
---
> 	JSON_CONF_SOFTFAIL,
> 	JSON_CONF_MAX,
140a148,153
> 		[JSON_CONF_SOFTFAIL] = {
> 			.key = "softfail",
> 			.type = CONFIG_TYPE_INT,
> 			.options = CONFIG_OPT_NONE,
> 			.u = { .value = 0 },
> 		},
283a297,313
> 	if (opi->softfail == 1 && opi->started == 0) {
> 		int state;
> 		state = json_init_connect(upi);
> 		/* Not connected but softfail, skip packet */
> 		if (state == 1) {
> 			ulogd_log(ULOGD_DEBUG, "unable to connect to json but softail=1, packet will be ignored.\n");
> 			return ULOGD_IRET_OK;
> 		}
> 		else if (state == 0) {
> 			ulogd_log(ULOGD_DEBUG, "successfully connected json endpoint!\n");
> 		}
> 		else {
> 			ulogd_log(ULOGD_FATAL, "not supposed to happen !\n");
> 			return ULOGD_IRET_STOP;
> 		}
> 	}
> 
500a531,535
> 	if ( softfail_ce(upi->config_kset).u.value != 0 )
> 		op->softfail = 1;
> 	else
> 		op->softfail = 0;
> 
542a578,609
> 
> /*
>    return value:
>     0: connection is OK.
>     1: connection is KO but softfail=1 (retry later).
>     -1: connection is KO and softfail=0 (fail).
> */
> static int json_init_connect(struct ulogd_pluginstance *upi)
> {
> 	struct json_priv *op = (struct json_priv *) &upi->private;
> 	int ret;
> 	ret = 0;
> 	if (op->mode == JSON_MODE_FILE)
> 		ret = json_init_file(upi);
> 	else
> 		ret = json_init_socket(upi);
> 
> 	/* failed starting and softfail_start != 0 */
> 	if (ret != 0) {
> 		if(op->softfail == 1) {
> 			ulogd_log(ULOGD_INFO, "can't init output, but softfail=1. Will retry later.\n");
> 			op->started = 0;
> 			return 1;
> 		} else {
> 			ulogd_log(ULOGD_FATAL, "can't connect and softfail=0, fatal error.\n");
> 			return -1;
> 		}
> 	}
> 	op->started = 1;
> 	return 0;
> }
> 
561,564c628
< 	if (op->mode == JSON_MODE_FILE)
< 		return json_init_file(upi);
< 	else
< 		return json_init_socket(upi);
---
>     return json_init_connect(upi) == -1 ? -1 : 0;