Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
Updated Elastic dependency to 7.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsbasjes committed Aug 31, 2020
1 parent 9f6d465 commit f747dd3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ v5.20-SNAPSHOT
- Disable sonarcloud on JDK 8
- Updated UDF dependencies
- Apache Nifi 1.12.0
- Elastic Search/Logstash 7.9.0

v5.19
===
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<logparser.version>5.5</logparser.version>

<!-- Elastic tools -->
<elastic.version>7.8.1</elastic.version>
<elastic.version>7.9.0</elastic.version>
<logstash.version>${elastic.version}</logstash.version>
<elasticsearch.version>${elastic.version}</elasticsearch.version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.elasticsearch.ingest.IngestDocument;
import org.elasticsearch.ingest.Processor;

import java.util.Collection;
import java.util.List;
import java.util.Map;

Expand All @@ -43,39 +42,15 @@ public class YauaaProcessor extends AbstractProcessor {

private final UserAgentAnalyzer uaa;

public YauaaProcessor(String tag,
String field,
String targetField,
Collection<String> fieldNames,
Integer cacheSize,
Integer preheat,
String extraRules) {
super(tag);
YauaaProcessor(String tag,
String description,
String field,
String targetField,
UserAgentAnalyzer uaa) {
super(tag, description);
this.field = field;
this.targetField = targetField;

UserAgentAnalyzerBuilder builder = UserAgentAnalyzer
.newBuilder()
.dropTests()
.immediateInitialization();

if (cacheSize >= 0) {
builder.withCache(cacheSize);
}

if (preheat >= 0) {
builder.preheat(preheat);
}

if (extraRules != null) {
builder.addYamlRule(extraRules);
}

if (fieldNames != null && !fieldNames.isEmpty()) {
builder.withFields(fieldNames);
}

this.uaa = builder.build();
this.uaa = uaa;
}

@Override
Expand All @@ -98,15 +73,36 @@ public String getType() {
public static final class Factory implements Processor.Factory {

@Override
public YauaaProcessor create(Map<String, Processor.Factory> factories, String tag, Map<String, Object> config) {
public Processor create(Map<String, Processor.Factory> processorFactories, String tag, String description, Map<String, Object> config) {
String field = readStringProperty(TYPE, tag, config, "field");
String targetField = readStringProperty(TYPE, tag, config, "target_field", "user_agent");
List<String> fieldNames = readOptionalList(TYPE, tag, config, "fieldNames");
Integer cacheSize = readIntProperty(TYPE, tag, config, "cacheSize", -1);
Integer preheat = readIntProperty(TYPE, tag, config, "preheat", -1);
String extraRules = readOptionalStringProperty(TYPE, tag, config, "extraRules");

return new YauaaProcessor(tag, field, targetField, fieldNames, cacheSize, preheat, extraRules);
UserAgentAnalyzerBuilder builder = UserAgentAnalyzer
.newBuilder()
.dropTests()
.immediateInitialization();

if (cacheSize >= 0) {
builder.withCache(cacheSize);
}

if (preheat >= 0) {
builder.preheat(preheat);
}

if (extraRules != null) {
builder.addYamlRule(extraRules);
}

if (fieldNames != null && !fieldNames.isEmpty()) {
builder.withFields(fieldNames);
}

return new YauaaProcessor(tag, description, field, targetField, builder.build());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.elasticsearch.plugin.ingest.yauaa;

import nl.basjes.parse.useragent.UserAgentAnalyzer;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.ingest.IngestDocument;
import org.elasticsearch.ingest.Processor;
Expand All @@ -26,7 +27,6 @@

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.hamcrest.Matchers.hasEntry;
Expand All @@ -49,7 +49,8 @@ public void testThatProcessorWorks() {
"Chrome/53.0.2785.124 Mobile Safari/537.36");
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", null, 42L, VersionType.EXTERNAL, document);

YauaaProcessor processor = new YauaaProcessor("tag", SOURCE_FIELD, TARGET_FIELD, null, -1, -1, null);
UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer.newBuilder().build();
YauaaProcessor processor = new YauaaProcessor("tag", "description", SOURCE_FIELD, TARGET_FIELD, userAgentAnalyzer);
Map<String, Object> data = processor.execute(ingestDocument).getSourceAndMetadata();

MatcherAssert.assertThat(data, hasKey(TARGET_FIELD));
Expand Down Expand Up @@ -91,12 +92,13 @@ public void testExtraRules() {
"Chrome/53.0.2785.124 Mobile Safari/537.36");
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", null, 42L, VersionType.EXTERNAL, document);

List<String> fieldNames = Arrays.asList("DeviceClass", "DeviceBrand", "DeviceName", "AgentNameVersionMajor", "FirstProductName");
Integer cacheSize = 10;
Integer preheat = 10;
String extraRules = "config:\n- matcher:\n extract:\n - 'FirstProductName : 1 :agent.(1)product.(1)name'\n";

YauaaProcessor processor = new YauaaProcessor("tag", SOURCE_FIELD, TARGET_FIELD, fieldNames, cacheSize, preheat, extraRules);
UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer.newBuilder()
.withFields(Arrays.asList("DeviceClass", "DeviceBrand", "DeviceName", "AgentNameVersionMajor", "FirstProductName"))
.withCache(10)
.preheat(10)
.addYamlRule("config:\n- matcher:\n extract:\n - 'FirstProductName : 1 :agent.(1)product.(1)name'\n")
.build();
YauaaProcessor processor = new YauaaProcessor("tag", "description", SOURCE_FIELD, TARGET_FIELD, userAgentAnalyzer);
Map<String, Object> data = processor.execute(ingestDocument).getSourceAndMetadata();

MatcherAssert.assertThat(data, hasKey(TARGET_FIELD));
Expand Down Expand Up @@ -160,7 +162,7 @@ public void testIngestPlugin() throws Exception {
configuration.put("preheat", 10);
configuration.put("extraRules", "config:\n- matcher:\n extract:\n - 'FirstProductName : 1 :agent.(1)product.(1)name'\n");

Processor processor = yauaaFactory.create(processors, "tag", configuration);
Processor processor = yauaaFactory.create(processors, "tag", "description", configuration);

assertEquals("yauaa", processor.getType());

Expand Down

0 comments on commit f747dd3

Please sign in to comment.