10865: Fix query for empty jobs table
[arvados.git] / services / api / config / initializers / lograge.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'safe_json'
6
7 Server::Application.configure do
8   config.lograge.enabled = true
9   config.lograge.formatter = Lograge::Formatters::Logstash.new
10   config.lograge.custom_options = lambda do |event|
11     payload = {
12       request_id: event.payload[:request_id],
13       client_ipaddr: event.payload[:client_ipaddr],
14       client_auth: event.payload[:client_auth],
15     }
16     exceptions = %w(controller action format id)
17     params = event.payload[:params].except(*exceptions)
18
19     # Omit secret_mounts field if supplied in create/update request
20     # body.
21     [
22       ['container', 'secret_mounts'],
23       ['container_request', 'secret_mounts'],
24     ].each do |resource, field|
25       if params[resource].is_a? Hash
26         params[resource] = params[resource].except(field)
27       end
28     end
29
30     # Redact new_user_token param in /arvados/v1/users/merge
31     # request. Log the auth UUID instead, if the token exists.
32     if params['new_user_token'].is_a? String
33       params['new_user_token_uuid'] =
34         ApiClientAuthorization.
35           where('api_token = ?', params['new_user_token']).
36           first.andand.uuid
37       params['new_user_token'] = '[...]'
38     end
39
40     params_s = SafeJSON.dump(params)
41     if params_s.length > Rails.configuration.max_request_log_params_size
42       payload[:params_truncated] = params_s[0..Rails.configuration.max_request_log_params_size] + "[...]"
43     else
44       payload[:params] = params
45     end
46     payload
47   end
48 end