Class: Fluent::Plugin::FormatDruidAuditLog1Filter

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_format_druid_audit_log_1.rb

Constant Summary collapse

NAME =
'format_druid_audit_log_1'
DEFAULT_QUERY_KEY =
'query'
DEFAULT_QUERY_RESULT_KEY =
'query_result'

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object

Raises:

  • (Fluent::ConfigError)


21
22
23
24
25
26
27
# File 'lib/fluent/plugin/filter_format_druid_audit_log_1.rb', line 21

def configure(conf)
  super

  return unless query_key.nil?

  raise Fluent::ConfigError, 'query_key should be specified'
end

#filter(_tag, _time, record) ⇒ Object



33
34
35
36
37
# File 'lib/fluent/plugin/filter_format_druid_audit_log_1.rb', line 33

def filter(_tag, _time, record)
  new_record = format_record(record.dup)
  fix_record(new_record)
  new_record
end

#fix_record(record) ⇒ Object



59
60
61
# File 'lib/fluent/plugin/filter_format_druid_audit_log_1.rb', line 59

def fix_record(record)
  fix_record_query_granularity(record)
end

#fix_record_query_granularity(record) ⇒ Object



63
64
65
66
67
68
# File 'lib/fluent/plugin/filter_format_druid_audit_log_1.rb', line 63

def fix_record_query_granularity(record)
  query_type = record['query_type'].downcase
  return if record.dig("#{query_type}_query", 'granularity').nil?

  record["#{query_type}_query"]['granularity'] = record["#{query_type}_query"]['granularity'].to_s
end

#format_record(record) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fluent/plugin/filter_format_druid_audit_log_1.rb', line 39

def format_record(record)
  [query_key, query_result_key].each do |key|
    record[key] = JSON.parse(record[key]) if record[key].is_a? String
  end

  query_type = guess_query_type(record)
  record['query_type'] = query_type

  query_data = record.delete(query_key)
  record["#{query_type}_query".downcase] = query_data
  record
end

#guess_query_type(record) ⇒ Object



52
53
54
55
56
57
# File 'lib/fluent/plugin/filter_format_druid_audit_log_1.rb', line 52

def guess_query_type(record)
  record.dig(query_key,
             'queryType') || (record.dig('query_result',
                                         'sqlQuery/time') && 'sql') || (record.dig(query_key,
                                                                                   'query') && 'sql') || 'unknown'
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/fluent/plugin/filter_format_druid_audit_log_1.rb', line 29

def multi_workers_ready?
  true
end