Commit 5df76410 authored by Changzheng Liu's avatar Changzheng Liu Committed by Matthias Käppler

Include Puma worker PID in structured log

Changelog: other
parent bcdf86cb
...@@ -97,7 +97,8 @@ Line breaks were added to examples for legibility: ...@@ -97,7 +97,8 @@ Line breaks were added to examples for legibility:
"cpu_s":17.50, "cpu_s":17.50,
"db_duration_s":0.08, "db_duration_s":0.08,
"view_duration_s":2.39, "view_duration_s":2.39,
"duration_s":20.54 "duration_s":20.54,
"pid": 81836
} }
``` ```
...@@ -120,6 +121,7 @@ seconds: ...@@ -120,6 +121,7 @@ seconds:
- `redis_<instance>_duration_s`: Total time to retrieve data from a Redis instance - `redis_<instance>_duration_s`: Total time to retrieve data from a Redis instance
- `redis_<instance>_read_bytes`: Total bytes read from a Redis instance - `redis_<instance>_read_bytes`: Total bytes read from a Redis instance
- `redis_<instance>_write_bytes`: Total bytes written to a Redis instance - `redis_<instance>_write_bytes`: Total bytes written to a Redis instance
- `pid`: Process ID of the Puma worker
User clone and fetch activity using HTTP transport appears in the log as `action: git_upload_pack`. User clone and fetch activity using HTTP transport appears in the log as `action: git_upload_pack`.
...@@ -190,7 +192,8 @@ Starting with GitLab 12.5, if an error occurs, an ...@@ -190,7 +192,8 @@ Starting with GitLab 12.5, if an error occurs, an
"cpu_s":17.50, "cpu_s":17.50,
"db_duration_s":0.08, "db_duration_s":0.08,
"view_duration_s":2.39, "view_duration_s":2.39,
"duration_s":20.54 "duration_s":20.54,
"pid": 81836,
"exception.class": "NameError", "exception.class": "NameError",
"exception.message": "undefined local variable or method `adsf' for #<Admin::DashboardController:0x00007ff3c9648588>", "exception.message": "undefined local variable or method `adsf' for #<Admin::DashboardController:0x00007ff3c9648588>",
"exception.backtrace": [ "exception.backtrace": [
......
...@@ -30,6 +30,7 @@ module Gitlab ...@@ -30,6 +30,7 @@ module Gitlab
instrument_cpu(payload) instrument_cpu(payload)
instrument_thread_memory_allocations(payload) instrument_thread_memory_allocations(payload)
instrument_load_balancing(payload) instrument_load_balancing(payload)
instrument_pid(payload)
end end
def instrument_gitaly(payload) def instrument_gitaly(payload)
...@@ -99,6 +100,10 @@ module Gitlab ...@@ -99,6 +100,10 @@ module Gitlab
payload[:cpu_s] = cpu_s.round(DURATION_PRECISION) if cpu_s payload[:cpu_s] = cpu_s.round(DURATION_PRECISION) if cpu_s
end end
def instrument_pid(payload)
payload[:pid] = Process.pid
end
def instrument_thread_memory_allocations(payload) def instrument_thread_memory_allocations(payload)
counters = ::Gitlab::Memory::Instrumentation.measure_thread_memory_allocations( counters = ::Gitlab::Memory::Instrumentation.measure_thread_memory_allocations(
::Gitlab::RequestContext.instance.thread_memory_allocations) ::Gitlab::RequestContext.instance.thread_memory_allocations)
......
...@@ -3,26 +3,23 @@ ...@@ -3,26 +3,23 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::GrapeLogging::Loggers::PerfLogger do RSpec.describe Gitlab::GrapeLogging::Loggers::PerfLogger do
subject { described_class.new } let(:mock_request) { OpenStruct.new(env: {}) }
describe ".parameters" do describe ".parameters" do
let(:mock_request) { OpenStruct.new(env: {}) } subject { described_class.new.parameters(mock_request, nil) }
describe 'when no performance datais are present' do let(:perf_data) { { redis_calls: 1 } }
it 'returns an empty Hash' do
expect(subject.parameters(mock_request, nil)).to eq({}) describe 'when no performance data present' do
end it { is_expected.not_to include(perf_data) }
end end
describe 'when Redis calls are present', :request_store do describe 'when performance data present', :request_store do
it 'returns a Hash with Redis information' do before do
Gitlab::Redis::SharedState.with { |redis| redis.get('perf-logger-test') } Gitlab::Redis::SharedState.with { |redis| redis.get('perf-logger-test') }
payload = subject.parameters(mock_request, nil)
expect(payload[:redis_calls]).to eq(1)
expect(payload[:redis_duration_s]).to be >= 0
end end
it { is_expected.to include(perf_data) }
end end
end end
end end
...@@ -83,6 +83,12 @@ RSpec.describe Gitlab::InstrumentationHelper do ...@@ -83,6 +83,12 @@ RSpec.describe Gitlab::InstrumentationHelper do
expect(payload).to include(:cpu_s) expect(payload).to include(:cpu_s)
end end
it 'logs the process ID' do
subject
expect(payload).to include(:pid)
end
context 'when logging memory allocations' do context 'when logging memory allocations' do
include MemoryInstrumentationHelper include MemoryInstrumentationHelper
......
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