-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin: implement
ecs_compatibility
for all plugins
- Default value supplied by `pipeline.ecs_compatibility` - Warns when default used (default will change in next major) - Warns when value other than `disabled` is used (BETA: by opting in, users can accidentally consume breaking changes in a minor release of Logstash, such as one that includes an upgrade to a plugin that introduces ECS compatibility logic)
- Loading branch information
Showing
10 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
logstash-core/lib/logstash/plugins/ecs_compatibility_support.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module LogStash | ||
module Plugins | ||
module ECSCompatibilitySupport | ||
def self.included(base) | ||
base.extend(ArgumentValidator) | ||
base.config(:ecs_compatibility, :validate => :ecs_compatibility_argument, | ||
:attr_accessor => false) | ||
end | ||
|
||
MUTEX = Mutex.new | ||
private_constant :MUTEX | ||
|
||
def ecs_compatibility | ||
@_ecs_compatibility || MUTEX.synchronize do | ||
@_ecs_compatibility ||= begin | ||
# use config_init-set value if present | ||
break @ecs_compatibility unless @ecs_compatibility.nil? | ||
|
||
pipeline = execution_context.pipeline | ||
pipeline_settings = pipeline && pipeline.settings | ||
pipeline_settings ||= LogStash::SETTINGS | ||
|
||
if !pipeline_settings.set?('pipeline.ecs_compatibility') | ||
deprecation_logger.deprecated("Relying on default value of `pipeline.ecs_compatibility`, which may change in a future major release of Logstash. " + | ||
"To avoid unexpected changes when upgrading Logstash, please explicitly declare your desired ECS Compatibility mode.") | ||
end | ||
|
||
pipeline_settings.get_value('pipeline.ecs_compatibility').to_sym | ||
end | ||
end | ||
end | ||
|
||
module ArgumentValidator | ||
V_PREFIXED_INTEGER_PATTERN = %r(\Av[1-9][0-9]?\Z).freeze | ||
private_constant :V_PREFIXED_INTEGER_PATTERN | ||
|
||
def validate_value(value, validator) | ||
return super unless validator == :ecs_compatibility_argument | ||
|
||
value = deep_replace(value) | ||
value = hash_or_array(value) | ||
|
||
if value.size == 1 | ||
return true, :disabled if value.first.to_s == 'disabled' | ||
return true, value.first.to_sym if value.first.to_s =~ V_PREFIXED_INTEGER_PATTERN | ||
end | ||
|
||
return false, "Expected a v-prefixed integer major-version number (e.g., `v1`) or the literal `disabled`, got #{value.inspect}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters