logstash-plugins / logstash-mixin-ecs_compatibility_support

Support for the ECS-Compatibility mode targeting Logstash 7.7, for plugins wishing to use this API on older Logstashes
Apache License 2.0
0 stars 7 forks source link

add support for aliases in version-constrained implementations #5

Closed yaauie closed 3 years ago

yaauie commented 3 years ago

While we have a large effort in-flight to add ECS v1 support for plugins in advance of Logstash 8's general availability, ECS v8 is set to release along-side Elastic Stack 8, and the delta is currently being scoped and is thus unknown. This means that as we get closer to the release of Logstash 8, we have a pending task to go back and add ECS v8 support to all plugins for which we recently added ECS v1 support.

These changes to the support adapter will allow plugin maintainers to describe ECS v8 as an alias for ECS v1 and provide only the delta in their usage of ecs_select, drastically reducing the overhead of implementing v8.

Where before, plugin maintainers were encouraged to describe the versions that they supported and forced to provide side-by-side implementations for all supported versions to each ecs_select:

require 'logstash/plugin_mixins/ecs_compatibility_support'

class LogStash::Inputs::Foo < Logstash::Inputs::Base
  include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled, :v1)

  def register
    @this = ecs_select[disabled: "old",    v1: "new"]
    @that = ecs_select[disabled: "legacy", v1: "novel"]
  end
end

With these changes maintainers now can describe one implementation in terms of another, providing only the delta:

require 'logstash/plugin_mixins/ecs_compatibility_support'

class LogStash::Inputs::Foo < Logstash::Inputs::Base
  include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled, :v1, :v8 => :v1)

  def register
    @this = ecs_select[disabled: "old",    v1: "new"]
    @that = ecs_select[disabled: "legacy", v1: "novel", v8:"shiny"]
  end
end

Plugin instantiation will be guarded to allow only the supported plugins, and usage of ecs_select will "fall through" the alias chain when a value is not provided. In the example above, when run in the new v8 mode, @this will resolve to "new" by the alias from v8 => v1, while @that will resolve to "shiny" because the value is explicitly given.

yaauie commented 3 years ago

Unfortunately, a hash literal with duplicates in Ruby can't be detected. By the time the object is instantiated for us, it has already been deduplicated (last wins).