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

Refs #22559 - Add parameters for structured logging #631

Merged
merged 1 commit into from
Apr 17, 2018

Conversation

ekohl
Copy link
Member

@ekohl ekohl commented Mar 27, 2018

No description provided.

@ekohl ekohl changed the title Refs #22493 - Add parameters for structured logging [WIP] Refs #22493 - Add parameters for structured logging Mar 27, 2018
@ekohl
Copy link
Member Author

ekohl commented Mar 27, 2018

This will also need code to install packages if any logger other than file is used.

Copy link
Member

@lzap lzap left a comment

Choose a reason for hiding this comment

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

Issue number must be 22559.

@@ -253,6 +253,8 @@

# Application logging
$logging_level = 'info'
$logging_type = 'file'
$logging_layout = 'pattern'
Copy link
Member

Choose a reason for hiding this comment

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

Default was multiline_pattern, but I am fine with switching to pattern. The difference is that the former adds | characters at the beginning of each line, which is useful for development but in syslog/journald this might not be the best thing to do. So +1.

Copy link
Member Author

Choose a reason for hiding this comment

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

Was multiline_pattern also used before structured logging was introduced? I thought it was pattern so stayed with it here.

Copy link
Member

Choose a reason for hiding this comment

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

It was the default, yes. I mean for development setup, not sure about production, but we did not explicitly set it so it was the default (so yes)? I actually like pattern more than the other one - it's cleaner.

@@ -253,6 +253,8 @@

# Application logging
$logging_level = 'info'
$logging_type = 'file'
Copy link
Member

Choose a reason for hiding this comment

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

This is indeed the most sane default - everything stays the same for production instance.

But logging to files is considered bad practice, except some corner cases (e.g. apache httpd access logs) using standard logging mechanisms should be preferred. I was hoping to default to journald (if present), syslog (otherwise) and just dropping /etc/rsyslog.d/foreman.conf configuration file and alerting daemon to reload (similarly for syslog-ng). If that's too complex in Puppet, we can just leave file logging for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is indeed the most sane default - everything stays the same for production instance.

That was indeed exactly what I thought, also because I can't quite oversee what else is affected. Start with configuration options and safe defaults.

If journald is just drop in, we could use facts to determine if systemd is used. I'm hesitant to start managing syslog since that can be fairly complex and more up to the admin to set up. That's why I'd fall back to file if systemd is not used. My plan was to revisit the defaults later.

Copy link
Member

Choose a reason for hiding this comment

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

The question is how or when do we find out it's now safe to change the default, too bad didn't have this in the beginning of 1.18 dev window. Would it make sense to change the default just after we branch out?

I agree that we shouldn't manage syslog but dropping a oneliner to /etc/rsyslog.d/foreman.conf would be acceptable I think?

Copy link
Member Author

Choose a reason for hiding this comment

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

The question is how or when do we find out it's now safe to change the default, too bad didn't have this in the beginning of 1.18 dev window. Would it make sense to change the default just after we branch out?

For me it depends on whether journald is a drop in replacement:

  • Does journald also log to a file?
  • Can foreman-debug extract logs from journald?

I agree that we shouldn't manage syslog but dropping a oneliner to /etc/rsyslog.d/foreman.conf would be acceptable I think?

The difficulty is that we can't rely on any syslog implementation. I can imagine users are using syslog-ng for example. Then we also need to support that. Suddenly we have a few extra parameters for things that IMHO belong in a profile module. Will we manage the syslog daemon as well for example. We've worked hard to keep that out of puppet-foreman. It just doesn't fit the design. I really don't want to touch syslog at all.

Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, journald main idea is all around binary journal that can be sealed - there is no file logging in journald. It can however forward to syslog and that's what it does by default on most systems these days.

I will create patch for foreman-debug to collect the logs from there for sure.

If we don't want to touch syslog, then another option is to ditch /var/log/foreman/production.log completely. An installer could archive/rename all files in pattern production*.log* and drop a dummy file with short explanation that this is not used. I don't think this is a bad experience for users after upgrade at all. Things change.

Structured logging patch is not only about structured logging, but also about collecting things from other parties like backend systems or smart proxy. With files, we can't achieve that, but having things in journald allows us to start working towards this goal.

Copy link
Member Author

Choose a reason for hiding this comment

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

To me it sounds like we should talk to our users about their expectations because nowadays I'm somewhat removed from actual deployments. Should we open a topic on community.theforeman.org?

Copy link
Member

Choose a reason for hiding this comment

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

@ekohl
Copy link
Member Author

ekohl commented Mar 27, 2018

I've expanded the PR to include acceptance tests. This told me we don't have the foreman-journald package in RPM nightly yet so I'm going to focus on that. Locally the Debian 9 tests looked good. I'm still running a last test run because I had an incorrect text in my test, but expecting it to pass.

@ekohl
Copy link
Member Author

ekohl commented Mar 27, 2018

Tests now pass locally:

debian-9-x64.example.com 17:54:52$ /bin/sh -c journalctl\ -u\ apache2
  -- Logs begin at Tue 2018-03-27 15:47:49 UTC, end at Tue 2018-03-27 15:54:51 UTC. --
  Mar 27 15:49:53 debian-9-x64.example.com systemd[1]: Starting The Apache HTTP Server...
  Mar 27 15:49:53 debian-9-x64.example.com systemd[1]: Started The Apache HTTP Server.
  Mar 27 15:53:48 debian-9-x64.example.com systemd[1]: Stopping The Apache HTTP Server...
  Mar 27 15:53:48 debian-9-x64.example.com systemd[1]: Stopped The Apache HTTP Server.
  Mar 27 15:53:48 debian-9-x64.example.com systemd[1]: Starting The Apache HTTP Server...
  Mar 27 15:53:48 debian-9-x64.example.com systemd[1]: Started The Apache HTTP Server.
  Mar 27 15:54:04 debian-9-x64.example.com foreman[18917]: [I|dyn|] start terminating throttle_limiter...
  Mar 27 15:54:04 debian-9-x64.example.com foreman[18917]: [I|dyn|] start terminating client dispatcher...
  Mar 27 15:54:04 debian-9-x64.example.com foreman[18917]: [I|dyn|] stop listening for new events...
  Mar 27 15:54:04 debian-9-x64.example.com foreman[18917]: [I|dyn|] start terminating clock...
  Mar 27 15:54:14 debian-9-x64.example.com foreman[18971]: [I|app|] Started HEAD "/" for 127.0.0.1 at 2018-03-27 15:54:14 +0000
  Mar 27 15:54:14 debian-9-x64.example.com foreman[18971]: [I|app|cc02b] Processing by DashboardController#index as HTML
  Mar 27 15:54:14 debian-9-x64.example.com foreman[18971]: [I|app|cc02b] Redirected to https://debian-9-x64.example.com/
  Mar 27 15:54:14 debian-9-x64.example.com foreman[18971]: [I|app|cc02b] Filter chain halted as #<Proc:0x00564bec4d09e8@/usr/share/foreman/vendor/ruby/2.3.0/gems/actionpack-5.1.4/lib/action_controller/metal/force_ssl.rb:65> rendered or redirected
  Mar 27 15:54:14 debian-9-x64.example.com foreman[18971]: [I|app|cc02b] Completed 301 Moved Permanently in 31ms (ActiveRecord: 8.1ms)
  Mar 27 15:54:14 debian-9-x64.example.com foreman[18971]: [I|app|] Started HEAD "/" for 127.0.0.1 at 2018-03-27 15:54:14 +0000
  Mar 27 15:54:14 debian-9-x64.example.com foreman[18971]: [I|app|54c81] Processing by DashboardController#index as HTML
  Mar 27 15:54:14 debian-9-x64.example.com foreman[18971]: [I|app|54c81] Redirected to https://debian-9-x64.example.com/users/login
  Mar 27 15:54:14 debian-9-x64.example.com foreman[18971]: [I|app|54c81] Filter chain halted as :require_login rendered or redirected
  Mar 27 15:54:14 debian-9-x64.example.com foreman[18971]: [I|app|54c81] Completed 302 Found in 42ms (ActiveRecord: 16.3ms)

debian-9-x64.example.com executed in 0.05 seconds
      should match /Redirected to https:\/\/debian-9-x64.example.com\/users\/login/

@ekohl ekohl force-pushed the structured-logging branch 2 times, most recently from 16b7ad3 to cb6fee8 Compare March 27, 2018 18:14
@lzap lzap changed the title [WIP] Refs #22493 - Add parameters for structured logging [WIP] Refs #22559 - Add parameters for structured logging Mar 29, 2018
@ekohl
Copy link
Member Author

ekohl commented Apr 9, 2018

With RPMs I have an issue with loading the gem. theforeman/foreman#5421 solves it for me.

Split off other commits in separate PRs that can be merged before this:

@lzap
Copy link
Member

lzap commented Apr 10, 2018

Shall I re-review now? 2/3 merged atm.

@ekohl
Copy link
Member Author

ekohl commented Apr 10, 2018

@lzap previously the tests on Debian failed because it wasn't logging in a situation where it first used file logging and then moved to journald. I still want to reproduce this.

@ekohl
Copy link
Member Author

ekohl commented Apr 10, 2018

@lzap looks like we have the same issue on CentOS in containers. Going to test it on a VM on my desktop now to see if I can reproduce it.

@lzap
Copy link
Member

lzap commented Apr 10, 2018

Oh interesting, no journald in container? It was designed to be container friendly, let's see.

@ekohl
Copy link
Member Author

ekohl commented Apr 10, 2018

@lzap when i manually ran only the journald test it did work for me locally. On Travis it first installs a basic Foreman with file logging. It could be that the upgrade doesn't work.

@ekohl
Copy link
Member Author

ekohl commented Apr 10, 2018

@lzap I know what the problem is. For the redirect log line I relied on the apache preloader to do a request but that isn't sent when you reload the app by touching restart.txt. I'll modify the tests to explicitly do a curl request to trigger a log line.

@ekohl ekohl force-pushed the structured-logging branch 2 times, most recently from 5474923 to 08407fa Compare April 10, 2018 16:30
@ekohl
Copy link
Member Author

ekohl commented Apr 10, 2018

Ready for re-review now.

@ekohl
Copy link
Member Author

ekohl commented Apr 10, 2018

(Debian tests are now failing because nightly doesn't install).

@mmoll
Copy link
Contributor

mmoll commented Apr 10, 2018

this needs a rebase now

@pondrejk
Copy link

Tested various combinations of --foreman-logging-layout --foreman-logging-level and --foreman-logging-type on rhel 7.4 based on docs in https://github.com/theforeman/theforeman.org/pull/1053/files
Some claims form that document that document I didn't verify, but that may be my misunderstanding of what parts are in progress. In short:

-- journald part works all right with all three patterns, foreman fields are logged as expected, filtering and persistent storage works
-- systemd setting for me just keeps logging to journald, logs land in /var/log/messages but that is I suppose due to journald default. So so far, these two options have the same effect, I also don't see the default facility setting mentioned in the doc
-- I din't find a way to set json_items in installer, is it something only configurable in the config file?

@ekohl
Copy link
Member Author

ekohl commented Apr 11, 2018

-- systemd setting for me just keeps logging to journald, logs land in /var/log/messages but that is I suppose due to journald default. So so far, these two options have the same effect, I also don't see the default facility setting mentioned in the doc

Do you mean syslog here?

-- I din't find a way to set json_items in installer, is it something only configurable in the config file?

We don't have that setting, but it should be easy to add. Shall I modify the PR?

@ekohl ekohl changed the title [WIP] Refs #22559 - Add parameters for structured logging Refs #22559 - Add parameters for structured logging Apr 11, 2018
@mmoll
Copy link
Contributor

mmoll commented Apr 11, 2018

please rebase :)

@ekohl
Copy link
Member Author

ekohl commented Apr 11, 2018

Rebased again :)

@pondrejk
Copy link

@ekohl

Do you mean syslog here?

Yes syslog, sorry

We don't have that setting, but it should be easy to add. Shall I modify the PR?

To me it makes sense to have yaml-configurable options also as installer parameters, so I'd say yes.

@lzap
Copy link
Member

lzap commented Apr 17, 2018

The current version stays on file appender by default, I started discussion in forums and it turned into poll which I did not want to do actually to be honest as I was hoping for more discussion around how to implement this in puppet. Anyway, I am fine with this version.

@mmoll
Copy link
Contributor

mmoll commented Apr 17, 2018

Let's bring this in as-is for now 👍

@mmoll mmoll merged commit 1279251 into theforeman:master Apr 17, 2018
@mmoll
Copy link
Contributor

mmoll commented Apr 17, 2018

merged, bedankt @ekohl!

@lzap
Copy link
Member

lzap commented Apr 19, 2018

Thanks a bunch @ekohl !

I realized one thing, when journald or syslog is set, we should configure logrotate NOT to poke httpd because it's not necessary anymore.

@ekohl ekohl deleted the structured-logging branch October 26, 2018 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants