Commit 4cb3dd48 authored by Ian Baum's avatar Ian Baum

Merge branch '4102-make-json-logging-default' into 'master'

Default to JSON logging when possible

Closes #4102

See merge request !3292
parents ecb66f7f 28d38e84
---
title: Default to JSON logging when possible
merge_request: 3292
author:
type: changed
......@@ -740,7 +740,7 @@ external_url 'GENERATED_EXTERNAL_URL'
################################################################################
# sidekiq['log_directory'] = "/var/log/gitlab/sidekiq"
# sidekiq['log_format'] = "default"
# sidekiq['log_format'] = "json"
# sidekiq['shutdown_timeout'] = 4
# sidekiq['concurrency'] = 25
# sidekiq['metrics_enabled'] = true
......
......@@ -13,7 +13,7 @@ default['gitaly']['certificate_path'] = nil
default['gitaly']['key_path'] = nil
default['gitaly']['prometheus_listen_addr'] = "localhost:9236"
default['gitaly']['logging_level'] = nil
default['gitaly']['logging_format'] = nil
default['gitaly']['logging_format'] = "json"
default['gitaly']['logging_sentry_dsn'] = nil
default['gitaly']['logging_ruby_sentry_dsn'] = nil
default['gitaly']['logging_sentry_environment'] = nil
......
......@@ -425,7 +425,7 @@ default['gitlab']['puma']['max_threads'] = 16
default['gitlab']['sidekiq']['enable'] = false
default['gitlab']['sidekiq']['ha'] = false
default['gitlab']['sidekiq']['log_directory'] = "/var/log/gitlab/sidekiq"
default['gitlab']['sidekiq']['log_format'] = "default"
default['gitlab']['sidekiq']['log_format'] = "json"
default['gitlab']['sidekiq']['shutdown_timeout'] = 4
default['gitlab']['sidekiq']['concurrency'] = 25
default['gitlab']['sidekiq']['metrics_enabled'] = true
......@@ -439,7 +439,7 @@ default['gitlab']['sidekiq']['listen_port'] = 8082
default['gitlab']['gitlab-shell']['dir'] = "/var/opt/gitlab/gitlab-shell"
default['gitlab']['gitlab-shell']['log_directory'] = "/var/log/gitlab/gitlab-shell/"
default['gitlab']['gitlab-shell']['log_level'] = nil
default['gitlab']['gitlab-shell']['log_format'] = nil
default['gitlab']['gitlab-shell']['log_format'] = "json"
default['gitlab']['gitlab-shell']['audit_usernames'] = nil
default['gitlab']['gitlab-shell']['http_settings'] = nil
default['gitlab']['gitlab-shell']['auth_file'] = nil
......@@ -484,7 +484,7 @@ default['gitlab']['gitlab-workhorse']['api_limit'] = nil
default['gitlab']['gitlab-workhorse']['api_queue_duration'] = nil
default['gitlab']['gitlab-workhorse']['api_queue_limit'] = nil
default['gitlab']['gitlab-workhorse']['api_ci_long_polling_duration'] = nil
default['gitlab']['gitlab-workhorse']['log_format'] = nil
default['gitlab']['gitlab-workhorse']['log_format'] = "json"
default['gitlab']['gitlab-workhorse']['env_directory'] = '/opt/gitlab/etc/gitlab-workhorse/env'
default['gitlab']['gitlab-workhorse']['env'] = {
'PATH' => "#{node['package']['install-dir']}/bin:#{node['package']['install-dir']}/embedded/bin:/bin:/usr/bin",
......@@ -518,7 +518,7 @@ default['gitlab']['gitlab-pages']['dir'] = "/var/opt/gitlab/gitlab-pages"
default['gitlab']['gitlab-pages']['log_directory'] = "/var/log/gitlab/gitlab-pages"
default['gitlab']['gitlab-pages']['status_uri'] = nil
default['gitlab']['gitlab-pages']['max_connections'] = nil
default['gitlab']['gitlab-pages']['log_format'] = nil
default['gitlab']['gitlab-pages']['log_format'] = "json"
default['gitlab']['gitlab-pages']['artifacts_server'] = true
default['gitlab']['gitlab-pages']['artifacts_server_url'] = nil
default['gitlab']['gitlab-pages']['artifacts_server_timeout'] = 10
......
......@@ -11,7 +11,7 @@ describe 'gitaly' do
let(:key_path) { '/path/to/key.pem' }
let(:prometheus_listen_addr) { 'localhost:9000' }
let(:logging_level) { 'warn' }
let(:logging_format) { 'json' }
let(:logging_format) { 'default' }
let(:logging_sentry_dsn) { 'https://my_key:my_secret@sentry.io/test_project' }
let(:logging_ruby_sentry_dsn) { 'https://my_key:my_secret@sentry.io/test_project-ruby' }
let(:logging_sentry_environment) { 'production' }
......@@ -33,7 +33,7 @@ describe 'gitaly' do
'PATH' => '/opt/gitlab/bin:/opt/gitlab/embedded/bin:/bin:/usr/bin',
'ICU_DATA' => '/opt/gitlab/embedded/share/icu/current',
'PYTHONPATH' => '/opt/gitlab/embedded/lib/python3.7/site-packages',
'WRAPPER_JSON_LOGGING' => 'false',
'WRAPPER_JSON_LOGGING' => 'true',
"GITALY_PID_FILE" => '/var/opt/gitlab/gitaly/gitaly.pid',
}
end
......@@ -101,9 +101,9 @@ describe 'gitaly' do
.with_content(%r{\[\[storage\]\]\s+name = 'default'\s+path = '/var/opt/gitlab/git-data/repositories'})
end
it 'populates sv related log files' do
it 'does not append timestamp in logs if logging format is json' do
expect(chef_run).to render_file('/opt/gitlab/sv/gitaly/log/run')
.with_content(/exec svlogd -tt \/var\/log\/gitlab\/gitaly/)
.with_content(/exec svlogd \/var\/log\/gitlab\/gitaly/)
end
end
......@@ -186,9 +186,9 @@ describe 'gitaly' do
.with_content(gitaly_ruby_section)
end
it 'does not append timestamp in logs if logging format is json' do
it 'populates sv related log files' do
expect(chef_run).to render_file('/opt/gitlab/sv/gitaly/log/run')
.with_content(/exec svlogd \/var\/log\/gitlab\/gitaly/)
.with_content(/exec svlogd -tt \/var\/log\/gitlab\/gitaly/)
end
context 'when using gitaly storage configuration' do
......
......@@ -45,7 +45,7 @@ describe 'gitlab::gitlab-pages' do
expect(chef_run).not_to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-root-key})
expect(chef_run).not_to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-metrics-address})
expect(chef_run).not_to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-status-uri})
expect(chef_run).not_to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-log-format})
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-log-format="json"})
expect(chef_run).not_to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-admin-https-cert})
expect(chef_run).not_to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-admin-https-key})
expect(chef_run).not_to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-admin-https-listener})
......@@ -55,7 +55,7 @@ describe 'gitlab::gitlab-pages' do
end
it 'correctly renders the pages log run file' do
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-pages/log/run").with_content(%r{exec svlogd -tt /var/log/gitlab/gitlab-pages})
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-pages/log/run").with_content(%r{exec svlogd /var/log/gitlab/gitlab-pages})
end
end
......@@ -109,7 +109,7 @@ describe 'gitlab::gitlab-pages' do
status_uri: '/@status',
max_connections: 7500,
inplace_chroot: true,
log_format: 'json',
log_format: 'text',
admin_https_cert: '/etc/gitlab/pages-admin.crt',
admin_https_key: '/etc/gitlab/pages-admin.key',
admin_https_listener: 'localhost:2345',
......@@ -149,7 +149,7 @@ describe 'gitlab::gitlab-pages' do
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-pages-status="/@status"})
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-max-conns=7500})
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-daemon-inplace-chroot=true})
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-log-format="json"})
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-log-format})
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-admin-https-cert="/etc/gitlab/pages-admin.crt"})
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-admin-https-key="/etc/gitlab/pages-admin.key"})
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-pages/run").with_content(%r{-admin-https-listener="localhost:2345"})
......@@ -163,7 +163,7 @@ describe 'gitlab::gitlab-pages' do
end
it 'correctly renders the pages log run file' do
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-pages/log/run").with_content(%r{exec svlogd /var/log/gitlab/gitlab-pages})
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-pages/log/run").with_content(%r{exec svlogd -tt /var/log/gitlab/gitlab-pages})
end
end
......
......@@ -988,28 +988,28 @@ describe 'gitlab::gitlab-rails' do
end
context 'Sidekiq log_format' do
it 'sets the Sidekiq log_format to default' do
it 'sets the Sidekiq log_format to json' do
expect(chef_run).to create_templatesymlink('Create a gitlab.yml and create a symlink to Rails root').with_variables(
hash_including(
sidekiq: hash_including(
'log_format' => 'default'
'log_format' => 'json'
)
)
)
expect(chef_run).to render_file("/opt/gitlab/sv/sidekiq/log/run").with_content(/svlogd -tt/)
expect(chef_run).not_to render_file("/opt/gitlab/sv/sidekiq/log/run").with_content(/-tt/)
end
it 'sets the Sidekiq log_format to json' do
stub_gitlab_rb(sidekiq: { log_format: 'json' })
it 'sets the Sidekiq log_format to default' do
stub_gitlab_rb(sidekiq: { log_format: 'default' })
expect(chef_run).to create_templatesymlink('Create a gitlab.yml and create a symlink to Rails root').with_variables(
hash_including(
sidekiq: hash_including(
'log_format' => 'json'
'log_format' => 'default'
)
)
)
expect(chef_run).not_to render_file("/opt/gitlab/sv/sidekiq/log/run").with_content(/-tt/)
expect(chef_run).to render_file("/opt/gitlab/sv/sidekiq/log/run").with_content(/svlogd -tt/)
end
end
......
......@@ -62,7 +62,7 @@ describe 'gitlab::gitlab-shell' do
expect(chef_run).to create_templatesymlink('Create a config.yml and create a symlink to Rails root').with_variables(
hash_including(
log_file: '/var/log/gitlab/gitlab-shell/gitlab-shell.log',
log_format: nil,
log_format: "json",
custom_hooks_dir: nil,
migration: { enabled: true, features: [] }
)
......
......@@ -133,6 +133,8 @@ describe 'gitlab-ee::sidekiq-cluster' do
end
context 'when default' do
before { stub_gitlab_rb(sidekiq: { log_format: 'default' }) }
it 'sets the svlogd -tt option' do
expect(chef_run).to render_file("/opt/gitlab/sv/sidekiq-cluster/log/run")
.with_content(/svlogd -tt/)
......@@ -140,8 +142,6 @@ describe 'gitlab-ee::sidekiq-cluster' do
end
context 'when json' do
before { stub_gitlab_rb(sidekiq: { log_format: 'json' }) }
it 'does not set the svlogd -tt option' do
expect(chef_run).not_to render_file("/opt/gitlab/sv/sidekiq-cluster/log/run")
.with_content(/-tt/)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment