-
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.
ECS Compatibility 7.x Backport (#12308)
Implements a plugin `ecs_compatibility` option, whose default value is powered by the pipeline-level setting `pipeline.ecs_compatibility`, in line with the proposal in #11623: In order to increase the confidence a user has when upgrading Logstash, this implementation uses the deprecation logger to warn when `ecs_compatibility` is used without an explicit directive. For now, as we continue to add ECS Compatibility Modes, an opting into a specific ECS Compatibility mode at a pipeline level is considered a BETA feature. All plugins using the [ECS Compatibility Support][] adapter will use the setting correctly, but pipelines configured in this way do not guarantee consistent behaviour across minor versions of Logstash or the plugins it bundles (e.g., upgraded plugins that have newly-implemented an ECS Compatibility mode will use the pipeline-level setting as a default, causing them to potentially behave differently after the upgrade). This change-set also includes a significant amount of work within the `PluginFactory`, which allows us to ensure that pipeline-level settings are available to a Logstash plugin _before_ its `initialize` is executed, including the maintaining of context for codecs that are routinely cloned. * JEE: instantiate codecs only once * PluginFactory: use passed FilterDelegator class * PluginFactory: require engine name in init * NOOP: remove useless secondary plugin factory interface * PluginFactory: simplify, compute java args only when necessary * PluginFactory: accept explicit id when vertex unavailable * PluginFactory: make source optional, args required * PluginFactory: threadsafe refactor of id duplicate tracking * PluginFactory: make id extraction/geration more abstract/understandable * PluginFactory: extract or generate ID when source not available * PluginFactory: inject ExecutionContext before initializing plugins * Codec: propagate execution_context and metric to clones * Plugin: intercept string-specified codecs and propagate execution_context * Plugin: implement `ecs_compatibility` for all plugins * Plugin: deprecate use of `Config::Mixin::DSL::validate_value(String, :codec)`
- Loading branch information
Showing
36 changed files
with
754 additions
and
372 deletions.
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
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
59 changes: 59 additions & 0 deletions
59
logstash-core/spec/logstash/execution_context_factory_spec.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,59 @@ | ||
# Licensed to Elasticsearch B.V. under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Elasticsearch B.V. licenses this file to you under | ||
# the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
require "spec_helper" | ||
|
||
describe LogStash::Plugins::ExecutionContextFactory do | ||
let(:pipeline) { double('Pipeline') } | ||
let(:agent) { double('Agent') } | ||
let(:inner_dlq_writer) { nil } | ||
|
||
subject(:factory) { described_class.new(agent, pipeline, inner_dlq_writer) } | ||
|
||
context '#create' do | ||
let(:plugin_id) { SecureRandom.uuid } | ||
let(:plugin_type) { 'input' } | ||
|
||
context 'the resulting instance' do | ||
subject(:instance) { factory.create(plugin_id, plugin_type) } | ||
|
||
it 'retains the pipeline from the factory' do | ||
expect(instance.pipeline).to be(pipeline) | ||
end | ||
|
||
it 'retains the agent from the factory' do | ||
expect(instance.agent).to be(agent) | ||
end | ||
|
||
it 'has a dlq_writer' do | ||
expect(instance.dlq_writer).to_not be_nil | ||
end | ||
|
||
context 'dlq_writer' do | ||
subject(:instance_dlq_writer) { instance.dlq_writer } | ||
|
||
it 'retains the plugin id' do | ||
expect(instance_dlq_writer.plugin_id).to eq(plugin_id) | ||
end | ||
|
||
it 'retains the plugin type' do | ||
expect(instance_dlq_writer.plugin_type).to eq(plugin_type) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.