Class: Loki::Entry

Inherits:
Object
  • Object
show all
Includes:
Loki
Defined in:
lib/logstash/outputs/loki/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loki

#to_ns

Constructor Details

#initialize(event, message_field, include_fields, metadata_fields) ⇒ Entry

Returns a new instance of Entry.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/logstash/outputs/loki/entry.rb', line 8

def initialize(event,message_field,include_fields,)
    @entry = {
        "ts" => to_ns(event.get("@timestamp")),
        "line" => event.get(message_field).to_s
    }
    event = event.clone()
    event.remove(message_field)
    event.remove("@timestamp")

    @labels = {}
    event.to_hash.each { |key,value|
        next if key.start_with?('@')
        next if value.is_a?(Hash)
        next if include_fields.length() > 0 and not include_fields.include?(key)
        @labels[key] = value.to_s
    }

    # Unlike include_fields we should skip if no metadata_fields provided
    if .length() > 0
        @metadata = {}
        event.to_hash.each { |key,value|
            next if key.start_with?('@')
            next if value.is_a?(Hash)
            next if .length() > 0 and not .include?(key)
            @metadata[key] = value.to_s
        }

        # Add @metadata to @entry if there was a match
        if @metadata.size > 0
            @entry.merge!('metadata' => @metadata)
        end
    end
end

Instance Attribute Details

#entryObject (readonly)

Returns the value of attribute entry.



7
8
9
# File 'lib/logstash/outputs/loki/entry.rb', line 7

def entry
  @entry
end

#labelsObject (readonly)

Returns the value of attribute labels.



7
8
9
# File 'lib/logstash/outputs/loki/entry.rb', line 7

def labels
  @labels
end