logstash-filter-java_filter_example icon indicating copy to clipboard operation
logstash-filter-java_filter_example copied to clipboard

Sample code and instructions for Java plugins will omit common configuration (eg. 'id', 'tags')

Open cameronkerrnz opened this issue 4 years ago • 0 comments

Logstash 7.9 at least; although as a documentation and example-code issue, it's been around since the Java API was released.

The official instructions and example source code for creatingpure-Java input/filter/output/codec plugins for Logstash leaves out some code which means plugins created according to the instructions will cause a configuration failure such as this:

[ERROR][co.elastic.logstash.api.PluginHelper] Unknown setting 'id' specified for plugin 'mmdb'

This log appears to come from PluginUtil, despite the class indicated in the log.

The provided instructions and code will have you use the following (How to write a Java input plugin):

    @Override
    public Collection<PluginConfigSpec<?>> configSchema() {
        return Arrays.asList(EVENT_COUNT_CONFIG, PREFIX_CONFIG);
    }

This should instead be something like the following:

import co.elastic.logstash.api.PluginHelper;
...

    @Override
    public Collection<PluginConfigSpec<?>> configSchema() {
        
        // The Java example I was looking at doesn't tell
        // you that you need to include the common config
        // too, nor does it show how.
        // 
        // This form of commonFilterSettings, with an
        // argument, will merge the provided settings with
        // the common ones for filter.
        //
        // Note that the checking of arguments is not done
        // when we run the unit-tests; that's not our
        // code. You may therefore encounter this during
        // integration testing instead.

        return PluginHelper.commonFilterSettings(
            Arrays.asList(
                SOURCE_CONFIG,
                TARGET_CONFIG,
                DATABASE_FILENAME_CONFIG,
                CACHE_SIZE_CONFIG,
                FIELDS_CONFIG));
    }

See the source for commonFilterSetttings

Most of the Java plugins in logstash-core get this right, such as the generator, stdin, uuid; although none of the output plugins do; though according to the documentation they should.

PS. I'm attaching this as an issue to the filter plugin, just because that's what I was working from, but clearly this affects multiple repositories and the documentation, so I'm happy to file this on another repo if you like (and can point me in the correct direction).

Cheers, Cameron

cameronkerrnz avatar Sep 29 '20 11:09 cameronkerrnz