MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
/*
|
|
|
|
|
* Event sink management
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2000-2019 Willy Tarreau - w@1wt.eu
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation, version 2.1
|
|
|
|
|
* exclusively.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*/
|
|
|
|
|
|
2022-08-11 10:38:20 -04:00
|
|
|
#include <sys/mman.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
2020-06-05 11:27:29 -04:00
|
|
|
#include <import/ist.h>
|
2020-05-27 06:58:42 -04:00
|
|
|
#include <haproxy/api.h>
|
2022-04-04 05:29:28 -04:00
|
|
|
#include <haproxy/applet.h>
|
2020-06-04 18:00:29 -04:00
|
|
|
#include <haproxy/cfgparse.h>
|
2020-06-04 14:19:54 -04:00
|
|
|
#include <haproxy/cli.h>
|
2020-06-05 11:27:29 -04:00
|
|
|
#include <haproxy/errors.h>
|
2020-05-27 12:01:47 -04:00
|
|
|
#include <haproxy/list.h>
|
2020-06-04 16:01:04 -04:00
|
|
|
#include <haproxy/log.h>
|
2021-05-08 14:20:21 -04:00
|
|
|
#include <haproxy/proxy.h>
|
2020-06-03 13:43:35 -04:00
|
|
|
#include <haproxy/ring.h>
|
2022-05-27 03:25:10 -04:00
|
|
|
#include <haproxy/sc_strm.h>
|
2020-06-04 11:37:26 -04:00
|
|
|
#include <haproxy/signal.h>
|
2020-06-03 14:02:28 -04:00
|
|
|
#include <haproxy/sink.h>
|
2022-05-27 03:47:12 -04:00
|
|
|
#include <haproxy/stconn.h>
|
2020-06-09 03:07:15 -04:00
|
|
|
#include <haproxy/time.h>
|
2021-05-08 07:05:30 -04:00
|
|
|
#include <haproxy/tools.h>
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
|
|
|
|
|
struct list sink_list = LIST_HEAD_INIT(sink_list);
|
|
|
|
|
|
2022-09-13 10:16:30 -04:00
|
|
|
/* sink proxies list */
|
|
|
|
|
struct proxy *sink_proxies_list;
|
|
|
|
|
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
struct sink *cfg_sink;
|
|
|
|
|
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
struct sink *sink_find(const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct sink *sink;
|
|
|
|
|
|
|
|
|
|
list_for_each_entry(sink, &sink_list, sink_list)
|
|
|
|
|
if (strcmp(sink->name, name) == 0)
|
|
|
|
|
return sink;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* creates a new sink and adds it to the list, it's still generic and not fully
|
|
|
|
|
* initialized. Returns NULL on allocation failure. If another one already
|
|
|
|
|
* exists with the same name, it will be returned. The caller can detect it as
|
|
|
|
|
* a newly created one has type SINK_TYPE_NEW.
|
|
|
|
|
*/
|
2020-07-06 09:54:06 -04:00
|
|
|
static struct sink *__sink_new(const char *name, const char *desc, int fmt)
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
{
|
|
|
|
|
struct sink *sink;
|
|
|
|
|
|
|
|
|
|
sink = sink_find(name);
|
|
|
|
|
if (sink)
|
|
|
|
|
goto end;
|
|
|
|
|
|
2020-05-28 05:13:15 -04:00
|
|
|
sink = calloc(1, sizeof(*sink));
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
if (!sink)
|
|
|
|
|
goto end;
|
|
|
|
|
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
sink->name = strdup(name);
|
2021-01-03 13:54:11 -05:00
|
|
|
if (!sink->name)
|
|
|
|
|
goto err;
|
|
|
|
|
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
sink->desc = strdup(desc);
|
2021-01-03 13:54:11 -05:00
|
|
|
if (!sink->desc)
|
|
|
|
|
goto err;
|
|
|
|
|
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
sink->fmt = fmt;
|
|
|
|
|
sink->type = SINK_TYPE_NEW;
|
2019-11-15 09:10:12 -05:00
|
|
|
sink->maxlen = BUFSIZE;
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
/* address will be filled by the caller if needed */
|
2019-08-20 05:57:52 -04:00
|
|
|
sink->ctx.fd = -1;
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
sink->ctx.dropped = 0;
|
|
|
|
|
HA_RWLOCK_INIT(&sink->ctx.lock);
|
2021-04-21 01:32:39 -04:00
|
|
|
LIST_APPEND(&sink_list, &sink->sink_list);
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
end:
|
|
|
|
|
return sink;
|
2021-01-03 13:54:11 -05:00
|
|
|
|
|
|
|
|
err:
|
2021-02-20 04:46:51 -05:00
|
|
|
ha_free(&sink->name);
|
|
|
|
|
ha_free(&sink->desc);
|
|
|
|
|
ha_free(&sink);
|
2021-01-03 13:54:11 -05:00
|
|
|
|
|
|
|
|
return NULL;
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-20 05:57:52 -04:00
|
|
|
/* creates a sink called <name> of type FD associated to fd <fd>, format <fmt>,
|
|
|
|
|
* and description <desc>. Returns NULL on allocation failure or conflict.
|
|
|
|
|
* Perfect duplicates are merged (same type, fd, and name).
|
|
|
|
|
*/
|
2020-07-06 09:54:06 -04:00
|
|
|
struct sink *sink_new_fd(const char *name, const char *desc, enum log_fmt fmt, int fd)
|
2019-08-20 05:57:52 -04:00
|
|
|
{
|
|
|
|
|
struct sink *sink;
|
|
|
|
|
|
|
|
|
|
sink = __sink_new(name, desc, fmt);
|
|
|
|
|
if (!sink || (sink->type == SINK_TYPE_FD && sink->ctx.fd == fd))
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
if (sink->type != SINK_TYPE_NEW) {
|
|
|
|
|
sink = NULL;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sink->type = SINK_TYPE_FD;
|
|
|
|
|
sink->ctx.fd = fd;
|
|
|
|
|
end:
|
|
|
|
|
return sink;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-23 09:47:49 -04:00
|
|
|
/* creates a sink called <name> of type BUF of size <size>, format <fmt>,
|
|
|
|
|
* and description <desc>. Returns NULL on allocation failure or conflict.
|
|
|
|
|
* Perfect duplicates are merged (same type and name). If sizes differ, the
|
|
|
|
|
* largest one is kept.
|
|
|
|
|
*/
|
2020-07-06 09:54:06 -04:00
|
|
|
struct sink *sink_new_buf(const char *name, const char *desc, enum log_fmt fmt, size_t size)
|
2019-08-23 09:47:49 -04:00
|
|
|
{
|
|
|
|
|
struct sink *sink;
|
|
|
|
|
|
|
|
|
|
sink = __sink_new(name, desc, fmt);
|
|
|
|
|
if (!sink)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
if (sink->type == SINK_TYPE_BUFFER) {
|
|
|
|
|
/* such a buffer already exists, we may have to resize it */
|
|
|
|
|
if (!ring_resize(sink->ctx.ring, size))
|
|
|
|
|
goto fail;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sink->type != SINK_TYPE_NEW) {
|
|
|
|
|
/* already exists of another type */
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sink->ctx.ring = ring_new(size);
|
|
|
|
|
if (!sink->ctx.ring) {
|
2021-04-21 01:32:39 -04:00
|
|
|
LIST_DELETE(&sink->sink_list);
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
free(sink->name);
|
|
|
|
|
free(sink->desc);
|
2019-08-23 09:47:49 -04:00
|
|
|
free(sink);
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sink->type = SINK_TYPE_BUFFER;
|
|
|
|
|
end:
|
|
|
|
|
return sink;
|
|
|
|
|
fail:
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
/* tries to send <nmsg> message parts (up to 8, ignored above) from message
|
2020-07-05 07:36:08 -04:00
|
|
|
* array <msg> to sink <sink>. Formatting according to the sink's preference is
|
2019-08-27 10:41:06 -04:00
|
|
|
* done here. Lost messages are NOT accounted for. It is preferable to call
|
|
|
|
|
* sink_write() instead which will also try to emit the number of dropped
|
|
|
|
|
* messages when there are any. It returns >0 if it could write anything,
|
|
|
|
|
* <=0 otherwise.
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
*/
|
2020-07-06 09:54:06 -04:00
|
|
|
ssize_t __sink_write(struct sink *sink, const struct ist msg[], size_t nmsg,
|
|
|
|
|
int level, int facility, struct ist *metadata)
|
|
|
|
|
{
|
|
|
|
|
struct ist *pfx = NULL;
|
2019-08-27 08:21:02 -04:00
|
|
|
size_t npfx = 0;
|
2020-05-06 08:33:46 -04:00
|
|
|
|
2020-07-06 09:54:06 -04:00
|
|
|
if (sink->fmt == LOG_FORMAT_RAW)
|
2020-05-06 08:33:46 -04:00
|
|
|
goto send;
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
|
2020-07-06 09:54:06 -04:00
|
|
|
pfx = build_log_header(sink->fmt, level, facility, metadata, &npfx);
|
2020-05-06 08:33:46 -04:00
|
|
|
|
|
|
|
|
send:
|
2019-08-20 05:57:52 -04:00
|
|
|
if (sink->type == SINK_TYPE_FD) {
|
2019-08-27 10:41:06 -04:00
|
|
|
return fd_write_frag_line(sink->ctx.fd, sink->maxlen, pfx, npfx, msg, nmsg, 1);
|
2019-08-23 09:47:49 -04:00
|
|
|
}
|
|
|
|
|
else if (sink->type == SINK_TYPE_BUFFER) {
|
2019-08-27 10:41:06 -04:00
|
|
|
return ring_write(sink->ctx.ring, sink->maxlen, pfx, npfx, msg, nmsg);
|
2019-08-20 05:57:52 -04:00
|
|
|
}
|
2019-08-27 10:41:06 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
|
2019-08-27 10:41:06 -04:00
|
|
|
/* Tries to emit a message indicating the number of dropped events. In case of
|
|
|
|
|
* success, the amount of drops is reduced by as much. It's supposed to be
|
|
|
|
|
* called under an exclusive lock on the sink to avoid multiple produces doing
|
|
|
|
|
* the same. On success, >0 is returned, otherwise <=0 on failure.
|
|
|
|
|
*/
|
2020-07-06 09:54:06 -04:00
|
|
|
int sink_announce_dropped(struct sink *sink, int facility)
|
2019-08-27 10:41:06 -04:00
|
|
|
{
|
2020-07-06 09:54:06 -04:00
|
|
|
static THREAD_LOCAL struct ist metadata[LOG_META_FIELDS];
|
|
|
|
|
static THREAD_LOCAL pid_t curr_pid;
|
|
|
|
|
static THREAD_LOCAL char pidstr[16];
|
2019-08-27 10:41:06 -04:00
|
|
|
unsigned int dropped;
|
|
|
|
|
struct buffer msg;
|
|
|
|
|
struct ist msgvec[1];
|
|
|
|
|
char logbuf[64];
|
|
|
|
|
|
|
|
|
|
while (unlikely((dropped = sink->ctx.dropped) > 0)) {
|
|
|
|
|
chunk_init(&msg, logbuf, sizeof(logbuf));
|
|
|
|
|
chunk_printf(&msg, "%u event%s dropped", dropped, dropped > 1 ? "s" : "");
|
|
|
|
|
msgvec[0] = ist2(msg.area, msg.data);
|
2020-05-06 08:33:46 -04:00
|
|
|
|
2020-07-06 09:54:06 -04:00
|
|
|
if (!metadata[LOG_META_HOST].len) {
|
|
|
|
|
if (global.log_send_hostname)
|
2022-03-15 08:11:06 -04:00
|
|
|
metadata[LOG_META_HOST] = ist(global.log_send_hostname);
|
2020-07-06 09:54:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!metadata[LOG_META_TAG].len)
|
|
|
|
|
metadata[LOG_META_TAG] = ist2(global.log_tag.area, global.log_tag.data);
|
|
|
|
|
|
|
|
|
|
if (unlikely(curr_pid != getpid()))
|
|
|
|
|
metadata[LOG_META_PID].len = 0;
|
|
|
|
|
|
|
|
|
|
if (!metadata[LOG_META_PID].len) {
|
|
|
|
|
curr_pid = getpid();
|
|
|
|
|
ltoa_o(curr_pid, pidstr, sizeof(pidstr));
|
|
|
|
|
metadata[LOG_META_PID] = ist2(pidstr, strlen(pidstr));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (__sink_write(sink, msgvec, 1, LOG_NOTICE, facility, metadata) <= 0)
|
2019-08-27 10:41:06 -04:00
|
|
|
return 0;
|
|
|
|
|
/* success! */
|
|
|
|
|
HA_ATOMIC_SUB(&sink->ctx.dropped, dropped);
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-26 12:17:04 -04:00
|
|
|
/* parse the "show events" command, returns 1 if a message is returned, otherwise zero */
|
|
|
|
|
static int cli_parse_show_events(char **args, char *payload, struct appctx *appctx, void *private)
|
|
|
|
|
{
|
|
|
|
|
struct sink *sink;
|
2022-05-05 09:18:57 -04:00
|
|
|
uint ring_flags;
|
2019-08-30 05:17:01 -04:00
|
|
|
int arg;
|
2019-08-26 12:17:04 -04:00
|
|
|
|
|
|
|
|
args++; // make args[1] the 1st arg
|
|
|
|
|
|
|
|
|
|
if (!*args[1]) {
|
|
|
|
|
/* no arg => report the list of supported sink */
|
2019-08-30 05:17:01 -04:00
|
|
|
chunk_printf(&trash, "Supported events sinks are listed below. Add -w(wait), -n(new). Any key to stop\n");
|
2019-08-26 12:17:04 -04:00
|
|
|
list_for_each_entry(sink, &sink_list, sink_list) {
|
|
|
|
|
chunk_appendf(&trash, " %-10s : type=%s, %u dropped, %s\n",
|
|
|
|
|
sink->name,
|
|
|
|
|
sink->type == SINK_TYPE_NEW ? "init" :
|
|
|
|
|
sink->type == SINK_TYPE_FD ? "fd" :
|
|
|
|
|
sink->type == SINK_TYPE_BUFFER ? "buffer" : "?",
|
|
|
|
|
sink->ctx.dropped, sink->desc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trash.area[trash.data] = 0;
|
|
|
|
|
return cli_msg(appctx, LOG_WARNING, trash.area);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!cli_has_level(appctx, ACCESS_LVL_OPER))
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
sink = sink_find(args[1]);
|
|
|
|
|
if (!sink)
|
|
|
|
|
return cli_err(appctx, "No such event sink");
|
|
|
|
|
|
|
|
|
|
if (sink->type != SINK_TYPE_BUFFER)
|
|
|
|
|
return cli_msg(appctx, LOG_NOTICE, "Nothing to report for this sink");
|
|
|
|
|
|
2022-05-05 09:18:57 -04:00
|
|
|
ring_flags = 0;
|
2019-08-30 05:17:01 -04:00
|
|
|
for (arg = 2; *args[arg]; arg++) {
|
|
|
|
|
if (strcmp(args[arg], "-w") == 0)
|
2022-05-05 09:18:57 -04:00
|
|
|
ring_flags |= RING_WF_WAIT_MODE;
|
2019-08-30 05:17:01 -04:00
|
|
|
else if (strcmp(args[arg], "-n") == 0)
|
2022-05-05 09:18:57 -04:00
|
|
|
ring_flags |= RING_WF_SEEK_NEW;
|
2019-08-30 05:17:01 -04:00
|
|
|
else if (strcmp(args[arg], "-nw") == 0 || strcmp(args[arg], "-wn") == 0)
|
2022-05-05 09:18:57 -04:00
|
|
|
ring_flags |= RING_WF_WAIT_MODE | RING_WF_SEEK_NEW;
|
2019-08-30 05:17:01 -04:00
|
|
|
else
|
|
|
|
|
return cli_err(appctx, "unknown option");
|
|
|
|
|
}
|
2022-05-05 09:18:57 -04:00
|
|
|
return ring_attach_cli(sink->ctx.ring, appctx, ring_flags);
|
2019-08-26 12:17:04 -04:00
|
|
|
}
|
|
|
|
|
|
2020-06-21 12:42:57 -04:00
|
|
|
/* Pre-configures a ring proxy to emit connections */
|
2020-05-28 05:13:15 -04:00
|
|
|
void sink_setup_proxy(struct proxy *px)
|
|
|
|
|
{
|
|
|
|
|
px->last_change = now.tv_sec;
|
BUG/MINOR: sink: Only use backend capability for the sink proxies
When a ring section is parsed, a proxy is created. For now, it has the
frontend (PR_CAP_FE) and the internal (PR_CAP_INT) capabilities, in addition
to the expected backend capability (PR_CAP_BE).
PR_CAP_INT capability was added to silent warning triggered because of
PR_CAP_FE capability. Indeed, Because the proxy is declared as a frontend,
warnings about missing bind lines and missing client timeout should be
triggered during the configuration parsing. These warnings are inhibited
because PR_CAP_INT capability is set. It is an issue on the 2.4 because
PR_CAP_INT capability does not exist. So warnings are always emitted.
But the true bug is that these proxies should not have PR_CAP_FE and
PR_CAP_INT capabilities. Removing these capabilities is enough to remove any
warnings on the 2.4, with no regression on higher versions. However, it may
be a good idea to eval if a dedicated frontend for sinks should be added or
not. This way, a true frontend would be used to start the sink applets. In
addition, proxies capabilities/modes have to be reviewed to have a less
ambiguous API. For instance a dedicate mode for sinks (PR_MODE_SINK ?) may
be added. Finally, it could be very nice to have all proxies in the same
list, including internal ones.
This patch should fix the issue #1900. It must be backported as far as 2.4.
2022-10-24 09:10:18 -04:00
|
|
|
px->cap = PR_CAP_BE;
|
2020-05-28 05:13:15 -04:00
|
|
|
px->maxconn = 0;
|
|
|
|
|
px->conn_retries = 1;
|
|
|
|
|
px->timeout.server = TICK_ETERNITY;
|
|
|
|
|
px->timeout.client = TICK_ETERNITY;
|
|
|
|
|
px->timeout.connect = TICK_ETERNITY;
|
|
|
|
|
px->accept = NULL;
|
|
|
|
|
px->options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC;
|
2022-09-13 10:16:30 -04:00
|
|
|
px->next = sink_proxies_list;
|
|
|
|
|
sink_proxies_list = px;
|
2020-05-28 05:13:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2022-05-04 14:42:23 -04:00
|
|
|
* IO Handler to handle message push to syslog tcp server.
|
|
|
|
|
* It takes its context from appctx->svcctx.
|
2020-05-28 05:13:15 -04:00
|
|
|
*/
|
|
|
|
|
static void sink_forward_io_handler(struct appctx *appctx)
|
|
|
|
|
{
|
2022-05-27 05:08:15 -04:00
|
|
|
struct stconn *sc = appctx_sc(appctx);
|
2022-05-27 04:44:25 -04:00
|
|
|
struct stream *s = __sc_strm(sc);
|
2020-05-28 05:13:15 -04:00
|
|
|
struct sink *sink = strm_fe(s)->parent;
|
2022-05-04 14:42:23 -04:00
|
|
|
struct sink_forward_target *sft = appctx->svcctx;
|
2020-05-28 05:13:15 -04:00
|
|
|
struct ring *ring = sink->ctx.ring;
|
|
|
|
|
struct buffer *buf = &ring->buf;
|
|
|
|
|
uint64_t msg_len;
|
2022-08-04 11:18:54 -04:00
|
|
|
size_t len, cnt, ofs, last_ofs;
|
2020-05-28 05:13:15 -04:00
|
|
|
int ret = 0;
|
|
|
|
|
|
2020-06-21 12:42:57 -04:00
|
|
|
/* if stopping was requested, close immediately */
|
2020-05-28 05:13:15 -04:00
|
|
|
if (unlikely(stopping))
|
|
|
|
|
goto close;
|
|
|
|
|
|
|
|
|
|
/* for rex because it seems reset to timeout
|
|
|
|
|
* and we don't want expire on this case
|
|
|
|
|
* with a syslog server
|
|
|
|
|
*/
|
2022-05-27 04:44:25 -04:00
|
|
|
sc_oc(sc)->rex = TICK_ETERNITY;
|
2020-05-28 05:13:15 -04:00
|
|
|
/* rto should not change but it seems the case */
|
2022-05-27 04:44:25 -04:00
|
|
|
sc_oc(sc)->rto = TICK_ETERNITY;
|
2020-05-28 05:13:15 -04:00
|
|
|
|
|
|
|
|
/* an error was detected */
|
2022-05-27 04:44:25 -04:00
|
|
|
if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
|
2020-05-28 05:13:15 -04:00
|
|
|
goto close;
|
|
|
|
|
|
|
|
|
|
/* con closed by server side */
|
2022-05-27 04:44:25 -04:00
|
|
|
if ((sc_oc(sc)->flags & CF_SHUTW))
|
2020-05-28 05:13:15 -04:00
|
|
|
goto close;
|
|
|
|
|
|
|
|
|
|
/* if the connection is not established, inform the stream that we want
|
|
|
|
|
* to be notified whenever the connection completes.
|
|
|
|
|
*/
|
2022-05-27 04:44:25 -04:00
|
|
|
if (sc_opposite(sc)->state < SC_ST_EST) {
|
2022-05-25 12:21:43 -04:00
|
|
|
applet_need_more_data(appctx);
|
2022-05-24 10:49:03 -04:00
|
|
|
se_need_remote_conn(appctx->sedesc);
|
2022-05-25 09:42:03 -04:00
|
|
|
applet_have_more_data(appctx);
|
2020-05-28 05:13:15 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HA_SPIN_LOCK(SFT_LOCK, &sft->lock);
|
|
|
|
|
if (appctx != sft->appctx) {
|
|
|
|
|
HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
|
|
|
|
|
goto close;
|
|
|
|
|
}
|
|
|
|
|
ofs = sft->ofs;
|
|
|
|
|
|
|
|
|
|
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
|
|
|
|
|
LIST_DEL_INIT(&appctx->wait_entry);
|
|
|
|
|
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
|
|
|
|
|
|
|
|
|
|
HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock);
|
|
|
|
|
|
|
|
|
|
/* explanation for the initialization below: it would be better to do
|
|
|
|
|
* this in the parsing function but this would occasionally result in
|
|
|
|
|
* dropped events because we'd take a reference on the oldest message
|
|
|
|
|
* and keep it while being scheduled. Thus instead let's take it the
|
|
|
|
|
* first time we enter here so that we have a chance to pass many
|
|
|
|
|
* existing messages before grabbing a reference to a location. This
|
|
|
|
|
* value cannot be produced after initialization.
|
|
|
|
|
*/
|
|
|
|
|
if (unlikely(ofs == ~0)) {
|
|
|
|
|
ofs = 0;
|
|
|
|
|
|
2021-04-06 07:53:36 -04:00
|
|
|
HA_ATOMIC_INC(b_peek(buf, ofs));
|
2020-05-28 05:13:15 -04:00
|
|
|
ofs += ring->ofs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* in this loop, ofs always points to the counter byte that precedes
|
|
|
|
|
* the message so that we can take our reference there if we have to
|
|
|
|
|
* stop before the end (ret=0).
|
|
|
|
|
*/
|
2022-05-27 04:44:25 -04:00
|
|
|
if (sc_opposite(sc)->state == SC_ST_EST) {
|
2020-12-02 11:02:09 -05:00
|
|
|
/* we were already there, adjust the offset to be relative to
|
|
|
|
|
* the buffer's head and remove us from the counter.
|
|
|
|
|
*/
|
|
|
|
|
ofs -= ring->ofs;
|
|
|
|
|
BUG_ON(ofs >= buf->size);
|
2021-04-06 07:53:36 -04:00
|
|
|
HA_ATOMIC_DEC(b_peek(buf, ofs));
|
2020-12-02 11:02:09 -05:00
|
|
|
|
2020-05-28 05:13:15 -04:00
|
|
|
ret = 1;
|
|
|
|
|
while (ofs + 1 < b_data(buf)) {
|
|
|
|
|
cnt = 1;
|
|
|
|
|
len = b_peek_varint(buf, ofs + cnt, &msg_len);
|
|
|
|
|
if (!len)
|
|
|
|
|
break;
|
|
|
|
|
cnt += len;
|
|
|
|
|
BUG_ON(msg_len + ofs + cnt + 1 > b_data(buf));
|
|
|
|
|
|
|
|
|
|
if (unlikely(msg_len + 1 > b_size(&trash))) {
|
|
|
|
|
/* too large a message to ever fit, let's skip it */
|
|
|
|
|
ofs += cnt + msg_len;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chunk_reset(&trash);
|
|
|
|
|
len = b_getblk(buf, trash.area, msg_len, ofs + cnt);
|
|
|
|
|
trash.data += len;
|
|
|
|
|
trash.area[trash.data++] = '\n';
|
|
|
|
|
|
2022-05-18 09:07:19 -04:00
|
|
|
if (applet_putchk(appctx, &trash) == -1) {
|
2020-05-28 05:13:15 -04:00
|
|
|
ret = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ofs += cnt + msg_len;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-06 07:53:36 -04:00
|
|
|
HA_ATOMIC_INC(b_peek(buf, ofs));
|
2020-05-28 05:13:15 -04:00
|
|
|
ofs += ring->ofs;
|
|
|
|
|
sft->ofs = ofs;
|
2022-08-04 11:18:54 -04:00
|
|
|
last_ofs = ring->ofs;
|
2020-05-28 05:13:15 -04:00
|
|
|
}
|
|
|
|
|
HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock);
|
|
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
|
/* let's be woken up once new data arrive */
|
|
|
|
|
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
|
2021-04-21 01:32:39 -04:00
|
|
|
LIST_APPEND(&ring->waiters, &appctx->wait_entry);
|
2022-08-04 11:18:54 -04:00
|
|
|
ofs = ring->ofs;
|
2020-05-28 05:13:15 -04:00
|
|
|
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
|
2022-08-04 11:18:54 -04:00
|
|
|
if (ofs != last_ofs) {
|
|
|
|
|
/* more data was added into the ring between the
|
|
|
|
|
* unlock and the lock, and the writer might not
|
|
|
|
|
* have seen us. We need to reschedule a read.
|
|
|
|
|
*/
|
|
|
|
|
applet_have_more_data(appctx);
|
|
|
|
|
} else
|
|
|
|
|
applet_have_no_more_data(appctx);
|
2020-05-28 05:13:15 -04:00
|
|
|
}
|
|
|
|
|
HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
|
|
|
|
|
|
|
|
|
|
/* always drain data from server */
|
2022-05-27 04:44:25 -04:00
|
|
|
co_skip(sc_oc(sc), sc_oc(sc)->output);
|
2020-05-28 05:13:15 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
close:
|
2022-05-27 04:44:25 -04:00
|
|
|
sc_shutw(sc);
|
|
|
|
|
sc_shutr(sc);
|
|
|
|
|
sc_ic(sc)->flags |= CF_READ_NULL;
|
2020-05-28 05:13:15 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-29 19:42:45 -04:00
|
|
|
/*
|
|
|
|
|
* IO Handler to handle message push to syslog tcp server
|
|
|
|
|
* using octet counting frames
|
2022-05-04 14:42:23 -04:00
|
|
|
* It takes its context from appctx->svcctx.
|
2020-05-29 19:42:45 -04:00
|
|
|
*/
|
|
|
|
|
static void sink_forward_oc_io_handler(struct appctx *appctx)
|
|
|
|
|
{
|
2022-05-27 05:08:15 -04:00
|
|
|
struct stconn *sc = appctx_sc(appctx);
|
2022-05-27 04:44:25 -04:00
|
|
|
struct stream *s = __sc_strm(sc);
|
2020-05-29 19:42:45 -04:00
|
|
|
struct sink *sink = strm_fe(s)->parent;
|
2022-05-04 14:42:23 -04:00
|
|
|
struct sink_forward_target *sft = appctx->svcctx;
|
2020-05-29 19:42:45 -04:00
|
|
|
struct ring *ring = sink->ctx.ring;
|
|
|
|
|
struct buffer *buf = &ring->buf;
|
|
|
|
|
uint64_t msg_len;
|
|
|
|
|
size_t len, cnt, ofs;
|
|
|
|
|
int ret = 0;
|
|
|
|
|
char *p;
|
|
|
|
|
|
2020-06-21 12:42:57 -04:00
|
|
|
/* if stopping was requested, close immediately */
|
2020-05-29 19:42:45 -04:00
|
|
|
if (unlikely(stopping))
|
|
|
|
|
goto close;
|
|
|
|
|
|
|
|
|
|
/* for rex because it seems reset to timeout
|
|
|
|
|
* and we don't want expire on this case
|
|
|
|
|
* with a syslog server
|
|
|
|
|
*/
|
2022-05-27 04:44:25 -04:00
|
|
|
sc_oc(sc)->rex = TICK_ETERNITY;
|
2020-05-29 19:42:45 -04:00
|
|
|
/* rto should not change but it seems the case */
|
2022-05-27 04:44:25 -04:00
|
|
|
sc_oc(sc)->rto = TICK_ETERNITY;
|
2020-05-29 19:42:45 -04:00
|
|
|
|
|
|
|
|
/* an error was detected */
|
2022-05-27 04:44:25 -04:00
|
|
|
if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
|
2020-05-29 19:42:45 -04:00
|
|
|
goto close;
|
|
|
|
|
|
|
|
|
|
/* con closed by server side */
|
2022-05-27 04:44:25 -04:00
|
|
|
if ((sc_oc(sc)->flags & CF_SHUTW))
|
2020-05-29 19:42:45 -04:00
|
|
|
goto close;
|
|
|
|
|
|
|
|
|
|
/* if the connection is not established, inform the stream that we want
|
|
|
|
|
* to be notified whenever the connection completes.
|
|
|
|
|
*/
|
2022-05-27 04:44:25 -04:00
|
|
|
if (sc_opposite(sc)->state < SC_ST_EST) {
|
2022-05-25 12:21:43 -04:00
|
|
|
applet_need_more_data(appctx);
|
2022-05-24 10:49:03 -04:00
|
|
|
se_need_remote_conn(appctx->sedesc);
|
2022-05-25 09:42:03 -04:00
|
|
|
applet_have_more_data(appctx);
|
2020-05-29 19:42:45 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HA_SPIN_LOCK(SFT_LOCK, &sft->lock);
|
|
|
|
|
if (appctx != sft->appctx) {
|
|
|
|
|
HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
|
|
|
|
|
goto close;
|
|
|
|
|
}
|
|
|
|
|
ofs = sft->ofs;
|
|
|
|
|
|
|
|
|
|
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
|
|
|
|
|
LIST_DEL_INIT(&appctx->wait_entry);
|
|
|
|
|
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
|
|
|
|
|
|
|
|
|
|
HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock);
|
|
|
|
|
|
|
|
|
|
/* explanation for the initialization below: it would be better to do
|
|
|
|
|
* this in the parsing function but this would occasionally result in
|
|
|
|
|
* dropped events because we'd take a reference on the oldest message
|
|
|
|
|
* and keep it while being scheduled. Thus instead let's take it the
|
|
|
|
|
* first time we enter here so that we have a chance to pass many
|
|
|
|
|
* existing messages before grabbing a reference to a location. This
|
|
|
|
|
* value cannot be produced after initialization.
|
|
|
|
|
*/
|
|
|
|
|
if (unlikely(ofs == ~0)) {
|
|
|
|
|
ofs = 0;
|
|
|
|
|
|
2021-04-06 07:53:36 -04:00
|
|
|
HA_ATOMIC_INC(b_peek(buf, ofs));
|
2020-05-29 19:42:45 -04:00
|
|
|
ofs += ring->ofs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* in this loop, ofs always points to the counter byte that precedes
|
|
|
|
|
* the message so that we can take our reference there if we have to
|
|
|
|
|
* stop before the end (ret=0).
|
|
|
|
|
*/
|
2022-05-27 04:44:25 -04:00
|
|
|
if (sc_opposite(sc)->state == SC_ST_EST) {
|
2020-12-02 11:02:09 -05:00
|
|
|
/* we were already there, adjust the offset to be relative to
|
|
|
|
|
* the buffer's head and remove us from the counter.
|
|
|
|
|
*/
|
|
|
|
|
ofs -= ring->ofs;
|
|
|
|
|
BUG_ON(ofs >= buf->size);
|
2021-04-06 07:53:36 -04:00
|
|
|
HA_ATOMIC_DEC(b_peek(buf, ofs));
|
2020-12-02 11:02:09 -05:00
|
|
|
|
2020-05-29 19:42:45 -04:00
|
|
|
ret = 1;
|
|
|
|
|
while (ofs + 1 < b_data(buf)) {
|
|
|
|
|
cnt = 1;
|
|
|
|
|
len = b_peek_varint(buf, ofs + cnt, &msg_len);
|
|
|
|
|
if (!len)
|
|
|
|
|
break;
|
|
|
|
|
cnt += len;
|
|
|
|
|
BUG_ON(msg_len + ofs + cnt + 1 > b_data(buf));
|
|
|
|
|
|
|
|
|
|
chunk_reset(&trash);
|
|
|
|
|
p = ulltoa(msg_len, trash.area, b_size(&trash));
|
|
|
|
|
if (p) {
|
|
|
|
|
trash.data = (p - trash.area) + 1;
|
|
|
|
|
*p = ' ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!p || (trash.data + msg_len > b_size(&trash))) {
|
|
|
|
|
/* too large a message to ever fit, let's skip it */
|
|
|
|
|
ofs += cnt + msg_len;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trash.data += b_getblk(buf, p + 1, msg_len, ofs + cnt);
|
|
|
|
|
|
2022-05-18 09:07:19 -04:00
|
|
|
if (applet_putchk(appctx, &trash) == -1) {
|
2020-05-29 19:42:45 -04:00
|
|
|
ret = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ofs += cnt + msg_len;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-06 07:53:36 -04:00
|
|
|
HA_ATOMIC_INC(b_peek(buf, ofs));
|
2020-05-29 19:42:45 -04:00
|
|
|
ofs += ring->ofs;
|
|
|
|
|
sft->ofs = ofs;
|
|
|
|
|
}
|
|
|
|
|
HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock);
|
|
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
|
/* let's be woken up once new data arrive */
|
|
|
|
|
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
|
2021-04-21 01:32:39 -04:00
|
|
|
LIST_APPEND(&ring->waiters, &appctx->wait_entry);
|
2020-05-29 19:42:45 -04:00
|
|
|
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
|
2022-05-25 09:42:03 -04:00
|
|
|
applet_have_no_more_data(appctx);
|
2020-05-29 19:42:45 -04:00
|
|
|
}
|
|
|
|
|
HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
|
|
|
|
|
|
|
|
|
|
/* always drain data from server */
|
2022-05-27 04:44:25 -04:00
|
|
|
co_skip(sc_oc(sc), sc_oc(sc)->output);
|
2020-05-29 19:42:45 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
close:
|
2022-05-27 04:44:25 -04:00
|
|
|
sc_shutw(sc);
|
|
|
|
|
sc_shutr(sc);
|
|
|
|
|
sc_ic(sc)->flags |= CF_READ_NULL;
|
2020-05-29 19:42:45 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 05:13:15 -04:00
|
|
|
void __sink_forward_session_deinit(struct sink_forward_target *sft)
|
|
|
|
|
{
|
2022-05-11 08:09:57 -04:00
|
|
|
struct stream *s = appctx_strm(sft->appctx);
|
2020-05-28 05:13:15 -04:00
|
|
|
struct sink *sink;
|
|
|
|
|
|
|
|
|
|
sink = strm_fe(s)->parent;
|
|
|
|
|
if (!sink)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &sink->ctx.ring->lock);
|
|
|
|
|
LIST_DEL_INIT(&sft->appctx->wait_entry);
|
|
|
|
|
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &sink->ctx.ring->lock);
|
|
|
|
|
|
|
|
|
|
sft->appctx = NULL;
|
|
|
|
|
task_wakeup(sink->forward_task, TASK_WOKEN_MSG);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-12 09:34:48 -04:00
|
|
|
static int sink_forward_session_init(struct appctx *appctx)
|
|
|
|
|
{
|
|
|
|
|
struct sink_forward_target *sft = appctx->svcctx;
|
|
|
|
|
struct stream *s;
|
|
|
|
|
struct sockaddr_storage *addr = NULL;
|
|
|
|
|
|
|
|
|
|
if (!sockaddr_alloc(&addr, &sft->srv->addr, sizeof(sft->srv->addr)))
|
|
|
|
|
goto out_error;
|
|
|
|
|
|
|
|
|
|
if (appctx_finalize_startup(appctx, sft->sink->forward_px, &BUF_NULL) == -1)
|
|
|
|
|
goto out_free_addr;
|
|
|
|
|
|
|
|
|
|
s = appctx_strm(appctx);
|
2022-05-17 13:40:40 -04:00
|
|
|
s->scb->dst = addr;
|
2022-05-17 13:44:42 -04:00
|
|
|
s->scb->flags |= SC_FL_NOLINGER;
|
2022-05-12 09:34:48 -04:00
|
|
|
|
|
|
|
|
s->target = &sft->srv->obj_type;
|
|
|
|
|
s->flags = SF_ASSIGNED;
|
|
|
|
|
|
|
|
|
|
s->do_log = NULL;
|
|
|
|
|
s->uniq_id = 0;
|
|
|
|
|
|
|
|
|
|
s->res.flags |= CF_READ_DONTWAIT;
|
|
|
|
|
/* for rto and rex to eternity to not expire on idle recv:
|
|
|
|
|
* We are using a syslog server.
|
|
|
|
|
*/
|
|
|
|
|
s->res.rto = TICK_ETERNITY;
|
|
|
|
|
s->res.rex = TICK_ETERNITY;
|
|
|
|
|
sft->appctx = appctx;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
out_free_addr:
|
|
|
|
|
sockaddr_free(&addr);
|
|
|
|
|
out_error:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2020-05-28 05:13:15 -04:00
|
|
|
|
|
|
|
|
static void sink_forward_session_release(struct appctx *appctx)
|
|
|
|
|
{
|
2022-05-04 14:42:23 -04:00
|
|
|
struct sink_forward_target *sft = appctx->svcctx;
|
2020-05-28 05:13:15 -04:00
|
|
|
|
|
|
|
|
if (!sft)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
HA_SPIN_LOCK(SFT_LOCK, &sft->lock);
|
|
|
|
|
if (sft->appctx == appctx)
|
|
|
|
|
__sink_forward_session_deinit(sft);
|
|
|
|
|
HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct applet sink_forward_applet = {
|
|
|
|
|
.obj_type = OBJ_TYPE_APPLET,
|
|
|
|
|
.name = "<SINKFWD>", /* used for logging */
|
|
|
|
|
.fct = sink_forward_io_handler,
|
2022-05-12 09:34:48 -04:00
|
|
|
.init = sink_forward_session_init,
|
2020-05-28 05:13:15 -04:00
|
|
|
.release = sink_forward_session_release,
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-29 19:42:45 -04:00
|
|
|
static struct applet sink_forward_oc_applet = {
|
|
|
|
|
.obj_type = OBJ_TYPE_APPLET,
|
|
|
|
|
.name = "<SINKFWDOC>", /* used for logging */
|
|
|
|
|
.fct = sink_forward_oc_io_handler,
|
2022-05-12 09:34:48 -04:00
|
|
|
.init = sink_forward_session_init,
|
2020-05-29 19:42:45 -04:00
|
|
|
.release = sink_forward_session_release,
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-28 05:13:15 -04:00
|
|
|
/*
|
|
|
|
|
* Create a new peer session in assigned state (connect will start automatically)
|
2022-05-04 14:42:23 -04:00
|
|
|
* It sets its context into appctx->svcctx.
|
2020-05-28 05:13:15 -04:00
|
|
|
*/
|
|
|
|
|
static struct appctx *sink_forward_session_create(struct sink *sink, struct sink_forward_target *sft)
|
|
|
|
|
{
|
|
|
|
|
struct appctx *appctx;
|
2020-05-29 19:42:45 -04:00
|
|
|
struct applet *applet = &sink_forward_applet;
|
|
|
|
|
|
|
|
|
|
if (sft->srv->log_proto == SRV_LOG_PROTO_OCTET_COUNTING)
|
|
|
|
|
applet = &sink_forward_oc_applet;
|
2020-05-28 05:13:15 -04:00
|
|
|
|
2022-05-16 11:09:48 -04:00
|
|
|
appctx = appctx_new_here(applet, NULL);
|
2022-01-19 08:50:11 -05:00
|
|
|
if (!appctx)
|
2022-03-23 06:01:09 -04:00
|
|
|
goto out_close;
|
2022-05-04 14:42:23 -04:00
|
|
|
appctx->svcctx = (void *)sft;
|
2020-05-28 05:13:15 -04:00
|
|
|
|
2022-05-12 09:34:48 -04:00
|
|
|
if (appctx_init(appctx) == -1)
|
2022-05-11 06:22:10 -04:00
|
|
|
goto out_free_appctx;
|
2022-03-23 06:01:09 -04:00
|
|
|
|
2020-05-28 05:13:15 -04:00
|
|
|
return appctx;
|
|
|
|
|
|
|
|
|
|
/* Error unrolling */
|
|
|
|
|
out_free_appctx:
|
2022-05-12 09:34:48 -04:00
|
|
|
appctx_free_on_early_error(appctx);
|
2020-05-28 05:13:15 -04:00
|
|
|
out_close:
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Task to handle connctions to forward servers
|
|
|
|
|
*/
|
2021-03-02 10:09:26 -05:00
|
|
|
static struct task *process_sink_forward(struct task * task, void *context, unsigned int state)
|
2020-05-28 05:13:15 -04:00
|
|
|
{
|
|
|
|
|
struct sink *sink = (struct sink *)context;
|
|
|
|
|
struct sink_forward_target *sft = sink->sft;
|
|
|
|
|
|
|
|
|
|
task->expire = TICK_ETERNITY;
|
|
|
|
|
|
|
|
|
|
if (!stopping) {
|
|
|
|
|
while (sft) {
|
|
|
|
|
HA_SPIN_LOCK(SFT_LOCK, &sft->lock);
|
|
|
|
|
/* if appctx is NULL, start a new session */
|
|
|
|
|
if (!sft->appctx)
|
|
|
|
|
sft->appctx = sink_forward_session_create(sink, sft);
|
|
|
|
|
HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
|
|
|
|
|
sft = sft->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
while (sft) {
|
|
|
|
|
HA_SPIN_LOCK(SFT_LOCK, &sft->lock);
|
|
|
|
|
/* awake applet to perform a clean close */
|
|
|
|
|
if (sft->appctx)
|
|
|
|
|
appctx_wakeup(sft->appctx);
|
|
|
|
|
HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
|
|
|
|
|
sft = sft->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return task;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* Init task to manage connctions to forward servers
|
|
|
|
|
*
|
|
|
|
|
* returns 0 in case of error.
|
|
|
|
|
*/
|
|
|
|
|
int sink_init_forward(struct sink *sink)
|
|
|
|
|
{
|
2021-10-01 12:23:30 -04:00
|
|
|
sink->forward_task = task_new_anywhere();
|
2020-05-28 05:13:15 -04:00
|
|
|
if (!sink->forward_task)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
sink->forward_task->process = process_sink_forward;
|
|
|
|
|
sink->forward_task->context = (void *)sink;
|
|
|
|
|
sink->forward_sighandler = signal_register_task(0, sink->forward_task, 0);
|
|
|
|
|
task_wakeup(sink->forward_task, TASK_WOKEN_INIT);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2022-08-31 12:52:17 -04:00
|
|
|
|
|
|
|
|
/* This tries to rotate a file-backed ring, but only if it contains contents.
|
|
|
|
|
* This way empty rings will not cause backups to be overwritten and it's safe
|
|
|
|
|
* to reload multiple times. That's only best effort, failures are silently
|
|
|
|
|
* ignored.
|
|
|
|
|
*/
|
|
|
|
|
void sink_rotate_file_backed_ring(const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct ring ring;
|
|
|
|
|
char *oldback;
|
|
|
|
|
int ret;
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
|
|
fd = open(name, O_RDONLY);
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* check for contents validity */
|
|
|
|
|
ret = read(fd, &ring, sizeof(ring));
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
|
|
if (ret != sizeof(ring))
|
|
|
|
|
goto rotate;
|
|
|
|
|
|
|
|
|
|
/* contents are present, we want to keep them => rotate. Note that
|
|
|
|
|
* an empty ring buffer has one byte (the marker).
|
|
|
|
|
*/
|
|
|
|
|
if (ring.buf.data > 1)
|
|
|
|
|
goto rotate;
|
|
|
|
|
|
|
|
|
|
/* nothing to keep, let's scratch the file and preserve the backup */
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
rotate:
|
|
|
|
|
oldback = NULL;
|
|
|
|
|
memprintf(&oldback, "%s.bak", name);
|
|
|
|
|
if (oldback) {
|
|
|
|
|
/* try to rename any possibly existing ring file to
|
|
|
|
|
* ".bak" and delete remains of older ones. This will
|
|
|
|
|
* ensure we don't wipe useful debug info upon restart.
|
|
|
|
|
*/
|
|
|
|
|
unlink(oldback);
|
|
|
|
|
if (rename(name, oldback) < 0)
|
|
|
|
|
unlink(oldback);
|
|
|
|
|
ha_free(&oldback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
/*
|
|
|
|
|
* Parse "ring" section and create corresponding sink buffer.
|
|
|
|
|
*
|
|
|
|
|
* The function returns 0 in success case, otherwise, it returns error
|
|
|
|
|
* flags.
|
|
|
|
|
*/
|
|
|
|
|
int cfg_parse_ring(const char *file, int linenum, char **args, int kwm)
|
|
|
|
|
{
|
|
|
|
|
int err_code = 0;
|
|
|
|
|
const char *inv;
|
|
|
|
|
size_t size = BUFSIZE;
|
2020-05-28 05:13:15 -04:00
|
|
|
struct proxy *p;
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
|
2022-08-11 10:12:11 -04:00
|
|
|
if (strcmp(args[0], "ring") == 0) { /* new ring section */
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
if (!*args[1]) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : missing ring name.\n", file, linenum);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inv = invalid_char(args[1]);
|
|
|
|
|
if (inv) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : invalid ring name '%s' (character '%c' is not permitted).\n", file, linenum, args[1], *inv);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sink_find(args[1])) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : sink named '%s' already exists.\n", file, linenum, args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-06 09:54:06 -04:00
|
|
|
cfg_sink = sink_new_buf(args[1], args[1], LOG_FORMAT_RAW, size);
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
if (!cfg_sink || cfg_sink->type != SINK_TYPE_BUFFER) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : unable to create a new sink buffer for ring '%s'.\n", file, linenum, args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
2020-05-28 05:13:15 -04:00
|
|
|
|
|
|
|
|
/* allocate new proxy to handle forwards */
|
|
|
|
|
p = calloc(1, sizeof *p);
|
|
|
|
|
if (!p) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init_new_proxy(p);
|
|
|
|
|
sink_setup_proxy(p);
|
|
|
|
|
p->parent = cfg_sink;
|
|
|
|
|
p->id = strdup(args[1]);
|
|
|
|
|
p->conf.args.file = p->conf.file = strdup(file);
|
|
|
|
|
p->conf.args.line = p->conf.line = linenum;
|
|
|
|
|
cfg_sink->forward_px = p;
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
}
|
|
|
|
|
else if (strcmp(args[0], "size") == 0) {
|
2022-08-11 10:12:11 -04:00
|
|
|
if (!cfg_sink || (cfg_sink->type != SINK_TYPE_BUFFER)) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : 'size' directive not usable with this type of sink.\n", file, linenum);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
size = atol(args[1]);
|
|
|
|
|
if (!size) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : invalid size '%s' for new sink buffer.\n", file, linenum, args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-11 10:38:20 -04:00
|
|
|
if (cfg_sink->store) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : cannot resize an already mapped file, please specify 'size' before 'backing-file'.\n", file, linenum);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-11 10:12:11 -04:00
|
|
|
if (size < cfg_sink->ctx.ring->buf.size) {
|
|
|
|
|
ha_warning("parsing [%s:%d] : ignoring new size '%llu' that is smaller than current size '%llu' for ring '%s'.\n",
|
|
|
|
|
file, linenum, (ullong)size, (ullong)cfg_sink->ctx.ring->buf.size, cfg_sink->name);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ring_resize(cfg_sink->ctx.ring, size)) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : fail to set sink buffer size '%llu' for ring '%s'.\n", file, linenum,
|
|
|
|
|
(ullong)cfg_sink->ctx.ring->buf.size, cfg_sink->name);
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-11 10:38:20 -04:00
|
|
|
else if (strcmp(args[0], "backing-file") == 0) {
|
|
|
|
|
/* This tries to mmap file <file> for size <size> and to use it as a backing store
|
|
|
|
|
* for ring <ring>. Existing data are delete. NULL is returned on error.
|
|
|
|
|
*/
|
|
|
|
|
const char *backing = args[1];
|
|
|
|
|
size_t size;
|
|
|
|
|
void *area;
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
|
|
if (!cfg_sink || (cfg_sink->type != SINK_TYPE_BUFFER)) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : 'backing-file' only usable with existing rings.\n", file, linenum);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cfg_sink->store) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : 'backing-file' already specified for ring '%s' (was '%s').\n", file, linenum, cfg_sink->name, cfg_sink->store);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-31 12:52:17 -04:00
|
|
|
/* let's check if the file exists and is not empty. That's the
|
|
|
|
|
* only condition under which we'll trigger a rotate, so that
|
|
|
|
|
* config checks, reloads, or restarts that don't emit anything
|
|
|
|
|
* do not rotate it again.
|
|
|
|
|
*/
|
|
|
|
|
sink_rotate_file_backed_ring(backing);
|
2022-08-12 09:38:20 -04:00
|
|
|
|
2022-08-12 09:03:12 -04:00
|
|
|
fd = open(backing, O_RDWR | O_CREAT, 0600);
|
2022-08-11 10:38:20 -04:00
|
|
|
if (fd < 0) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : cannot open backing-file '%s' for ring '%s': %s.\n", file, linenum, backing, cfg_sink->name, strerror(errno));
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size = (cfg_sink->ctx.ring->buf.size + 4095UL) & -4096UL;
|
|
|
|
|
if (ftruncate(fd, size) != 0) {
|
|
|
|
|
close(fd);
|
|
|
|
|
ha_alert("parsing [%s:%d] : could not adjust size of backing-file for ring '%s': %s.\n", file, linenum, cfg_sink->name, strerror(errno));
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
area = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
|
|
|
if (area == MAP_FAILED) {
|
|
|
|
|
close(fd);
|
|
|
|
|
ha_alert("parsing [%s:%d] : failed to use '%s' as a backing file for ring '%s': %s.\n", file, linenum, backing, cfg_sink->name, strerror(errno));
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* we don't need the file anymore */
|
|
|
|
|
close(fd);
|
|
|
|
|
cfg_sink->store = strdup(backing);
|
|
|
|
|
|
|
|
|
|
/* never fails */
|
|
|
|
|
ring_free(cfg_sink->ctx.ring);
|
|
|
|
|
cfg_sink->ctx.ring = ring_make_from_area(area, size);
|
|
|
|
|
}
|
2020-05-28 05:13:15 -04:00
|
|
|
else if (strcmp(args[0],"server") == 0) {
|
2022-11-16 12:56:34 -05:00
|
|
|
if (!cfg_sink || (cfg_sink->type != SINK_TYPE_BUFFER)) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : unable to create server '%s'.\n", file, linenum, args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 10:36:46 -05:00
|
|
|
err_code |= parse_server(file, linenum, args, cfg_sink->forward_px, NULL,
|
|
|
|
|
SRV_PARSE_PARSE_ADDR|SRV_PARSE_INITIAL_RESOLVE);
|
2020-05-28 05:13:15 -04:00
|
|
|
}
|
|
|
|
|
else if (strcmp(args[0],"timeout") == 0) {
|
|
|
|
|
if (!cfg_sink || !cfg_sink->forward_px) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : unable to set timeout '%s'.\n", file, linenum, args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strcmp(args[1], "connect") == 0 ||
|
|
|
|
|
strcmp(args[1], "server") == 0) {
|
|
|
|
|
const char *res;
|
|
|
|
|
unsigned int tout;
|
|
|
|
|
|
|
|
|
|
if (!*args[2]) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
|
|
|
|
|
file, linenum, args[0], args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
res = parse_time_err(args[2], &tout, TIME_UNIT_MS);
|
|
|
|
|
if (res == PARSE_TIME_OVER) {
|
|
|
|
|
ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s %s>, maximum value is 2147483647 ms (~24.8 days).\n",
|
|
|
|
|
file, linenum, args[2], args[0], args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
else if (res == PARSE_TIME_UNDER) {
|
|
|
|
|
ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s %s>, minimum non-null value is 1 ms.\n",
|
|
|
|
|
file, linenum, args[2], args[0], args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
else if (res) {
|
|
|
|
|
ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n",
|
|
|
|
|
file, linenum, *res, args[0], args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
2022-10-19 10:26:21 -04:00
|
|
|
if (args[1][0] == 'c')
|
2020-05-28 05:13:15 -04:00
|
|
|
cfg_sink->forward_px->timeout.connect = tout;
|
|
|
|
|
else
|
|
|
|
|
cfg_sink->forward_px->timeout.server = tout;
|
|
|
|
|
}
|
|
|
|
|
}
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
else if (strcmp(args[0],"format") == 0) {
|
|
|
|
|
if (!cfg_sink) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : unable to set format '%s'.\n", file, linenum, args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-06 09:54:06 -04:00
|
|
|
cfg_sink->fmt = get_log_format(args[1]);
|
|
|
|
|
if (cfg_sink->fmt == LOG_FORMAT_UNSPEC) {
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
ha_alert("parsing [%s:%d] : unknown format '%s'.\n", file, linenum, args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp(args[0],"maxlen") == 0) {
|
|
|
|
|
if (!cfg_sink) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : unable to set event max length '%s'.\n", file, linenum, args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg_sink->maxlen = atol(args[1]);
|
|
|
|
|
if (!cfg_sink->maxlen) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : invalid size '%s' for new sink buffer.\n", file, linenum, args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp(args[0],"description") == 0) {
|
|
|
|
|
if (!cfg_sink) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : unable to set description '%s'.\n", file, linenum, args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!*args[1]) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : missing ring description text.\n", file, linenum);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(cfg_sink->desc);
|
|
|
|
|
|
|
|
|
|
cfg_sink->desc = strdup(args[1]);
|
|
|
|
|
if (!cfg_sink->desc) {
|
|
|
|
|
ha_alert("parsing [%s:%d] : fail to set description '%s'.\n", file, linenum, args[1]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-29 09:47:52 -04:00
|
|
|
else {
|
|
|
|
|
ha_alert("parsing [%s:%d] : unknown statement '%s'.\n", file, linenum, args[0]);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
|
|
|
|
|
err:
|
|
|
|
|
return err_code;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 04:41:36 -04:00
|
|
|
/* Creates an new sink buffer from a log server.
|
|
|
|
|
*
|
|
|
|
|
* It uses the logsrvaddress to declare a forward
|
|
|
|
|
* server for this buffer. And it initializes the
|
|
|
|
|
* forwarding.
|
|
|
|
|
*
|
|
|
|
|
* The function returns a pointer on the
|
|
|
|
|
* allocated struct sink if allocate
|
|
|
|
|
* and initialize succeed, else if it fails
|
|
|
|
|
* it returns NULL.
|
|
|
|
|
*
|
|
|
|
|
* Note: the sink is created using the name
|
2021-04-24 04:25:42 -04:00
|
|
|
* specified into logsrv->ring_name
|
2021-04-02 04:41:36 -04:00
|
|
|
*/
|
|
|
|
|
struct sink *sink_new_from_logsrv(struct logsrv *logsrv)
|
|
|
|
|
{
|
|
|
|
|
struct proxy *p = NULL;
|
|
|
|
|
struct sink *sink = NULL;
|
|
|
|
|
struct server *srv = NULL;
|
|
|
|
|
struct sink_forward_target *sft = NULL;
|
|
|
|
|
|
|
|
|
|
/* allocate new proxy to handle
|
|
|
|
|
* forward to a stream server
|
|
|
|
|
*/
|
|
|
|
|
p = calloc(1, sizeof *p);
|
|
|
|
|
if (!p) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init_new_proxy(p);
|
|
|
|
|
sink_setup_proxy(p);
|
|
|
|
|
p->id = strdup(logsrv->ring_name);
|
|
|
|
|
p->conf.args.file = p->conf.file = strdup(logsrv->conf.file);
|
|
|
|
|
p->conf.args.line = p->conf.line = logsrv->conf.line;
|
|
|
|
|
|
2022-10-24 09:53:01 -04:00
|
|
|
/* Set default connect and server timeout */
|
|
|
|
|
p->timeout.connect = MS_TO_TICKS(1000);
|
|
|
|
|
p->timeout.server = MS_TO_TICKS(5000);
|
|
|
|
|
|
2021-04-02 04:41:36 -04:00
|
|
|
/* allocate a new server to forward messages
|
|
|
|
|
* from ring buffer
|
|
|
|
|
*/
|
|
|
|
|
srv = new_server(p);
|
|
|
|
|
if (!srv)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
/* init server */
|
|
|
|
|
srv->id = strdup(logsrv->ring_name);
|
|
|
|
|
srv->conf.file = strdup(logsrv->conf.file);
|
|
|
|
|
srv->conf.line = logsrv->conf.line;
|
|
|
|
|
srv->addr = logsrv->addr;
|
|
|
|
|
srv->svc_port = get_host_port(&logsrv->addr);
|
|
|
|
|
HA_SPIN_INIT(&srv->lock);
|
|
|
|
|
|
|
|
|
|
/* process per thread init */
|
2021-06-15 09:33:20 -04:00
|
|
|
if (srv_init_per_thr(srv) == -1)
|
2021-04-02 04:41:36 -04:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
/* the servers are linked backwards
|
|
|
|
|
* first into proxy
|
|
|
|
|
*/
|
|
|
|
|
p->srv = srv;
|
|
|
|
|
srv->next = p->srv;
|
|
|
|
|
|
|
|
|
|
/* allocate sink_forward_target descriptor */
|
|
|
|
|
sft = calloc(1, sizeof(*sft));
|
|
|
|
|
if (!sft)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
/* init sink_forward_target offset */
|
|
|
|
|
sft->srv = srv;
|
|
|
|
|
sft->appctx = NULL;
|
|
|
|
|
sft->ofs = ~0;
|
|
|
|
|
HA_SPIN_INIT(&sft->lock);
|
|
|
|
|
|
2021-04-24 04:25:42 -04:00
|
|
|
/* prepare description for the sink */
|
2021-04-02 04:41:36 -04:00
|
|
|
chunk_reset(&trash);
|
|
|
|
|
chunk_printf(&trash, "created from logserver declared into '%s' at line %d", logsrv->conf.file, logsrv->conf.line);
|
|
|
|
|
|
|
|
|
|
/* allocate a new sink buffer */
|
|
|
|
|
sink = sink_new_buf(logsrv->ring_name, trash.area, logsrv->format, BUFSIZE);
|
|
|
|
|
if (!sink || sink->type != SINK_TYPE_BUFFER) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* link sink_forward_target to proxy */
|
|
|
|
|
sink->forward_px = p;
|
|
|
|
|
p->parent = sink;
|
|
|
|
|
|
|
|
|
|
/* insert into sink_forward_targets
|
|
|
|
|
* list into sink
|
|
|
|
|
*/
|
2022-05-12 08:50:09 -04:00
|
|
|
sft->sink = sink;
|
2021-04-02 04:41:36 -04:00
|
|
|
sft->next = sink->sft;
|
|
|
|
|
sink->sft = sft;
|
|
|
|
|
|
|
|
|
|
/* mark server as an attached reader to the ring */
|
|
|
|
|
if (!ring_attach(sink->ctx.ring)) {
|
|
|
|
|
/* should never fail since there is
|
|
|
|
|
* only one reader
|
|
|
|
|
*/
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* initialize sink buffer forwarding */
|
|
|
|
|
if (!sink_init_forward(sink))
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
/* reset familyt of logsrv to consider the ring buffer target */
|
|
|
|
|
logsrv->addr.ss_family = AF_UNSPEC;
|
|
|
|
|
|
|
|
|
|
return sink;
|
|
|
|
|
error:
|
|
|
|
|
if (p) {
|
|
|
|
|
if (p->id)
|
|
|
|
|
free(p->id);
|
|
|
|
|
if (p->conf.file)
|
|
|
|
|
free(p->conf.file);
|
|
|
|
|
|
|
|
|
|
free(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (srv) {
|
|
|
|
|
if (srv->id)
|
|
|
|
|
free(srv->id);
|
|
|
|
|
if (srv->conf.file)
|
|
|
|
|
free((void *)srv->conf.file);
|
|
|
|
|
if (srv->per_thr)
|
|
|
|
|
free(srv->per_thr);
|
|
|
|
|
free(srv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sft)
|
|
|
|
|
free(sft);
|
|
|
|
|
|
|
|
|
|
if (sink) {
|
|
|
|
|
if (sink->ctx.ring)
|
|
|
|
|
ring_free(sink->ctx.ring);
|
|
|
|
|
|
2021-04-21 01:32:39 -04:00
|
|
|
LIST_DELETE(&sink->sink_list);
|
2021-04-02 04:41:36 -04:00
|
|
|
free(sink->name);
|
|
|
|
|
free(sink->desc);
|
|
|
|
|
free(sink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
/*
|
|
|
|
|
* Post parsing "ring" section.
|
|
|
|
|
*
|
|
|
|
|
* The function returns 0 in success case, otherwise, it returns error
|
|
|
|
|
* flags.
|
|
|
|
|
*/
|
|
|
|
|
int cfg_post_parse_ring()
|
|
|
|
|
{
|
|
|
|
|
int err_code = 0;
|
2020-05-28 05:13:15 -04:00
|
|
|
struct server *srv;
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
|
|
|
|
|
if (cfg_sink && (cfg_sink->type == SINK_TYPE_BUFFER)) {
|
|
|
|
|
if (cfg_sink->maxlen > b_size(&cfg_sink->ctx.ring->buf)) {
|
|
|
|
|
ha_warning("ring '%s' event max length '%u' exceeds size, forced to size '%lu'.\n",
|
2020-06-02 06:00:46 -04:00
|
|
|
cfg_sink->name, cfg_sink->maxlen, (unsigned long)b_size(&cfg_sink->ctx.ring->buf));
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
cfg_sink->maxlen = b_size(&cfg_sink->ctx.ring->buf);
|
|
|
|
|
err_code |= ERR_ALERT;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 05:13:15 -04:00
|
|
|
/* prepare forward server descriptors */
|
|
|
|
|
if (cfg_sink->forward_px) {
|
|
|
|
|
srv = cfg_sink->forward_px->srv;
|
|
|
|
|
while (srv) {
|
|
|
|
|
struct sink_forward_target *sft;
|
|
|
|
|
|
|
|
|
|
/* allocate sink_forward_target descriptor */
|
|
|
|
|
sft = calloc(1, sizeof(*sft));
|
|
|
|
|
if (!sft) {
|
|
|
|
|
ha_alert("memory allocation error initializing server '%s' in ring '%s'.\n",srv->id, cfg_sink->name);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
sft->srv = srv;
|
|
|
|
|
sft->appctx = NULL;
|
|
|
|
|
sft->ofs = ~0; /* init ring offset */
|
2022-08-04 10:00:13 -04:00
|
|
|
sft->sink = cfg_sink;
|
2020-05-28 05:13:15 -04:00
|
|
|
sft->next = cfg_sink->sft;
|
|
|
|
|
HA_SPIN_INIT(&sft->lock);
|
|
|
|
|
|
|
|
|
|
/* mark server attached to the ring */
|
|
|
|
|
if (!ring_attach(cfg_sink->ctx.ring)) {
|
|
|
|
|
ha_alert("server '%s' sets too many watchers > 255 on ring '%s'.\n", srv->id, cfg_sink->name);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
}
|
|
|
|
|
cfg_sink->sft = sft;
|
|
|
|
|
srv = srv->next;
|
|
|
|
|
}
|
|
|
|
|
sink_init_forward(cfg_sink);
|
|
|
|
|
}
|
|
|
|
|
}
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
cfg_sink = NULL;
|
|
|
|
|
|
|
|
|
|
return err_code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* resolve sink names at end of config. Returns 0 on success otherwise error
|
|
|
|
|
* flags.
|
|
|
|
|
*/
|
|
|
|
|
int post_sink_resolve()
|
|
|
|
|
{
|
2020-11-06 09:24:23 -05:00
|
|
|
int err_code = ERR_NONE;
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
struct logsrv *logsrv, *logb;
|
|
|
|
|
struct sink *sink;
|
|
|
|
|
struct proxy *px;
|
|
|
|
|
|
|
|
|
|
list_for_each_entry_safe(logsrv, logb, &global.logsrvs, list) {
|
|
|
|
|
if (logsrv->type == LOG_TARGET_BUFFER) {
|
|
|
|
|
sink = sink_find(logsrv->ring_name);
|
2021-04-02 04:41:36 -04:00
|
|
|
if (!sink) {
|
|
|
|
|
/* LOG_TARGET_BUFFER but !AF_UNSPEC
|
|
|
|
|
* means we must allocate a sink
|
|
|
|
|
* buffer to send messages to this logsrv
|
|
|
|
|
*/
|
|
|
|
|
if (logsrv->addr.ss_family != AF_UNSPEC) {
|
|
|
|
|
sink = sink_new_from_logsrv(logsrv);
|
|
|
|
|
if (!sink) {
|
|
|
|
|
ha_alert("global stream log server declared in file '%s' at line %d cannot be initialized'.\n",
|
|
|
|
|
logsrv->conf.file, logsrv->conf.line);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ha_alert("global log server declared in file '%s' at line %d uses unknown ring named '%s'.\n",
|
|
|
|
|
logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (sink->type != SINK_TYPE_BUFFER) {
|
|
|
|
|
ha_alert("global log server declared in file '%s' at line %d uses incompatible ring '%s'.\n",
|
|
|
|
|
logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
}
|
|
|
|
|
logsrv->sink = sink;
|
|
|
|
|
}
|
2021-04-02 04:41:36 -04:00
|
|
|
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (px = proxies_list; px; px = px->next) {
|
|
|
|
|
list_for_each_entry_safe(logsrv, logb, &px->logsrvs, list) {
|
|
|
|
|
if (logsrv->type == LOG_TARGET_BUFFER) {
|
|
|
|
|
sink = sink_find(logsrv->ring_name);
|
2021-04-02 04:41:36 -04:00
|
|
|
if (!sink) {
|
|
|
|
|
/* LOG_TARGET_BUFFER but !AF_UNSPEC
|
|
|
|
|
* means we must allocate a sink
|
|
|
|
|
* buffer to send messages to this logsrv
|
|
|
|
|
*/
|
|
|
|
|
if (logsrv->addr.ss_family != AF_UNSPEC) {
|
|
|
|
|
sink = sink_new_from_logsrv(logsrv);
|
|
|
|
|
if (!sink) {
|
|
|
|
|
ha_alert("log server declared in proxy section '%s' file '%s' at line %d cannot be initialized'.\n",
|
|
|
|
|
px->id, logsrv->conf.file, logsrv->conf.line);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ha_alert("log server declared in proxy section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n",
|
|
|
|
|
px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (sink->type != SINK_TYPE_BUFFER) {
|
|
|
|
|
ha_alert("log server declared in proxy section '%s' in file '%s' at line %d uses incomatible ring named '%s'.\n",
|
|
|
|
|
px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
}
|
|
|
|
|
logsrv->sink = sink;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-07 08:19:42 -04:00
|
|
|
|
|
|
|
|
for (px = cfg_log_forward; px; px = px->next) {
|
|
|
|
|
list_for_each_entry_safe(logsrv, logb, &px->logsrvs, list) {
|
|
|
|
|
if (logsrv->type == LOG_TARGET_BUFFER) {
|
|
|
|
|
sink = sink_find(logsrv->ring_name);
|
2021-04-02 04:41:36 -04:00
|
|
|
if (!sink) {
|
|
|
|
|
/* LOG_TARGET_BUFFER but !AF_UNSPEC
|
|
|
|
|
* means we must allocate a sink
|
|
|
|
|
* buffer to send messages to this logsrv
|
|
|
|
|
*/
|
|
|
|
|
if (logsrv->addr.ss_family != AF_UNSPEC) {
|
|
|
|
|
sink = sink_new_from_logsrv(logsrv);
|
|
|
|
|
if (!sink) {
|
|
|
|
|
ha_alert("log server declared in log-forward section '%s' file '%s' at line %d cannot be initialized'.\n",
|
|
|
|
|
px->id, logsrv->conf.file, logsrv->conf.line);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ha_alert("log server declared in log-forward section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n",
|
|
|
|
|
px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
|
|
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (sink->type != SINK_TYPE_BUFFER) {
|
|
|
|
|
ha_alert("log server declared in log-forward section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n",
|
|
|
|
|
px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
|
2020-07-07 08:19:42 -04:00
|
|
|
err_code |= ERR_ALERT | ERR_FATAL;
|
|
|
|
|
}
|
|
|
|
|
logsrv->sink = sink;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
return err_code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-20 05:57:52 -04:00
|
|
|
static void sink_init()
|
|
|
|
|
{
|
2020-07-06 09:54:06 -04:00
|
|
|
sink_new_fd("stdout", "standard output (fd#1)", LOG_FORMAT_RAW, 1);
|
|
|
|
|
sink_new_fd("stderr", "standard output (fd#2)", LOG_FORMAT_RAW, 2);
|
|
|
|
|
sink_new_buf("buf0", "in-memory ring buffer", LOG_FORMAT_TIMED, 1048576);
|
2019-08-23 09:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void sink_deinit()
|
|
|
|
|
{
|
|
|
|
|
struct sink *sink, *sb;
|
|
|
|
|
|
|
|
|
|
list_for_each_entry_safe(sink, sb, &sink_list, sink_list) {
|
2022-08-11 10:38:20 -04:00
|
|
|
if (sink->type == SINK_TYPE_BUFFER) {
|
|
|
|
|
if (sink->store)
|
|
|
|
|
munmap(sink->ctx.ring->buf.area, sink->ctx.ring->buf.size);
|
|
|
|
|
else
|
|
|
|
|
ring_free(sink->ctx.ring);
|
|
|
|
|
}
|
2021-04-21 01:32:39 -04:00
|
|
|
LIST_DELETE(&sink->sink_list);
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
free(sink->name);
|
|
|
|
|
free(sink->desc);
|
2019-08-23 09:47:49 -04:00
|
|
|
free(sink);
|
|
|
|
|
}
|
2019-08-20 05:57:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INITCALL0(STG_REGISTER, sink_init);
|
2019-08-23 09:47:49 -04:00
|
|
|
REGISTER_POST_DEINIT(sink_deinit);
|
2019-08-20 05:57:52 -04:00
|
|
|
|
2019-08-26 12:17:04 -04:00
|
|
|
static struct cli_kw_list cli_kws = {{ },{
|
2021-05-07 05:38:37 -04:00
|
|
|
{ { "show", "events", NULL }, "show events [<sink>] [-w] [-n] : show event sink state", cli_parse_show_events, NULL, NULL },
|
2019-08-26 12:17:04 -04:00
|
|
|
{{},}
|
|
|
|
|
}};
|
|
|
|
|
|
|
|
|
|
INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
|
|
|
|
|
|
MEDIUM: ring: new section ring to declare custom ring buffers.
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to be
used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr). This
is the default.
rfc3164 The RFC3164 syslog message format. This is the default.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the systemd
logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
2020-05-25 09:01:04 -04:00
|
|
|
/* config parsers for this section */
|
|
|
|
|
REGISTER_CONFIG_SECTION("ring", cfg_parse_ring, cfg_post_parse_ring);
|
|
|
|
|
REGISTER_POST_CHECK(post_sink_resolve);
|
|
|
|
|
|
MINOR: sink: create definitions a minimal code for event sinks
The principle will be to be able to dispatch events to various destinations
called "sinks". This is already done in part in logs where log servers can
be either a UDP socket or a file descriptor. This will be needed with the
new trace subsystem where we may also want to add ring buffers. And it turns
out that all such destinations make sense at all places. Logs may need to be
sent to a TCP server via a ring buffer, or consulted from the CLI. Trace
events may need to be sent to stdout/stderr as well as to remote log servers.
This patch creates a new structure "sink" aiming at addressing these similar
needs. The goal is to merge together what is common to all of them, such as
the output format, the dropped events count, etc, and also keep separately
the target identification (network address, file descriptor). Provisions
were made to have a "waiter" on the sink. For a TCP log server it will be
the task to wake up after writing to the log buffer. For a ring buffer, it
could be the list of watchers on the CLI running a "tail" operation and
waiting for new events. A lock was also placed in the struct since many
operations will require some locking, including the FD ones. The output
formats covers those in use by logs and two extra ones prepending the ISO
time in front of the message (convenient for stdio/buffer).
For now only the generic infrastructure is present, no type-specific
output is implemented. There's the sink_write() function which prepares
and formats a message to be sent, trying hard to avoid copies and only
using pointer manipulation, where the type-specific code just has to be
added. Dropped messages are already counted (for now 100% drop). The
message is put into an iovec array as it will be trivial to use with
file descriptors and sockets.
2019-08-11 10:38:56 -04:00
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* c-indent-level: 8
|
|
|
|
|
* c-basic-offset: 8
|
|
|
|
|
* End:
|
|
|
|
|
*/
|