Class: Fluent::Plugin::AzureFunctionsOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_azurefunctions.rb

Constant Summary collapse

DEFAULT_BUFFER_TYPE =
"memory"

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object

Raises:

  • (Fluent::ConfigError)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fluent/plugin/out_azurefunctions.rb', line 39

def configure(conf)
  compat_parameters_convert(conf, :buffer)
  super
  raise Fluent::ConfigError, 'no endpoint' if @endpoint.empty?
  raise Fluent::ConfigError, 'no function_key' if @function_key.empty?
  if not @key_names.nil?
    @key_names = @key_names.split(',')
  end
  if @add_time_field and @time_field_name.empty?
    raise Fluent::ConfigError, 'time_field_name must be set if add_time_field is true'
  end
  if @add_tag_field and @tag_field_name.empty?
    raise Fluent::ConfigError, 'tag_field_name must be set if add_tag_field is true'
  end
  @timef = Fluent::TimeFormatter.new(@time_format, @localtime)
end

#format(tag, time, record) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fluent/plugin/out_azurefunctions.rb', line 67

def format(tag, time, record)
  if @add_time_field
    record[@time_field_name] = @timef.format(time)
  end
  if @add_tag_field
    record[@tag_field_name] = tag
  end

  r = {}
  r['.rid'] =  SecureRandom.uuid
  if @add_time_field
    r[@time_field_name] = @timef.format(time)
  end
  if @add_tag_field
    r[@tag_field_name] = tag
  end

  if not @key_names.nil?
    @key_names.each_with_index do |key, i|
      value = record.include?(key) ? record[key] : ''
      r[key] = value
    end
    record = r
  else
    record = record.merge(r)
  end
  record.to_msgpack
end

#formatted_to_msgpack_binary?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/fluent/plugin/out_azurefunctions.rb', line 96

def formatted_to_msgpack_binary?
  true
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/fluent/plugin/out_azurefunctions.rb', line 100

def multi_workers_ready?
  true
end

#shutdownObject



62
63
64
65
# File 'lib/fluent/plugin/out_azurefunctions.rb', line 62

def shutdown
  super
  # destroy
end

#startObject



56
57
58
59
60
# File 'lib/fluent/plugin/out_azurefunctions.rb', line 56

def start
  super
  # start
  @client=AzureFunctions::HTTPTriggerClient::new(@endpoint,@function_key)
end

#write(chunk) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/fluent/plugin/out_azurefunctions.rb', line 104

def write(chunk)
  chunk.msgpack_each { |record|
    payload = JSON.dump(record)
    unique_identifier = record[".rid"]
    #p "payload=#{payload}"
    #p "unique_identifier=#{unique_identifier}"
    begin
      @client.post(payload)
    rescue Exception => ex
      log.fatal "Error occured in posting to Azure Functions HTTP trigger function: "
              + "'#{ex}', .rid=>#{unique_identifier}, payload=>" + payload
    end
  }
end