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.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fluent/plugin/out_scribe.rb', line 36

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



48
49
50
51
52
53
# File 'lib/fluent/plugin/out_scribe.rb', line 48

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

  super
end

#format(tag, time, record) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/fluent/plugin/out_scribe.rb', line 68

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



64
65
66
# File 'lib/fluent/plugin/out_scribe.rb', line 64

def shutdown
  super
end

#startObject



55
56
57
58
59
60
61
62
# File 'lib/fluent/plugin/out_scribe.rb', line 55

def start
  super

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

#write(chunk) ⇒ Object



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
111
112
113
114
# File 'lib/fluent/plugin/out_scribe.rb', line 78

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