Class: Fluent::ScribeOutput

Inherits:
BufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_scribe.rb

Instance Method Summary collapse

Constructor Details

#initializeScribeOutput

Returns a new instance of ScribeOutput.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fluent/plugin/out_scribe.rb', line 32

def initialize
  require 'thrift'
  $:.unshift File.join(File.dirname(__FILE__), 'thrift')
  require 'fb303_types'
  require 'fb303_constants'
  require 'facebook_service'
  require 'scribe_types'
  require 'scribe_constants'
  require 'scribe'
  super
end

Instance Method Details

#configure(conf) ⇒ Object



44
45
46
47
48
49
# File 'lib/fluent/plugin/out_scribe.rb', line 44

def configure(conf)
  # override default buffer_chunk_limit
  conf['buffer_chunk_limit'] ||= '1m'

  super
end

#format(tag, time, record) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/fluent/plugin/out_scribe.rb', line 64

def format(tag, time, record)
  if @remove_prefix and
      ( (tag[0, @removed_length] == @removed_prefix_string and tag.length > @removed_length) or
      tag == @remove_prefix)
    [(tag[@removed_length..-1] || @default_category), record].to_msgpack
  else
    [tag, record].to_msgpack
  end
end

#shutdownObject



60
61
62
# File 'lib/fluent/plugin/out_scribe.rb', line 60

def shutdown
  super
end

#startObject



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

def start
  super

  if @remove_prefix
    @removed_prefix_string = @remove_prefix + '.'
    @removed_length = @removed_prefix_string.length
  end
end

#write(chunk) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fluent/plugin/out_scribe.rb', line 74

def write(chunk)
  socket = Thrift::Socket.new @host, @port, @timeout
  transport = Thrift::FramedTransport.new socket
  protocol = Thrift::BinaryProtocol.new transport, false, false
  client = Scribe::Client.new protocol

  transport.open
  begin
    entries = []

    chunk.msgpack_each do |arr|
      tag, record = arr
      next unless @format_to_json || record.has_key?(@field_ref)

      message = @format_to_json ? record : record[@field_ref]

      if message.kind_of?(Array) or message.kind_of?(Hash)
        message = message.to_json
      end

      if @add_newline
        message = message + "\n"
      end

      entry = LogEntry.new
      entry.category = tag
      entry.message = message.force_encoding('ASCII-8BIT')

      entries << entry
    end

    $log.debug "Writing #{entries.count} entries to scribe"
    client.Log(entries)
  ensure
    transport.close
  end
end