Skip to content

Commit

Permalink
Merge pull request #58 from logicmonitor/57-plugin-does-not-support-m…
Browse files Browse the repository at this point in the history
…ulti-workers-configuration

Add multi worker support.
  • Loading branch information
siddharthck authored Sep 21, 2023
2 parents 73f1bab + 1a4fbb5 commit 943b80b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
30 changes: 17 additions & 13 deletions lib/fluent/plugin/out_lm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LmOutput < BufferedOutput
config_param :debug, :bool, :default => false

config_param :include_metadata, :bool, :default => false

config_param :force_encoding, :string, :default => ""

config_param :compression, :string, :default => ""
Expand All @@ -48,7 +48,7 @@ class LmOutput < BufferedOutput
config_param :device_less_logs, :bool, :default => false

config_param :http_proxy, :string, :default => nil

# Use bearer token for auth.
config_param :bearer_token, :string, :default => nil, secret: true

Expand All @@ -59,6 +59,10 @@ def configure(conf)
super
end

def multi_workers_ready?
true
end

# This method is called when starting.
# Open sockets or files here.
def start
Expand All @@ -82,8 +86,8 @@ def configure_auth
if @access_id == nil || @access_key == nil
log.info "Access Id or access key null. Using bearer token for authentication."
@use_bearer_instead_of_lmv1 = true
end
if @use_bearer_instead_of_lmv1 && @bearer_token == nil
end
if @use_bearer_instead_of_lmv1 && @bearer_token == nil
log.error "Bearer token not specified. Either access_id and access_key both or bearer_token must be specified for authentication with Logicmonitor."
raise ArgumentError, 'No valid authentication specified. Either access_id and access_key both or bearer_token must be specified for authentication with Logicmonitor.'
end
Expand Down Expand Up @@ -150,7 +154,7 @@ def process_record(tag, time, record)
else
lm_event[DEVICELESS_KEY_SERVICE] = encode_if_necessary(record[DEVICELESS_KEY_SERVICE])
if record[DEVICELESS_KEY_NAMESPACE]!=nil
lm_event[DEVICELESS_KEY_NAMESPACE] = encode_if_necessary(record[DEVICELESS_KEY_NAMESPACE])
lm_event[DEVICELESS_KEY_NAMESPACE] = encode_if_necessary(record[DEVICELESS_KEY_NAMESPACE])
end
end
end
Expand All @@ -167,13 +171,13 @@ def process_record(tag, time, record)
end

def get_metadata(record)
#if encoding is not defined we will skip going through each key val
#if encoding is not defined we will skip going through each key val
#and return the whole record for performance reasons in case of a bulky record.
if @force_encoding == ""
if @force_encoding == ""
return record
else
lm_event = {}
record.each do |key, value|
record.each do |key, value|
lm_event["#{key}"] = get_encoded_string(value)
end
return lm_event
Expand All @@ -194,7 +198,7 @@ def get_encoded_string(str)

def send_batch(events)
body = events.to_json

if @debug
log.info "Sending #{events.length} events to logic monitor at #{@url}"
log.info "Request json #{body}"
Expand All @@ -218,7 +222,7 @@ def send_batch(events)
end

resp = @http_client.request @uri, request
if @debug || resp.kind_of?(Net::HTTPMultiStatus) || !resp.kind_of?(Net::HTTPSuccess)
if @debug || resp.kind_of?(Net::HTTPMultiStatus) || !resp.kind_of?(Net::HTTPSuccess)
log.info "Status code:#{resp.code} Request Id:#{resp.header['x-request-id']} message:#{resp.body}"
end
end
Expand All @@ -228,7 +232,7 @@ def generate_token(events)

if @use_bearer_instead_of_lmv1
return "Bearer #{@bearer_token}"
else
else
timestamp = DateTime.now.strftime('%Q')
signature = Base64.strict_encode64(
OpenSSL::HMAC.hexdigest(
Expand All @@ -238,7 +242,7 @@ def generate_token(events)
)
)
return "LMv1 #{@access_id}:#{signature}:#{timestamp}"
end
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/fluent/plugin/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module LmLogsFluentPlugin
VERSION = '1.1.0'
end
VERSION = '1.2.0'
end

0 comments on commit 943b80b

Please sign in to comment.