From d721c1fc72fcc1e3796315ef96c1135d429305e8 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Sat, 21 Oct 2017 16:25:15 +0200 Subject: [PATCH] Singularize the Filters module Since we are using single objects from this namespaces, it is much more suitable to be named in singular than in plural. --- lib/rackstash/adapter/logger.rb | 2 +- lib/rackstash/buffer.rb | 11 +++++----- lib/rackstash/{filters.rb => filter.rb} | 22 +++++++++---------- .../{filters => filter}/clear_color.rb | 2 +- .../{filters => filter}/default_fields.rb | 2 +- .../{filters => filter}/default_tags.rb | 2 +- lib/rackstash/{filters => filter}/rename.rb | 2 +- lib/rackstash/{filters => filter}/replace.rb | 2 +- .../{filters => filter}/skip_event.rb | 2 +- .../{filters => filter}/truncate_message.rb | 2 +- lib/rackstash/{filters => filter}/update.rb | 2 +- lib/rackstash/filter_chain.rb | 22 +++++++++---------- lib/rackstash/flow.rb | 11 +++++----- lib/rackstash/message.rb | 2 +- .../{filters => filter}/clear_color_spec.rb | 4 ++-- .../default_fields_spec.rb | 4 ++-- .../{filters => filter}/default_tags_spec.rb | 4 ++-- .../{filters => filter}/rename_spec.rb | 4 ++-- .../{filters => filter}/replace_spec.rb | 4 ++-- .../{filters => filter}/skip_event_spec.rb | 4 ++-- .../truncate_message_spec.rb | 4 ++-- .../{filters => filter}/update_spec.rb | 4 ++-- .../{filters_spec.rb => filter_spec.rb} | 6 ++--- 23 files changed, 61 insertions(+), 63 deletions(-) rename lib/rackstash/{filters.rb => filter.rb} (88%) rename lib/rackstash/{filters => filter}/clear_color.rb (98%) rename lib/rackstash/{filters => filter}/default_fields.rb (99%) rename lib/rackstash/{filters => filter}/default_tags.rb (99%) rename lib/rackstash/{filters => filter}/rename.rb (98%) rename lib/rackstash/{filters => filter}/replace.rb (99%) rename lib/rackstash/{filters => filter}/skip_event.rb (99%) rename lib/rackstash/{filters => filter}/truncate_message.rb (99%) rename lib/rackstash/{filters => filter}/update.rb (99%) rename spec/rackstash/{filters => filter}/clear_color_spec.rb (91%) rename spec/rackstash/{filters => filter}/default_fields_spec.rb (93%) rename spec/rackstash/{filters => filter}/default_tags_spec.rb (91%) rename spec/rackstash/{filters => filter}/rename_spec.rb (93%) rename spec/rackstash/{filters => filter}/replace_spec.rb (93%) rename spec/rackstash/{filters => filter}/skip_event_spec.rb (94%) rename spec/rackstash/{filters => filter}/truncate_message_spec.rb (97%) rename spec/rackstash/{filters => filter}/update_spec.rb (94%) rename spec/rackstash/{filters_spec.rb => filter_spec.rb} (95%) diff --git a/lib/rackstash/adapter/logger.rb b/lib/rackstash/adapter/logger.rb index 67eb833..9fe30c1 100644 --- a/lib/rackstash/adapter/logger.rb +++ b/lib/rackstash/adapter/logger.rb @@ -22,7 +22,7 @@ module Rackstash # standard library. All logs emitted to the given logger will be emitted # with the defined severity (`INFO` by default). Since a log event in # Rackstash can contain multiple concatenanted messages, you should make - # sure to format them properly with {Filters} or a custom encoder if + # sure to format them properly with a {Filter} or a custom encoder if # required. # # While most loggers expect Strings as arguments to their `add` method, some diff --git a/lib/rackstash/buffer.rb b/lib/rackstash/buffer.rb index e2b4bfb..4e3f387 100644 --- a/lib/rackstash/buffer.rb +++ b/lib/rackstash/buffer.rb @@ -337,17 +337,16 @@ module Rackstash # # Note that the resulting hash still contains an Array of {Message}s in the # `"message"` field and a `Time` object in the '@timestamp' field. This - # allows the {Flow}'s components (usually the {Filters} or the - # {Flow#encoder}) to reject or adapt some messages based on - # their original attributes, e.g., their severity or timestamp. It is the - # responsibility of the {Flow#encoder} to correctly format the - # `"@timestamp"` field. + # allows the {Flow}'s components (usually a {Filter} or the {Flow#encoder}) + # to reject or adapt some messages based on their original attributes, e.g., + # their severity or timestamp. It is the responsibility of the + # {Flow#encoder} to correctly format the `"@timestamp"` field. # # All other fields in the event Hash besides `"message"` and `@timestamp"` # are either `Hash`, `Array`, frozen `String`, `Integer` or `Float` objects. # All hashes (including nested hashes) use `String` keys. # - # @return [Hash] the event expected by the event {Filters}. + # @return [Hash] the event expected by the event {Filter}s. def to_event event = fields.to_h event[FIELD_TAGS] = tags.to_a diff --git a/lib/rackstash/filters.rb b/lib/rackstash/filter.rb similarity index 88% rename from lib/rackstash/filters.rb rename to lib/rackstash/filter.rb index 7994b2c..d45ff63 100644 --- a/lib/rackstash/filters.rb +++ b/lib/rackstash/filter.rb @@ -5,13 +5,13 @@ # This software may be modified and distributed under the terms # of the MIT license. See the LICENSE.txt file for details. -require 'rackstash/filters/clear_color' -require 'rackstash/filters/default_fields' -require 'rackstash/filters/default_tags' -require 'rackstash/filters/rename' -require 'rackstash/filters/replace' -require 'rackstash/filters/skip_event' -require 'rackstash/filters/truncate_message' +require 'rackstash/filter/clear_color' +require 'rackstash/filter/default_fields' +require 'rackstash/filter/default_tags' +require 'rackstash/filter/rename' +require 'rackstash/filter/replace' +require 'rackstash/filter/skip_event' +require 'rackstash/filter/truncate_message' module Rackstash # Filters are part of a {Flow} where they can alter the log event before it is @@ -28,16 +28,16 @@ module Rackstash # # A filter can be any object responding to `call`, e.g. a Proc or a concrete # class inside this module. - module Filters + module Filter # Create a new filter instance from the specified class and the given # arguments. The class can be given as an actual class or as the name of a # filter in which case we are resolving it to a class defined inside the - # {Rackstash::Filters} namespace. + # {Rackstash::Filter} namespace. # # @param klass [Class, Symbol, String, #call] a description of the class # from which we are creating a new filter object. When giving a `Class`, # we are using it as is. When giving a `String` or `Symbol`, we are - # determining the associated class from the {Rackstash::Filters} module + # determining the associated class from the {Rackstash::Filter} module # and create an instance of that. When giving an object which responds to # `call` already, we return it unchanged, ignoring any additional passed # `args`. @@ -66,7 +66,7 @@ module Rackstash end # @return [Hash Class>] a Hash with names of filters and their - # respective classes which can be used with {Filters.build} to create a + # respective classes which can be used with {Filter.build} to create a # new filter object def self.known constants.each_with_object({}) do |const, known| diff --git a/lib/rackstash/filters/clear_color.rb b/lib/rackstash/filter/clear_color.rb similarity index 98% rename from lib/rackstash/filters/clear_color.rb rename to lib/rackstash/filter/clear_color.rb index 41093cb..3127c5d 100644 --- a/lib/rackstash/filters/clear_color.rb +++ b/lib/rackstash/filter/clear_color.rb @@ -6,7 +6,7 @@ # of the MIT license. See the LICENSE.txt file for details. module Rackstash - module Filters + module Filter # Remove all ANSI color codes from the `"message"` field of the given event # `Hash`. # diff --git a/lib/rackstash/filters/default_fields.rb b/lib/rackstash/filter/default_fields.rb similarity index 99% rename from lib/rackstash/filters/default_fields.rb rename to lib/rackstash/filter/default_fields.rb index 630f514..735c288 100644 --- a/lib/rackstash/filters/default_fields.rb +++ b/lib/rackstash/filter/default_fields.rb @@ -6,7 +6,7 @@ # of the MIT license. See the LICENSE.txt file for details. module Rackstash - module Filters + module Filter # The {DefaultFields} filter allows to define fields which should be added # to an event if they aren't already explicitly set. # diff --git a/lib/rackstash/filters/default_tags.rb b/lib/rackstash/filter/default_tags.rb similarity index 99% rename from lib/rackstash/filters/default_tags.rb rename to lib/rackstash/filter/default_tags.rb index e117ad5..71b010b 100644 --- a/lib/rackstash/filters/default_tags.rb +++ b/lib/rackstash/filter/default_tags.rb @@ -6,7 +6,7 @@ # of the MIT license. See the LICENSE.txt file for details. module Rackstash - module Filters + module Filter # The {DefaultTags} filter allows to define tags which should be added # to an event if they aren't already explicitly set there. All existing tags # on the event are retained. diff --git a/lib/rackstash/filters/rename.rb b/lib/rackstash/filter/rename.rb similarity index 98% rename from lib/rackstash/filters/rename.rb rename to lib/rackstash/filter/rename.rb index 7bdcab5..98364d7 100644 --- a/lib/rackstash/filters/rename.rb +++ b/lib/rackstash/filter/rename.rb @@ -6,7 +6,7 @@ # of the MIT license. See the LICENSE.txt file for details. module Rackstash - module Filters + module Filter # Rename one or more fields in the given event. # # @example diff --git a/lib/rackstash/filters/replace.rb b/lib/rackstash/filter/replace.rb similarity index 99% rename from lib/rackstash/filters/replace.rb rename to lib/rackstash/filter/replace.rb index 234e008..88c95ba 100644 --- a/lib/rackstash/filters/replace.rb +++ b/lib/rackstash/filter/replace.rb @@ -6,7 +6,7 @@ # of the MIT license. See the LICENSE.txt file for details. module Rackstash - module Filters + module Filter # Replace fields in the given event with new values. A new value can be # specified as either a fixed value or as a `Proc` (or any other object # responding to `call`). In the latter case, the callable object will be diff --git a/lib/rackstash/filters/skip_event.rb b/lib/rackstash/filter/skip_event.rb similarity index 99% rename from lib/rackstash/filters/skip_event.rb rename to lib/rackstash/filter/skip_event.rb index 9906ad1..c846d68 100644 --- a/lib/rackstash/filters/skip_event.rb +++ b/lib/rackstash/filter/skip_event.rb @@ -6,7 +6,7 @@ # of the MIT license. See the LICENSE.txt file for details. module Rackstash - module Filters + module Filter # Skip the further processing of the event of the condition is `true`. # # This filter is a basic example of how you can write filters which abort diff --git a/lib/rackstash/filters/truncate_message.rb b/lib/rackstash/filter/truncate_message.rb similarity index 99% rename from lib/rackstash/filters/truncate_message.rb rename to lib/rackstash/filter/truncate_message.rb index 80a890d..52330af 100644 --- a/lib/rackstash/filters/truncate_message.rb +++ b/lib/rackstash/filter/truncate_message.rb @@ -6,7 +6,7 @@ # of the MIT license. See the LICENSE.txt file for details. module Rackstash - module Filters + module Filter # The Truncate filter can be used to restrict the size of the emitted # message. By selectively deleting parts until the message size fits into # the defined limit, you can ensure that log events are properly handled by diff --git a/lib/rackstash/filters/update.rb b/lib/rackstash/filter/update.rb similarity index 99% rename from lib/rackstash/filters/update.rb rename to lib/rackstash/filter/update.rb index f997d05..bde1c46 100644 --- a/lib/rackstash/filters/update.rb +++ b/lib/rackstash/filter/update.rb @@ -6,7 +6,7 @@ # of the MIT license. See the LICENSE.txt file for details. module Rackstash - module Filters + module Filter # Update fields in the given event with new values. A new value can be # specified as either a fixed value or as a `Proc` (or any other object # responding to `call`). In the latter case, the callable object will be diff --git a/lib/rackstash/filter_chain.rb b/lib/rackstash/filter_chain.rb index 8c54ed5..9ccb306 100644 --- a/lib/rackstash/filter_chain.rb +++ b/lib/rackstash/filter_chain.rb @@ -11,10 +11,10 @@ module Rackstash # The FilterChain contains a list of event filters which are used by a {Flow} # to mutate an event before it is envoded and sent to the adapter for writing. # - # A filter is any object responding to `call`, e.g. one of the {Filters} or a - # `Proc` object. When running the filters, we call each filter iin turn, - # passing the event. The filter can change the event in any way desired but - # should make sure that it preserves the basic structure of the event: + # A filter is any object responding to `call`, e.g. a {Filter} or a `Proc` + # object. When running the filters, we call each filter in turn, passing the + # event. The filter can change the event in any way desired but should make + # sure that it preserves the basic structure of the event: # # * Only use basic objects: `Hash`, `Array`, `String`, `Integer`, `Float`. # * Hash keys should always be strings @@ -78,8 +78,8 @@ module Rackstash end # Adds a new filter at the end of the filter chain. You can either give a - # callable object (e.g. a `Proc` or one of the {Filters}) or specify the - # filter with a given block. + # callable object (e.g. a `Proc` or a {Filter}) or specify the filter with + # a given block. # # @param filter_spec (see #build_filter) # @raise [TypeError] if no suitable filter could be created from @@ -236,8 +236,8 @@ module Rackstash alias size length # Prepends a new filter at the beginning of the filter chain. You can either - # give a callable object (e.g. a `Proc` or one of the {Filters}) or specify - # the filter with a given block. + # give a callable object (e.g. a `Proc` or a {Filter}) or specify the filter + # with a given block. # # @param filter_spec (see #build_filter) # @raise [TypeError] if we could not build a filter from the given @@ -296,16 +296,16 @@ module Rackstash # `#call`), we will directly return it. If you give a `Class` plus any # optional initializer arguments, we will return a new instance of that # class. When giving a `String` or `Symbol`, we will resolve it to a - # filter class from the {Rackstash::Filters} module and create a new + # filter class from the {Rackstash::Filter} module and create a new # instance of that class with the additional arguments given to # `initialize`. # @return [#call] a filter instance def build_filter(filter_spec, &block) if filter_spec.empty? - return Rackstash::Filters.build(block) if block_given? + return Rackstash::Filter.build(block) if block_given? raise ArgumentError, 'Need to specify a filter' else - Rackstash::Filters.build(*filter_spec, &block) + Rackstash::Filter.build(*filter_spec, &block) end end end diff --git a/lib/rackstash/flow.rb b/lib/rackstash/flow.rb index 1c9beb9..c30e431 100644 --- a/lib/rackstash/flow.rb +++ b/lib/rackstash/flow.rb @@ -7,7 +7,7 @@ require 'rackstash/adapter' require 'rackstash/encoder' -require 'rackstash/filters' +require 'rackstash/filter' require 'rackstash/filter_chain' module Rackstash @@ -19,7 +19,7 @@ module Rackstash # In order to transform and persist log events, a Flow uses several # components: # - # * Any number of {Filters} (zero or more). The filters can change the log + # * Any number of {Filter}s (zero or more). The filters can change the log # event before it is passed to the adapter by adding, changing, or removing # fields. The filters also have access to the array of {Message} objects in # `event["messages"]` which provide the original severity and timestamp of @@ -41,7 +41,7 @@ module Rackstash # encoder Rackstash::Encoder::JSON.new # # # Anonymize IPs in the remote_ip field. - # filter Rackstash::Filters::AnonymizeIPMask.new('remote_ip') + # filter Rackstash::Filter::AnonymizeIPMask.new('remote_ip') # # # Add the maximum severity of any message in the event into the # # severity and severity_label fields. @@ -70,9 +70,8 @@ module Rackstash # can be wrapped in an adapter. See {Adapter.[]} # @param encoder [#encode] an encoder, usually one of the {Encoder}s. If # this is not given, the adapter's default_encoder will be used. - # @param filters [Array<#call>] an array of filters. Can be one of the - # pre-defined {Filters}, a `Proc`, or any other object which responds to - # `call`. + # @param filters [Array<#call>] an array of filters. Can be a pre-defined + # {Filter}, a `Proc`, or any other object which responds to `call`. # @yieldparam flow [self] if the given block accepts an argument, we yield # `self` as a parameter, else, the block is directly executed in the # context of `self`. diff --git a/lib/rackstash/message.rb b/lib/rackstash/message.rb index b52e93f..c86c422 100644 --- a/lib/rackstash/message.rb +++ b/lib/rackstash/message.rb @@ -14,7 +14,7 @@ module Rackstash # # In the end, only the `message` field will be included in the final log # event. However, the stored meta-data can be useful when filtering or - # changing the messages of a log event using {Filters} later. + # changing the messages of a log event using a {Filter} later. # # All `Message` objects and their respective data are immutable after # initialization. diff --git a/spec/rackstash/filters/clear_color_spec.rb b/spec/rackstash/filter/clear_color_spec.rb similarity index 91% rename from spec/rackstash/filters/clear_color_spec.rb rename to spec/rackstash/filter/clear_color_spec.rb index cd09c22..d39a4aa 100644 --- a/spec/rackstash/filters/clear_color_spec.rb +++ b/spec/rackstash/filter/clear_color_spec.rb @@ -7,9 +7,9 @@ require 'spec_helper' -require 'rackstash/filters/clear_color' +require 'rackstash/filter/clear_color' -describe Rackstash::Filters::ClearColor do +describe Rackstash::Filter::ClearColor do let(:filter) { described_class.new } it 'removes any ANSI color codes from the message' do diff --git a/spec/rackstash/filters/default_fields_spec.rb b/spec/rackstash/filter/default_fields_spec.rb similarity index 93% rename from spec/rackstash/filters/default_fields_spec.rb rename to spec/rackstash/filter/default_fields_spec.rb index ec67bde..5a63800 100644 --- a/spec/rackstash/filters/default_fields_spec.rb +++ b/spec/rackstash/filter/default_fields_spec.rb @@ -7,9 +7,9 @@ require 'spec_helper' -require 'rackstash/filters/default_fields' +require 'rackstash/filter/default_fields' -describe Rackstash::Filters::DefaultFields do +describe Rackstash::Filter::DefaultFields do let(:event) { { 'foo' => 'v1', diff --git a/spec/rackstash/filters/default_tags_spec.rb b/spec/rackstash/filter/default_tags_spec.rb similarity index 91% rename from spec/rackstash/filters/default_tags_spec.rb rename to spec/rackstash/filter/default_tags_spec.rb index 40940fb..d809e73 100644 --- a/spec/rackstash/filters/default_tags_spec.rb +++ b/spec/rackstash/filter/default_tags_spec.rb @@ -7,9 +7,9 @@ require 'spec_helper' -require 'rackstash/filters/default_tags' +require 'rackstash/filter/default_tags' -describe Rackstash::Filters::DefaultTags do +describe Rackstash::Filter::DefaultTags do let(:event) { { 'key' => 'value' diff --git a/spec/rackstash/filters/rename_spec.rb b/spec/rackstash/filter/rename_spec.rb similarity index 93% rename from spec/rackstash/filters/rename_spec.rb rename to spec/rackstash/filter/rename_spec.rb index 219a31a..9ca1bc5 100644 --- a/spec/rackstash/filters/rename_spec.rb +++ b/spec/rackstash/filter/rename_spec.rb @@ -7,9 +7,9 @@ require 'spec_helper' -require 'rackstash/filters/rename' +require 'rackstash/filter/rename' -describe Rackstash::Filters::Rename do +describe Rackstash::Filter::Rename do let(:event) { { 'foo' => 'foo value', diff --git a/spec/rackstash/filters/replace_spec.rb b/spec/rackstash/filter/replace_spec.rb similarity index 93% rename from spec/rackstash/filters/replace_spec.rb rename to spec/rackstash/filter/replace_spec.rb index aaae562..98f19e5 100644 --- a/spec/rackstash/filters/replace_spec.rb +++ b/spec/rackstash/filter/replace_spec.rb @@ -7,9 +7,9 @@ require 'spec_helper' -require 'rackstash/filters/replace' +require 'rackstash/filter/replace' -describe Rackstash::Filters::Replace do +describe Rackstash::Filter::Replace do let(:event) { { 'foo' => 'foo value', diff --git a/spec/rackstash/filters/skip_event_spec.rb b/spec/rackstash/filter/skip_event_spec.rb similarity index 94% rename from spec/rackstash/filters/skip_event_spec.rb rename to spec/rackstash/filter/skip_event_spec.rb index 528a59a..ab6cdc5 100644 --- a/spec/rackstash/filters/skip_event_spec.rb +++ b/spec/rackstash/filter/skip_event_spec.rb @@ -7,9 +7,9 @@ require 'spec_helper' -require 'rackstash/filters/skip_event' +require 'rackstash/filter/skip_event' -describe Rackstash::Filters::SkipEvent do +describe Rackstash::Filter::SkipEvent do describe '#initialize' do it 'expects a condition' do expect { described_class.new }.to raise_error TypeError diff --git a/spec/rackstash/filters/truncate_message_spec.rb b/spec/rackstash/filter/truncate_message_spec.rb similarity index 97% rename from spec/rackstash/filters/truncate_message_spec.rb rename to spec/rackstash/filter/truncate_message_spec.rb index bf96f4f..4bc1157 100644 --- a/spec/rackstash/filters/truncate_message_spec.rb +++ b/spec/rackstash/filter/truncate_message_spec.rb @@ -7,9 +7,9 @@ require 'spec_helper' -require 'rackstash/filters/truncate_message' +require 'rackstash/filter/truncate_message' -describe Rackstash::Filters::TruncateMessage do +describe Rackstash::Filter::TruncateMessage do let(:max_size) { 36 } let(:args) { { selectors: [], cut: :bottom } } let(:filter) { described_class.new(max_size, **args) } diff --git a/spec/rackstash/filters/update_spec.rb b/spec/rackstash/filter/update_spec.rb similarity index 94% rename from spec/rackstash/filters/update_spec.rb rename to spec/rackstash/filter/update_spec.rb index ddac2d2..20f1d71 100644 --- a/spec/rackstash/filters/update_spec.rb +++ b/spec/rackstash/filter/update_spec.rb @@ -7,9 +7,9 @@ require 'spec_helper' -require 'rackstash/filters/update' +require 'rackstash/filter/update' -describe Rackstash::Filters::Update do +describe Rackstash::Filter::Update do let(:event) { { 'foo' => 'foo value', diff --git a/spec/rackstash/filters_spec.rb b/spec/rackstash/filter_spec.rb similarity index 95% rename from spec/rackstash/filters_spec.rb rename to spec/rackstash/filter_spec.rb index 08457b7..9a93f2f 100644 --- a/spec/rackstash/filters_spec.rb +++ b/spec/rackstash/filter_spec.rb @@ -8,9 +8,9 @@ require 'spec_helper' require 'securerandom' -require 'rackstash/filters' +require 'rackstash/filter' -describe Rackstash::Filters do +describe Rackstash::Filter do let(:filter_class) { Class.new } let(:random) { SecureRandom.hex(6) } let(:filter_class_name) { :"FilterClass#{random}" } @@ -60,7 +60,7 @@ describe Rackstash::Filters do end describe '.known' do - it 'returns a Hash with known Filters' do + it 'returns a Hash with known filters' do expect(described_class.known).not_to be_empty expect(described_class.known.keys).to all(