Skip to content

Commit

Permalink
JAVAFICATION: Port Loggable Module to Java
Browse files Browse the repository at this point in the history
  • Loading branch information
original-brownbear committed May 17, 2018
1 parent bd8f80e commit c0abde2
Show file tree
Hide file tree
Showing 44 changed files with 134 additions and 95 deletions.
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/api/service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# encoding: utf-8
require "logstash/instrument/collector"
require "logstash/util/loggable"

module LogStash
module Api
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
require "logstash/logging"

module LogStash module BootstrapCheck
class DefaultConfig
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/codecs/base.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# encoding: utf-8
require "logstash/event"
require "logstash/plugin"
require "logstash/logging"

# This is the base class for logstash codecs.
module LogStash::Codecs; class Base < LogStash::Plugin
Expand Down
5 changes: 2 additions & 3 deletions logstash-core/lib/logstash/compiler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'logstash/util/loggable'
require 'logstash/compiler/lscl/lscl_grammar'

java_import org.logstash.config.ir.PipelineIR
Expand All @@ -15,10 +14,10 @@ def self.compile_sources(sources_with_metadata, support_escapes)
input_graph = Graph.combine(*graph_sections.map {|s| s[:input] }).graph
output_graph = Graph.combine(*graph_sections.map {|s| s[:output] }).graph

filter_graph = graph_sections.reduce(nil) do |acc, s|
filter_graph = graph_sections.reduce(nil) do |acc, s|
filter_section = s[:filter]

if acc.nil?
if acc.nil?
filter_section
else
acc.chain(filter_section)
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/config/mixin.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# encoding: utf-8
require "logstash/plugins/registry"
require "logstash/logging"
require "logstash/util/password"
require "logstash/util/safe_uri"
require "logstash/version"
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/config/modules_common.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
require "logstash/util/loggable"
require "logstash/elasticsearch_client"
require "logstash/modules/kibana_client"
require "logstash/modules/elasticsearch_importer"
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/config/source/local.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# encoding: utf-8
require "logstash/config/source/base"
require "logstash/config/pipeline_config"
require "logstash/util/loggable"
require "uri"

module LogStash module Config module Source
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/config/source/modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require "logstash/config/source/base"
require "logstash/config/modules_common"
require "logstash/config/pipeline_config"
require "logstash/util/loggable"

module LogStash module Config module Source
class Modules < Base
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/config/source/multi_local.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# encoding: utf-8
require "logstash/config/source/local"
require "logstash/util/loggable"
require "logstash/pipeline_settings"

module LogStash module Config module Source
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/elasticsearch_client.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
require "logstash/logging"
require "elasticsearch"
require "elasticsearch/transport/transport/http/manticore"

Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/filters/base.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# encoding: utf-8
require "logstash/event"
require "logstash/logging"
require "logstash/plugin"
require "logstash/config/mixin"
require "logstash/util/decorators"
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/inputs/base.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# encoding: utf-8
require "logstash/event"
require "logstash/plugin"
require "logstash/logging"
require "logstash/config/mixin"
require "logstash/codecs/base"
require "logstash/util/decorators"
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/instrument/collector.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# encoding: utf-8
require "logstash/instrument/snapshot"
require "logstash/instrument/metric_store"
require "logstash/util/loggable"
require "concurrent/timer_task"
require "observer"
require "singleton"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
require "logstash/util/loggable"
require "logstash/util"
require "concurrent"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# encoding: utf-8
require "pathname"
require "logstash/util/loggable"

# Logic from elasticsearch/core/src/main/java/org/elasticsearch/monitor/os/OsProbe.java
# Move to ruby to remove any existing dependency
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/instrument/snapshot.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
require "logstash/util/loggable"

module LogStash module Instrument
class Snapshot
Expand Down
2 changes: 0 additions & 2 deletions logstash-core/lib/logstash/modules/cli_parser.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# encoding: utf-8
require "logstash/logging"

module LogStash module Modules class CLIParser
include LogStash::Util::Loggable

Expand Down
2 changes: 0 additions & 2 deletions logstash-core/lib/logstash/modules/elasticsearch_config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# encoding: utf-8
require "logstash/logging"

require_relative "elasticsearch_resource"

module LogStash module Modules class ElasticsearchConfig
Expand Down
2 changes: 0 additions & 2 deletions logstash-core/lib/logstash/modules/elasticsearch_importer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# encoding: utf-8
require "logstash/logging"

module LogStash module Modules class ElasticsearchImporter
include LogStash::Util::Loggable

Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/modules/file_reader.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
require "logstash/logging"
require "logstash/json"

module LogStash module Modules class FileReader
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/modules/kibana_client.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
require "logstash/logging"
require "logstash/json"
require "manticore"

Expand Down
2 changes: 0 additions & 2 deletions logstash-core/lib/logstash/modules/kibana_config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# encoding: utf-8
require "logstash/logging"

require_relative "file_reader"
require_relative "kibana_settings"
require_relative "kibana_dashboards"
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/modules/kibana_dashboards.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
require "logstash/logging"
require_relative "kibana_base"

module LogStash module Modules class KibanaDashboards < KibanaBase
Expand Down
2 changes: 0 additions & 2 deletions logstash-core/lib/logstash/modules/kibana_importer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# encoding: utf-8
require "logstash/logging"

module LogStash module Modules class KibanaImporter
include LogStash::Util::Loggable

Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/modules/kibana_settings.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
require "logstash/logging"
require_relative "kibana_base"

module LogStash module Modules class KibanaSettings < KibanaBase
Expand Down
2 changes: 0 additions & 2 deletions logstash-core/lib/logstash/modules/scaffold.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# encoding: utf-8
require "logstash/logging"
require "logstash/util/loggable"
require "erb"

require_relative "elasticsearch_config"
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/modules/settings_merger.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# encoding: utf-8
require "logstash/util"
require "logstash/util/loggable"

module LogStash module Modules module SettingsMerger
include LogStash::Util::Loggable
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/outputs/base.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# encoding: utf-8
require "logstash/event"
require "logstash/logging"
require "logstash/plugin"
require "logstash/config/mixin"
require "concurrent/atomic/atomic_fixnum"
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/pipeline_action/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require "logstash/pipeline"
require "logstash/java_pipeline"
require "logstash/converge_result"
require "logstash/util/loggable"

module LogStash module PipelineAction
class Create < Base
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/pipeline_action/reload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require "logstash/pipeline_action/base"
require "logstash/pipeline_action/create"
require "logstash/pipeline_action/stop"
require "logstash/util/loggable"
require "logstash/converge_result"

module LogStash module PipelineAction
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
require "logstash/logging"
require "logstash/config/mixin"
require "concurrent"
require "securerandom"
Expand Down
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/plugins/registry.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# encoding: utf-8
require "rubygems/package"
require "logstash/util/loggable"
require "logstash/plugin"
require "logstash/plugins/hooks_registry"
require "logstash/modules/scaffold"
Expand Down
9 changes: 4 additions & 5 deletions logstash-core/lib/logstash/settings.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
require "logstash/util/loggable"
require "fileutils"
require "logstash/util/byte_value"
require "logstash/util/substitution_variables"
Expand All @@ -10,7 +9,7 @@ class Settings

include LogStash::Util::SubstitutionVariables
include LogStash::Util::Loggable

def initialize
@settings = {}
# Theses settings were loaded from the yaml file
Expand Down Expand Up @@ -119,15 +118,15 @@ def from_yaml(yaml_path, file_name="logstash.yml")
self.merge(deep_replace(flatten_hash(settings)), true)
self
end

def post_process
if @post_process_callbacks
@post_process_callbacks.each do |callback|
callback.call(self)
end
end
end

def on_post_process(&block)
@post_process_callbacks ||= []
@post_process_callbacks << block
Expand Down Expand Up @@ -439,7 +438,7 @@ class WritableDirectory < Setting
def initialize(name, default=nil, strict=false)
super(name, ::String, default, strict)
end

def validate(path)
super(path)

Expand Down
31 changes: 1 addition & 30 deletions logstash-core/lib/logstash/util/loggable.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
# encoding: utf-8
require "logstash/logging/logger"

module LogStash module Util
module Loggable
def self.included(klass)

def klass.log4j_name
ruby_name = self.name || self.class.name || self.class.to_s
ruby_name.gsub('::', '.').downcase
end

def klass.logger
@logger ||= LogStash::Logging::Logger.new(log4j_name)
end

def klass.slow_logger(warn_threshold, info_threshold, debug_threshold, trace_threshold)
@slow_logger ||= LogStash::Logging::SlowLogger.new(log4j_name, warn_threshold, info_threshold, debug_threshold, trace_threshold)
end

def logger
self.class.logger
end

def slow_logger(warn_threshold, info_threshold, debug_threshold, trace_threshold)
self.class.slow_logger(warn_threshold, info_threshold, debug_threshold, trace_threshold)
end
end
end
end; end
# Keeping this file for backwards compatibility with plugins that include it directly.
2 changes: 0 additions & 2 deletions logstash-core/lib/logstash/util/substitution_variables.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# encoding: utf-8
require "logstash/logging"
require "logstash/util/loggable"
require "logstash/util/secretstore"

module ::LogStash::Util::SubstitutionVariables
Expand Down
8 changes: 4 additions & 4 deletions logstash-core/spec/logstash/config/mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:password) { "sekret" }
let(:double_logger) { double("logger").as_null_object }

subject do
subject do
Class.new(LogStash::Filters::Base) do
include LogStash::Config::Mixin
config_name "test_deprecated"
Expand Down Expand Up @@ -151,7 +151,7 @@

it "should raise a configuration error" do
expect { subject.required_strings }.to raise_error(LogStash::ConfigurationError)
end
end
end

context "with no value specified" do
Expand All @@ -160,7 +160,7 @@
it "should raise a configuration error" do
expect { subject.required_strings }.to raise_error(LogStash::ConfigurationError)
end
end
end
end
end

Expand Down Expand Up @@ -208,7 +208,7 @@

shared_examples("safe URI") do |options|
options ||= {}

subject { klass.new("uri" => uri_str) }

it "should be a SafeURI object" do
Expand Down
1 change: 0 additions & 1 deletion logstash-core/spec/logstash/modules/cli_parser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "spec_helper"
require "logstash/logging"
require "logstash/modules/cli_parser"

describe LogStash::Modules::CLIParser do
Expand Down
4 changes: 2 additions & 2 deletions logstash-core/spec/logstash/pipeline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class TestPipeline < LogStash::Pipeline
after do
pipeline.shutdown
end

it "should call close of output without output-workers" do
pipeline.run

Expand All @@ -395,7 +395,7 @@ class TestPipeline < LogStash::Pipeline
# cause the suite to fail :(
pipeline.close
end

it "should use LIR provided IDs" do
expect(pipeline.inputs.first.id).to eq(pipeline.lir.input_plugin_vertices.first.id)
expect(pipeline.filters.first.id).to eq(pipeline.lir.filter_plugin_vertices.first.id)
Expand Down
Loading

0 comments on commit c0abde2

Please sign in to comment.