Class: LogStash::Codecs::Delegator

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/logstash/codecs/delegator.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ Delegator

Returns a new instance of Delegator.



3
4
5
6
7
# File 'lib/logstash/codecs/delegator.rb', line 3

def initialize(obj)
  super(obj)
  @encode_metric = LogStash::Instrument::NamespacedNullMetric.new
  @decode_metric = LogStash::Instrument::NamespacedNullMetric.new
end

Instance Method Details

#classObject



9
10
11
# File 'lib/logstash/codecs/delegator.rb', line 9

def class
  __getobj__.class
end

#decode(data) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/logstash/codecs/delegator.rb', line 42

def decode(data)
  @decode_metric.increment(:writes_in)
  @decode_metric.time(:duration_in_millis) do
    __getobj__.decode(data) do |event|
      @decode_metric.increment(:out)
      yield event
    end
  end
end

#encode(event) ⇒ Object



28
29
30
31
32
33
# File 'lib/logstash/codecs/delegator.rb', line 28

def encode(event)
  @encode_metric.increment(:writes_in)
  @encode_metric.time(:duration_in_millis) do
    __getobj__.encode(event)
  end
end

#metric=(metric) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/logstash/codecs/delegator.rb', line 13

def metric=(metric)
  __getobj__.metric = metric

  __getobj__.metric.gauge(:name, __getobj__.class.config_name)

  @encode_metric = __getobj__.metric.namespace(:encode)
  @encode_metric.counter(:writes_in)
  @encode_metric.report_time(:duration_in_millis, 0)

  @decode_metric = __getobj__.metric.namespace(:decode)
  @decode_metric.counter(:writes_in)
  @decode_metric.counter(:out)
  @decode_metric.report_time(:duration_in_millis, 0)
end

#multi_encode(events) ⇒ Object



35
36
37
38
39
40
# File 'lib/logstash/codecs/delegator.rb', line 35

def multi_encode(events)
  @encode_metric.increment(:writes_in, events.length)
  @encode_metric.time(:duration_in_millis) do
    __getobj__.multi_encode(events)
  end
end