diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-12 21:07:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-12 21:07:34 +0300 |
commit | 90859e80ca23b8709d56b60d2066b569053e7e02 (patch) | |
tree | 15d9ac5c194220fab358c42325645fdf2c6ead13 /config | |
parent | 7530cf5ad8dd86fbe19e129b6bb31b23849ed757 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'config')
-rw-r--r-- | config/initializers/snowplow_tracker.rb | 23 | ||||
-rw-r--r-- | config/puma.example.development.rb | 8 | ||||
-rw-r--r-- | config/puma.rb.example | 8 |
3 files changed, 39 insertions, 0 deletions
diff --git a/config/initializers/snowplow_tracker.rb b/config/initializers/snowplow_tracker.rb new file mode 100644 index 00000000000..3c730e03738 --- /dev/null +++ b/config/initializers/snowplow_tracker.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +# Gitlab.com uses Snowplow for identifying users and events. +# https://gitlab.com/gitlab-org/gitlab/issues/6329 +# +# SnowplowTracker write log into STDERR +# https://github.com/snowplow/snowplow-ruby-tracker/blob/39fcfa2be793f2e25e73087a9700abc93f43b5e8/lib/snowplow-tracker/emitters.rb#L23 +# `LOGGER = Logger.new(STDERR)` +# +# In puma.rb, if `stdout_redirect` specify stderr, Puma will overwrite STDERR in: +# https://github.com/puma/puma/blob/b41205f5cacbc2ad0060472bdce68ba636f42175/lib/puma/runner.rb#L134 +# `STDERR.reopen stderr, (append ? "a" : "w")` +# As a result, SnowplowTracker will log into Puma stderr, when Puma enabled. +# +# By default, SnowplowTracker uses default log formatter. +# When enable Puma, SnowplowTracker log is expected to be JSON format, as part of puma_stderr.log. +# Hence overwrite ::SnowplowTracker::LOGGER.formatter to JSON formatter + +if defined?(::Puma) && defined?(::SnowplowTracker::LOGGER) + ::SnowplowTracker::LOGGER.formatter = proc do |severity, datetime, progname, msg| + { severity: severity, timestamp: datetime.utc.iso8601(3), pid: $$, progname: progname, message: msg }.to_json << "\n" + end +end diff --git a/config/puma.example.development.rb b/config/puma.example.development.rb index 6f686437f88..ecbfac660c9 100644 --- a/config/puma.example.development.rb +++ b/config/puma.example.development.rb @@ -78,3 +78,11 @@ tag 'gitlab-puma-worker' # value is 60 seconds. # worker_timeout 60 + +# Use json formatter +require_relative "/home/git/gitlab/lib/gitlab/puma_logging/json_formatter" + +json_formatter = Gitlab::PumaLogging::JSONFormatter.new +log_formatter do |str| + json_formatter.call(str) +end diff --git a/config/puma.rb.example b/config/puma.rb.example index 10f255a87de..cd7adca157f 100644 --- a/config/puma.rb.example +++ b/config/puma.rb.example @@ -68,3 +68,11 @@ tag 'gitlab-puma-worker' # value is 60 seconds. # worker_timeout 60 + +# Use json formatter +require_relative "/home/git/gitlab/lib/gitlab/puma_logging/json_formatter" + +json_formatter = Gitlab::PumaLogging::JSONFormatter.new +log_formatter do |str| + json_formatter.call(str) +end
\ No newline at end of file |