Class: Fluent::Plugin::WodbyFilter

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

Instance Method Summary collapse

Instance Method Details

#filter(tag, time, record) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fluent/plugin/filter_wodby.rb', line 34

def filter(tag, time, record)
  record['wodby.filter'] = true

  if record.has_key?('kubernetes') && record['kubernetes'].has_key?('namespace_name')
    namespace = record['kubernetes']['namespace_name']
    unless @instance_map.has_key?(namespace)
      record['wodby.instance_query'] = namespace
      instance = get_instance(namespace)
      app = get_app(instance['app_id'])
      org = get_org(app['org_id'])

      @instance_map[namespace] = {
        'name' => "#{app['name']}.#{instance['name']}",
        'title' => "#{app['title']} - #{instance['title']}",
        'type' => instance['type'],
        'organization' => org['name'],
        'organization_title' => org['title'],
      }
    end

    record['wodby.instance'] = @instance_map[namespace]['name']
    record['wodby.instance_title'] = @instance_map[namespace]['title']
    record['wodby.instance_type'] = @instance_map[namespace]['type']
    record['wodby.organization'] = @instance_map[namespace]['organization']
    record['wodby.organization_title'] = @instance_map[namespace]['organization_title']
  else
    log.info "No namespace found"
    log.info record
  end

  record
end

#startObject



27
28
29
30
31
32
# File 'lib/fluent/plugin/filter_wodby.rb', line 27

def start
  super

  @instance_map = {}
  log.info "Initialized wodby plugin"
end