From 9bc7ead311a858735d455765c6cb2b43ff3bf8d7 Mon Sep 17 00:00:00 2001 From: Ahsan Date: Mon, 9 May 2022 13:41:41 +0200 Subject: [PATCH 1/4] Key changed for deviceless logs to comply with otel --- lib/fluent/plugin/out_lm.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin/out_lm.rb b/lib/fluent/plugin/out_lm.rb index fa076a9..210cb21 100644 --- a/lib/fluent/plugin/out_lm.rb +++ b/lib/fluent/plugin/out_lm.rb @@ -105,11 +105,11 @@ def process_record(tag, time, record) lm_event["_lm.resourceId"] = record["_lm.resourceId"] end else - if record["service"]==nil + if record["resource.service.name"]==nil log.error "When device_less_logs is set \'true\', record must have \'service\'. Ignoring this event #{lm_event}." return nil else - lm_event["service"] = encode_if_necessary(record["service"]) + lm_event["resource.service.name"] = encode_if_necessary(record["resource.service.name"]) end end From 0746df703dbce59e7d6d67be6d34a84fd0777511 Mon Sep 17 00:00:00 2001 From: Ahsan Date: Mon, 9 May 2022 13:44:58 +0200 Subject: [PATCH 2/4] tests fixed --- test/plugin/test_device_less_logs.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/plugin/test_device_less_logs.rb b/test/plugin/test_device_less_logs.rb index 82bc27b..91cd8b0 100644 --- a/test/plugin/test_device_less_logs.rb +++ b/test/plugin/test_device_less_logs.rb @@ -32,8 +32,8 @@ def create_valid_subject "tag" => "lm.test", "meta1" => "metadata1", "meta2" => "metadata2", - "service" => "lm-service", - "namespace" => "lm-namepsace", + "resource.service.name" => "lm-service", + "resource.service.namespace" => "lm-namepsace", "someProp" => "someVal"} result = plugin.process_record(tag, time, record) @@ -41,7 +41,7 @@ def create_valid_subject expected = { "message" => "Hello from test", "timestamp" => "2020-10-30T00:29:08.629701504Z", - "service" => "lm-service" + "resource.service.name" => "lm-service" } assert_equal expected, result end @@ -62,7 +62,7 @@ def create_valid_subject "meta3" => "testMeta3", "meta4" => "testMeta4", "meta5" => {"key1" => "value1", "key2" => {"key2_1" => "value2_1"}}, - "service" => "lm-service" } + "resource.service.name" => "lm-service" } result = plugin.process_record(tag, time, record) @@ -74,7 +74,7 @@ def create_valid_subject "meta3" => "testMeta3", "meta4" => "testMeta4", "meta5" => {"key1" => "value1", "key2" => {"key2_1" => "value2_1"}}, - "service" => "lm-service" + "resource.service.name" => "lm-service" } assert_equal expected, result end From d87474e55cb388b1f33644d492f8f143fca57712 Mon Sep 17 00:00:00 2001 From: Ahsan Date: Mon, 16 May 2022 13:06:36 +0200 Subject: [PATCH 3/4] namespace picked up for deviceless in case of include-metadata is false --- lib/fluent/plugin/out_lm.rb | 21 ++++++++++++----- test/plugin/test_device_less_logs.rb | 34 +++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/lib/fluent/plugin/out_lm.rb b/lib/fluent/plugin/out_lm.rb index 210cb21..a258d77 100644 --- a/lib/fluent/plugin/out_lm.rb +++ b/lib/fluent/plugin/out_lm.rb @@ -15,6 +15,10 @@ module Fluent class LmOutput < BufferedOutput Fluent::Plugin.register_output('lm', self) + RESOURCE_MAPPING_KEY = "_lm.resourceId".freeze + DEVICELESS_KEY_SERVICE = "resource.service.name".freeze + DEVICELESS_KEY_NAMESPACE = "resource.service.namespace".freeze + # config_param defines a parameter. You can refer a parameter via @path instance variable config_param :access_id, :string, :default => "access_id" @@ -91,7 +95,8 @@ def process_record(tag, time, record) end if !@device_less_logs - if record["_lm.resourceId"] == nil + # With devices + if record[RESOURCE_MAPPING_KEY] == nil @resource_mapping.each do |key, value| k = value nestedVal = record @@ -100,17 +105,21 @@ def process_record(tag, time, record) resource_map[k] = nestedVal end end - lm_event["_lm.resourceId"] = resource_map + lm_event[RESOURCE_MAPPING_KEY] = resource_map else - lm_event["_lm.resourceId"] = record["_lm.resourceId"] + lm_event[RESOURCE_MAPPING_KEY] = record[RESOURCE_MAPPING_KEY] end else - if record["resource.service.name"]==nil + # Device less + if record[DEVICELESS_KEY_SERVICE]==nil log.error "When device_less_logs is set \'true\', record must have \'service\'. Ignoring this event #{lm_event}." return nil else - lm_event["resource.service.name"] = encode_if_necessary(record["resource.service.name"]) - end + 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]) + end + end end if record["timestamp"] != nil diff --git a/test/plugin/test_device_less_logs.rb b/test/plugin/test_device_less_logs.rb index 91cd8b0..8344237 100644 --- a/test/plugin/test_device_less_logs.rb +++ b/test/plugin/test_device_less_logs.rb @@ -41,7 +41,8 @@ def create_valid_subject expected = { "message" => "Hello from test", "timestamp" => "2020-10-30T00:29:08.629701504Z", - "resource.service.name" => "lm-service" + "resource.service.name" => "lm-service", + "resource.service.namespace" => "lm-namepsace" } assert_equal expected, result end @@ -95,5 +96,36 @@ def create_valid_subject expected = nil assert_equal expected, result end + + + test "when device_less_logs is true and include_metadata is false record must have \'service\' and pick up namespace " do + plugin = create_driver(%[ + resource_mapping {"a.b": "lm_property"} + device_less_logs true + include_metadata false + ]).instance + tag = "lm.test" + time = Time.parse("2020-08-23T00:53:15+00:00").to_i + record = { + "message" => "Hello from test", + "timestamp" => "2020-10-30T00:29:08.629701504Z" , + "meta1" => "testMeta1" , + "meta2" => "testMeta2", + "meta3" => "testMeta3", + "meta4" => "testMeta4", + "meta5" => {"key1" => "value1", "key2" => {"key2_1" => "value2_1"}}, + "resource.service.name" => "lm-service", + "resource.service.namespace" => "lm-namespace" } + + result = plugin.process_record(tag, time, record) + + expected = { + "message" => "Hello from test", + "timestamp" => "2020-10-30T00:29:08.629701504Z", + "resource.service.name" => "lm-service", + "resource.service.namespace" => "lm-namespace" + } + assert_equal expected, result + end end end \ No newline at end of file From 9937db83c073f1e3acc44cc1d064b59d5611530b Mon Sep 17 00:00:00 2001 From: Ahsan Date: Mon, 16 May 2022 14:55:43 +0200 Subject: [PATCH 4/4] version incremented to release --- fluent-plugin-lm-logs.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-plugin-lm-logs.gemspec b/fluent-plugin-lm-logs.gemspec index d1a8de2..0db7d59 100644 --- a/fluent-plugin-lm-logs.gemspec +++ b/fluent-plugin-lm-logs.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |spec| spec.name = "fluent-plugin-lm-logs" - spec.version = '1.0.3' + spec.version = '1.0.4' spec.authors = ["LogicMonitor"] spec.email = "rubygems@logicmonitor.com" spec.summary = "LogicMonitor logs fluentd output plugin"