-
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.
- Loading branch information
1 parent
dc174b2
commit 3dd1288
Showing
66 changed files
with
4,420 additions
and
357 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,2 @@ | ||
# encoding: utf-8 | ||
# | ||
module LogStash | ||
class FilterDelegator | ||
extend Forwardable | ||
DELEGATED_METHODS = [ | ||
:register, | ||
:close, | ||
:threadsafe?, | ||
:do_close, | ||
:do_stop, | ||
:periodic_flush, | ||
:reloadable? | ||
] | ||
def_delegators :@filter, *DELEGATED_METHODS | ||
|
||
attr_reader :id | ||
|
||
def initialize(filter, id) | ||
@klass = filter.class | ||
@id = id | ||
@filter = filter | ||
|
||
# Scope the metrics to the plugin | ||
namespaced_metric = filter.metric | ||
@metric_events = namespaced_metric.namespace(:events) | ||
@metric_events_in = @metric_events.counter(:in) | ||
@metric_events_out = @metric_events.counter(:out) | ||
@metric_events_time = @metric_events.counter(:duration_in_millis) | ||
namespaced_metric.gauge(:name, config_name) | ||
|
||
# Not all the filters will do bufferings | ||
define_flush_method if @filter.respond_to?(:flush) | ||
end | ||
|
||
def config_name | ||
@klass.config_name | ||
end | ||
|
||
def multi_filter(events) | ||
@metric_events_in.increment(events.size) | ||
|
||
start_time = java.lang.System.nano_time | ||
new_events = @filter.multi_filter(events) | ||
@metric_events_time.increment((java.lang.System.nano_time - start_time) / 1_000_000) | ||
|
||
# There is no guarantee in the context of filter | ||
# that EVENTS_IN == EVENTS_OUT, see the aggregates and | ||
# the split filter | ||
c = new_events.count { |event| !event.cancelled? } | ||
@metric_events_out.increment(c) if c > 0 | ||
new_events | ||
end | ||
|
||
private | ||
def define_flush_method | ||
define_singleton_method(:flush) do |options = {}| | ||
# we also need to trace the number of events | ||
# coming from a specific filters. | ||
new_events = @filter.flush(options) | ||
|
||
# Filter plugins that does buffering or spooling of events like the | ||
# `Logstash-filter-aggregates` can return `NIL` and will flush on the next flush ticks. | ||
@metric_events_out.increment(new_events.size) if new_events && new_events.size > 0 | ||
new_events | ||
end | ||
end | ||
end | ||
end | ||
# The contents of this file have been ported to Java. It is included for for compatibility | ||
# with plugins that directly include it. |
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
106 changes: 106 additions & 0 deletions
106
logstash-core/src/main/java/co/elastic/logstash/api/Configuration.java
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,106 @@ | ||
package co.elastic.logstash.api; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
/** | ||
* Configuration for Logstash Java plugins. | ||
*/ | ||
public final class Configuration { | ||
|
||
private final Map<String, Object> rawSettings; | ||
|
||
/** | ||
* @param raw Configuration Settings Map. Values are serialized. | ||
*/ | ||
public Configuration(final Map<String, Object> raw) { | ||
this.rawSettings = raw; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> T get(final PluginConfigSpec<T> configSpec) { | ||
if (rawSettings.containsKey(configSpec.name())) { | ||
Object o = rawSettings.get(configSpec.name()); | ||
if (configSpec.type().isAssignableFrom(o.getClass())) { | ||
return (T) o; | ||
} else { | ||
throw new IllegalStateException( | ||
String.format("Setting value for '%s' of type '%s' incompatible with defined type of '%s'", | ||
configSpec.name(), o.getClass(), configSpec.type())); | ||
} | ||
} else { | ||
return configSpec.defaultValue(); | ||
} | ||
} | ||
|
||
public Object getRawValue(final PluginConfigSpec<?> configSpec) { | ||
return rawSettings.get(configSpec.name()); | ||
} | ||
|
||
public boolean contains(final PluginConfigSpec<?> configSpec) { | ||
return rawSettings.containsKey(configSpec.name()); | ||
} | ||
|
||
public Collection<String> allKeys() { | ||
return rawSettings.keySet(); | ||
} | ||
|
||
public static PluginConfigSpec<String> stringSetting(final String name) { | ||
return new PluginConfigSpec<>( | ||
name, String.class, null, false, false | ||
); | ||
} | ||
|
||
public static PluginConfigSpec<String> stringSetting(final String name, final String defaultValue) { | ||
return new PluginConfigSpec<>( | ||
name, String.class, defaultValue, false, false | ||
); | ||
} | ||
|
||
public static PluginConfigSpec<String> requiredStringSetting(final String name) { | ||
return new PluginConfigSpec<>(name, String.class, null, false, true); | ||
} | ||
|
||
public static PluginConfigSpec<Long> numSetting(final String name) { | ||
return new PluginConfigSpec<>( | ||
name, Long.class, null, false, false | ||
); | ||
} | ||
|
||
public static PluginConfigSpec<Long> numSetting(final String name, final long defaultValue) { | ||
return new PluginConfigSpec<>( | ||
name, Long.class, defaultValue, false, false | ||
); | ||
} | ||
|
||
public static PluginConfigSpec<Path> pathSetting(final String name) { | ||
return new PluginConfigSpec<>(name, Path.class, null, false, false); | ||
} | ||
|
||
public static PluginConfigSpec<Boolean> booleanSetting(final String name) { | ||
return new PluginConfigSpec<>(name, Boolean.class, null, false, false); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static PluginConfigSpec<Map<String, String>> hashSetting(final String name) { | ||
return new PluginConfigSpec(name, Map.class, null, false, false); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static <T> PluginConfigSpec<Map<String, T>> requiredFlatHashSetting( | ||
final String name, Class<T> type) { | ||
//TODO: enforce subtype | ||
return new PluginConfigSpec( | ||
name, Map.class, null, false, true | ||
); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static PluginConfigSpec<Map<String, Configuration>> requiredNestedHashSetting( | ||
final String name, final Collection<PluginConfigSpec<?>> spec) { | ||
return new PluginConfigSpec( | ||
name, Map.class, null, false, true, spec | ||
); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
logstash-core/src/main/java/co/elastic/logstash/api/Context.java
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,13 @@ | ||
package co.elastic.logstash.api; | ||
|
||
import org.logstash.common.io.DeadLetterQueueWriter; | ||
|
||
/** | ||
* Holds Logstash Environment. | ||
*/ | ||
public final class Context { | ||
|
||
public DeadLetterQueueWriter dlqWriter() { | ||
return null; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
logstash-core/src/main/java/co/elastic/logstash/api/LogstashPlugin.java
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,16 @@ | ||
package co.elastic.logstash.api; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Logstash plugin annotation for finding plugins on the classpath and setting their name as used | ||
* in the configuration syntax. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface LogstashPlugin { | ||
String name(); | ||
} |
8 changes: 8 additions & 0 deletions
8
logstash-core/src/main/java/co/elastic/logstash/api/Plugin.java
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,8 @@ | ||
package co.elastic.logstash.api; | ||
|
||
import java.util.Collection; | ||
|
||
public interface Plugin { | ||
|
||
Collection<PluginConfigSpec<?>> configSchema(); | ||
} |
Oops, something went wrong.