logstash-mixin-ecs_compatibility_support 1.2.0-java → 1.3.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6ff73bf503783cc17b6fbc2ebebcf23398d52ffa01cfc2a9d397566833f9706
4
- data.tar.gz: 69d950da27ad60c8fdb09a08e72f7a4ffce9ede7e85cad0bfb130854cf40a07b
3
+ metadata.gz: 8a64fc499677faca675d99eccc08d8d397f6d1330b6073ce31ab1570a0e750d1
4
+ data.tar.gz: 6a4c3df642e4dc252d545069b4a7b301ecf246c2655b893409f1898643507353
5
5
  SHA512:
6
- metadata.gz: 5334c125b5e9b24567500ae94546b3acd5260d7f83232eaa173439d68e8d974ca294f4a3f5b0c33d0d760ac4d843ea67bcb920b0713f480848e6d5044a43895b
7
- data.tar.gz: 3b5bddca9732f6f03f79d4bf8ebf0dbeedb120dd7b23703f68c7e8410f5896e7124e343a2a843ce0346eeee6463c02bf738d1add11fed102f7c12e4147707e8f
6
+ metadata.gz: b84794d3a79993ecb23464e8293ee9f44d2430f6901c5f92f5dfcaa46e45fe09b5ee6f353afe8a8b36afa976f1bcc8b4ee69e123d2b665e5cb2b1228c9aea445
7
+ data.tar.gz: bb9d04088b8dcdd81a1ffefeb9ef1e5eec02e4fd24491684630e5c7e5c9a007121604c5b3435433f6a971b8e42eb2b0e926b1355fc0021e22f53a8de899cd433
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 1.3.0
2
+ - Feat: introduce a target check helper [#6](https://github.com/logstash-plugins/logstash-mixin-ecs_compatibility_support/pull/6)
3
+
1
4
  # 1.2.0
2
5
  - Added support for resolution aliases, allowing a plugin that uses `ecs_select` to support multiple ECS versions with a single declaration.
3
6
 
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../ecs_compatibility_support'
4
+
5
+ module LogStash
6
+ module PluginMixins
7
+ module ECSCompatibilitySupport
8
+ # A target option check that can be included into any `LogStash::Plugin`.
9
+ #
10
+ # @see ECSCompatibilitySupport()
11
+ module TargetCheck
12
+ ##
13
+ # @api internal (use: `LogStash::Plugin::include`)
14
+ # @param base [Class]: a class that inherits `LogStash::Plugin`, typically one
15
+ # descending from one of the four plugin base classes
16
+ # (e.g., `LogStash::Inputs::Base`)
17
+ # @return [void]
18
+ def self.included(base)
19
+ fail(ArgumentError, "`#{base}` must inherit LogStash::Plugin") unless base < LogStash::Plugin
20
+ fail(ArgumentError, "`#{base}` must include #{ECSCompatibilitySupport}") unless base < ECSCompatibilitySupport
21
+ base.prepend(RegisterDecorator)
22
+ end
23
+
24
+ TARGET_NOT_SET_MESSAGE = ("ECS compatibility is enabled but `target` option was not specified. " +
25
+ "This may cause fields to be set at the top-level of the event where they are likely to clash with the Elastic Common Schema. " +
26
+ "It is recommended to set the `target` option to avoid potential schema conflicts (if your data is ECS compliant " +
27
+ "or non-conflicting, feel free to ignore this message)").freeze
28
+
29
+ private
30
+
31
+ ##
32
+ # Check whether `target` is specified.
33
+ #
34
+ # @return [nil] if target is unspecified and ECS compatibility is disabled
35
+ # @return [true, false]
36
+ def target_set?
37
+ return true unless target.nil?
38
+ return nil if ecs_compatibility == :disabled
39
+ false # target isn't set
40
+ end
41
+
42
+ module RegisterDecorator
43
+
44
+ ##
45
+ # Logs an info message when ecs_compatibility is enabled but plugin has no `target` configuration specified.
46
+ # @override
47
+ def register
48
+ super.tap do
49
+ logger.info(TARGET_NOT_SET_MESSAGE) if target_set? == false
50
+ end
51
+ end
52
+
53
+ end
54
+ private_constant :RegisterDecorator
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+
3
+ require "logstash-core"
4
+
5
+ require 'logstash/inputs/base'
6
+ require 'logstash/filters/base'
7
+ require 'logstash/codecs/base'
8
+ require 'logstash/outputs/base'
9
+
10
+ require "logstash/plugin_mixins/ecs_compatibility_support/target_check"
11
+
12
+ describe LogStash::PluginMixins::ECSCompatibilitySupport::TargetCheck do
13
+
14
+ describe "check_target_set_in_ecs_mode" do
15
+
16
+ context 'with a plugin' do
17
+
18
+ subject(:plugin_class) do
19
+ Class.new(LogStash::Filters::Base) do
20
+ include LogStash::PluginMixins::ECSCompatibilitySupport
21
+ include LogStash::PluginMixins::ECSCompatibilitySupport::TargetCheck
22
+
23
+ config :target, :validate => :string
24
+
25
+ def register; 42 end
26
+
27
+ end
28
+ end
29
+
30
+ it 'skips check when ECS disabled' do
31
+ plugin = plugin_class.new('ecs_compatibility' => 'disabled')
32
+ allow( plugin.logger ).to receive(:info)
33
+ expect( plugin.register ).to eql 42
34
+ expect( plugin.logger ).to_not have_received(:info).with(a_string_including "`target` option")
35
+ end
36
+
37
+ it 'warns when target is not set in ECS mode' do
38
+ plugin = plugin_class.new('ecs_compatibility' => 'v1')
39
+ allow( plugin.logger ).to receive(:info)
40
+ expect( plugin.register ).to eql 42
41
+ expect( plugin.logger ).to have_received(:info).with(a_string_including "ECS compatibility is enabled but `target` option was not specified.")
42
+ end
43
+
44
+ it 'does not warn when target is set' do
45
+ plugin = plugin_class.new('ecs_compatibility' => 'v1', 'target' => 'foo')
46
+ allow( plugin.logger ).to receive(:info)
47
+ expect( plugin.register ).to eql 42
48
+ expect( plugin.logger ).to_not have_received(:info).with(a_string_including "`target` option")
49
+ end
50
+
51
+ end
52
+
53
+ it 'fails check when no target config' do
54
+ plugin_class = Class.new(LogStash::Filters::Base) do
55
+ include LogStash::PluginMixins::ECSCompatibilitySupport
56
+ include LogStash::PluginMixins::ECSCompatibilitySupport::TargetCheck
57
+
58
+ def register; end
59
+
60
+ end
61
+ plugin = plugin_class.new('ecs_compatibility' => 'v1')
62
+ expect { plugin.register }.to raise_error NameError, /\btarget\b/
63
+ end
64
+
65
+ end
66
+
67
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-mixin-ecs_compatibility_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-04 00:00:00.000000000 Z
11
+ date: 2021-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -96,8 +96,10 @@ files:
96
96
  - lib/logstash/plugin_mixins/ecs_compatibility_support.rb
97
97
  - lib/logstash/plugin_mixins/ecs_compatibility_support/selector.rb
98
98
  - lib/logstash/plugin_mixins/ecs_compatibility_support/spec_helper.rb
99
+ - lib/logstash/plugin_mixins/ecs_compatibility_support/target_check.rb
99
100
  - spec/logstash/plugin_mixins/ecs_compatibility_support/selector_spec.rb
100
101
  - spec/logstash/plugin_mixins/ecs_compatibility_support/spec_helper_spec.rb
102
+ - spec/logstash/plugin_mixins/ecs_compatibility_support/target_check_spec.rb
101
103
  - spec/logstash/plugin_mixins/ecs_compatibility_support_spec.rb
102
104
  homepage: https://github.com/logstash-plugins/logstash-mixin-ecs_compatibility_support
103
105
  licenses:
@@ -127,4 +129,5 @@ summary: Support for the ECS-Compatibility mode introduced in Logstash 7.x, for
127
129
  test_files:
128
130
  - spec/logstash/plugin_mixins/ecs_compatibility_support/selector_spec.rb
129
131
  - spec/logstash/plugin_mixins/ecs_compatibility_support/spec_helper_spec.rb
132
+ - spec/logstash/plugin_mixins/ecs_compatibility_support/target_check_spec.rb
130
133
  - spec/logstash/plugin_mixins/ecs_compatibility_support_spec.rb