Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: syslog-ng-ctl: add start and stop internal log message command. #2840

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mehul-m-prajapati
Copy link
Contributor

@mehul-m-prajapati mehul-m-prajapati commented Jul 21, 2019

Hi,

This patch will add 2 new syslog-ng-ctl commands,

  1. syslog-ng-ctl internal-logs --start (Start collecting internal log messages)
  2. syslog-ng-ctl internal-logs --stop (Display collected internal log messages and stop further collection of messages)

Later, I will use these commands in debun to save internal log messages in a file.

To set message levels,

syslog-ng-ctl debug --set 1
syslog-ng-ctl internal-logs start
#wait 
syslog-ng-ctl stop
syslog-ng-ctl debug --set 0

resolves mehul-m-prajapati/gsoc-debun-tool#5

Thanks,
Mehul

@kira-syslogng
Copy link
Contributor

This user does not have permission to start the build. Can one of the admins verify this patch and start the build?
(admin: you have the next options (make sure you checked the code):
"ok to test" to accept this pull request (and further changes) for testing
"test this please" for a one time test run
"add to whitelist" add author of a Pull Request to whitelist (globally, be careful, it means this user can trigger kira for any PR)
do nothing -> CI won't start)

@kira-syslogng
Copy link
Contributor

Build FAILURE

@mehul-m-prajapati mehul-m-prajapati changed the title syslog-ng-ctl: add start and stop internal log messgages command. [WIP] syslog-ng-ctl: add start and stop internal log messgages command. Jul 22, 2019
@kira-syslogng
Copy link
Contributor

Build FAILURE

@kira-syslogng
Copy link
Contributor

Build FAILURE

lib/afinter.c Outdated Show resolved Hide resolved
@mehul-m-prajapati
Copy link
Contributor Author

``

Could you please explain the reason for this change?

With this change, it will collect logs at higher levels. I think it was one of the requirements of this feature.

@mehul-m-prajapati
Copy link
Contributor Author

mehul-m-prajapati commented Jul 23, 2019

This is inheritly racy, you get messages and stop collection. Any number of message could arrive between the two call. First you have to stop the collection and than collect the logs. (or done in one step)

ok. I will first stop the collection and then get the internal message logs

@kira-syslogng
Copy link
Contributor

Build FAILURE

@Kokan
Copy link
Collaborator

Kokan commented Jul 24, 2019

``

Could you please explain the reason for this change?

With this change, it will collect logs at higher levels. I think it was one of the requirements of this feature.

Yes, it is. But the question how much higher should it be is still open, well it gave an answer as highest. But imho that is not good enough. So it should be up to the user to decide, it could be configured like syslog-ng-ctl internal-logs start --debug/--warning.
On the other hand this is kinda a possibility already via syslog-ng-ctl:

Syntax: /tmp/install/sbin/syslog-ng-ctl <command> [options]
Possible commands are:
...
    verbose              Enable/query verbose messages
    debug                Enable/query debug messages
    trace                Enable/query trace messages
...

Which is good enough for now, one could simply do:

syslog-ng-ctl debug --set 1
syslog-ng-ctl internal-logs start
#wait 
syslog-ng-ctl stop
syslog-ng-ctl debug --set 0

lib/afinter.c Show resolved Hide resolved
@kira-syslogng
Copy link
Contributor

Build SUCCESS

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@mehul-m-prajapati mehul-m-prajapati changed the title [WIP] syslog-ng-ctl: add start and stop internal log messgages command. syslog-ng-ctl: add start and stop internal log messgages command. Jul 28, 2019
@lbudai lbudai self-requested a review July 31, 2019 08:38
@mehul-m-prajapati mehul-m-prajapati changed the title syslog-ng-ctl: add start and stop internal log message command. WIP: syslog-ng-ctl: add start and stop internal log message command. Jan 4, 2020
@kira-syslogng
Copy link
Contributor

Build FAILURE

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@Kokan Kokan changed the title WIP: syslog-ng-ctl: add start and stop internal log message command. syslog-ng-ctl: add start and stop internal log message command. Feb 10, 2020
@kira-syslogng
Copy link
Contributor

Build SUCCESS

@kira-syslogng
Copy link
Contributor

Build SUCCESS

while (!g_queue_is_empty(internal_msg_queue))
{
msg = g_queue_pop_head(internal_msg_queue);
msg_text = log_msg_get_value(msg, LM_V_MESSAGE, NULL);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest doing something similar that is used in dqtool (dqtool.c). Dqtool allows specifying a template function as cli parameter. You can use that input to format the message. If template function is not provided, I think the same default can be fine that is used in dqtool: log_template_compile(template, "$DATE $HOST $MSGHDR$MSG\n", NULL);.

log_writer_format_log would be somewhat difficult to use, as you would need a (at least partially) initialized LogWriter instance.

control_internal_logs(ControlConnection *cc, GString *command, gpointer user_data)
{
GString *result = g_string_new("");
gchar **arguments = g_strsplit(command->str, " ", 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be freed in the end with g_strfreev().

slng_internal(int argc, char *argv[], const gchar *mode, GOptionContext *ctx)
{
GString *cmd = g_string_new("");

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If neither start or stop are provided, I think we should write an error. Now the cli exits silently. Well the error code is not zero, so not entirely silently. Still, we could write something out.

else if (config_options_stop)
g_string_assign(cmd, "INTERLOGS STOP");
else
return 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not allow that start and stop are provided at the same time.

else if (g_str_equal(arguments[1], "STOP"))
{
afinter_stop_live_collection();
afinter_get_collected_messages(result);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get assertion error with the following case:

@version: 3.25

log {
    source { example-msg-generator(num(1)); };
    destination { file(/dev/stdout); };
};

Start syslog-ng with ./syslog-ng -Fe -f ../etc/internal.conf.

After calling start, and then stop, syslog-ng emits:

[2020-03-03T13:05:58.048621] g_queue_is_empty: assertion 'queue != NULL' failed

}

if (!strlen(result->str))
g_string_assign(result, "No live messages collected");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log collection does not work for me some reason. I am generating messages continuously with:

@version: 3.25

log {
    source { example-msg-generator(); };
    destination { file(/dev/stdout); };
};

Starting syslog-ng with -Fevdt, I can see internal logs generating continuously. However when I start the cli, wait a few seconds, then stop it, I only see this error message: No live messages collected.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. If I start syslog-ng in foreground, then there will be no internal messages.

Could you please handle as error if someone wants to start the log collection while syslog-ng is running in foreground? Others can run into this as well.


g_static_mutex_lock(&internal_msg_lock);

while (!g_queue_is_empty(internal_msg_queue))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I steadily get deadlock in the following case:

@version: 3.25

log {
    source { example-msg-generator(); };
    destination { file(/dev/stdout); };
};

Start syslog-ng with ./syslog-ng -F -f ../etc/internal.conf (! just -F, not -Fdt. With -Fdt, I did not see deadlock yet).

After start and stop, syslog-ng hangs. I crashed syslog-ng with segv (kill -segv ), then checked the core dump with gdb: I see syslog-ng hangs while trying to grab a lock during pushing internal message. Moving up in the stack, the message is triggered by g_queue_is_empty (through a g_log call). The hint is internal_msg_queue is empty for some reason, and I think the code wants to emit the same assert that I mentioned in the other comment. So maybe the root cause and the fix is the same.


while (!g_queue_is_empty(internal_msg_queue))
{
msg = g_queue_pop_head(internal_msg_queue);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message needs to be unreffed using log_msg_unref.

@furiel
Copy link
Collaborator

furiel commented Mar 16, 2020

@mehul-m-prajapati I think this PR is close to the finish line. Did you have time to look into the review comments? Is there anything to be clarified? Let me know if you need any help.

@mehul-m-prajapati
Copy link
Contributor Author

mehul-m-prajapati commented Mar 16, 2020

@mehul-m-prajapati I think this PR is close to the finish line. Did you have time to look into the review comments? Is there anything to be clarified? Let me know if you need any help.

Hi @furiel ,

Thanks for taking time to review my PR. I will make changes in this week.

@mehul-m-prajapati mehul-m-prajapati changed the title syslog-ng-ctl: add start and stop internal log message command. WIP: syslog-ng-ctl: add start and stop internal log message command. Mar 22, 2020
afinter: add functions to collect internal messages at higher level.

Signed-off-by: Mehul Prajapati <mehul.encs@gmail.com>
@kira-syslogng
Copy link
Contributor

Build SUCCESS

@MrAnno MrAnno removed the request for review from lbudai February 12, 2022 20:40
@MrAnno MrAnno marked this pull request as draft February 12, 2022 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Collect internal logs with possibly higher log level
8 participants