Skip to content

Commit

Permalink
Geoip processor should respect the ignore_missing parameter in case o…
Browse files Browse the repository at this point in the history
…f missing database (#87793) (#88051)

If database is missing then respect ignore_missing parameter configured
on the geoip processor. If ignore_missing is enabled then the document
should not be tagged. In this case the document shouldn't be tagged.

Closes #87345
  • Loading branch information
martijnvg committed Jun 27, 2022
1 parent f43bfbd commit 81e948a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/changelog/87793.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 87793
summary: Geoip processor should respect the `ignore_missing` in case of missing database
area: Ingest
type: bug
issues:
- 87345
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public IngestDocument execute(IngestDocument ingestDocument) throws IOException

DatabaseReaderLazyLoader lazyLoader = this.supplier.get();
if (lazyLoader == null) {
tag(ingestDocument, databaseFile);
if (ignoreMissing == false) {
tag(ingestDocument, databaseFile);
}
return ingestDocument;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,51 @@ public void testInvalidDatabase() throws Exception {
assertThat(ingestDocument.getSourceAndMetadata(), hasEntry("tags", List.of("_geoip_expired_database")));
}

public void testNoDatabase() throws Exception {
GeoIpProcessor processor = new GeoIpProcessor(
randomAlphaOfLength(10),
null,
"source_field",
() -> null,
() -> true,
"target_field",
EnumSet.allOf(GeoIpProcessor.Property.class),
false,
false,
"GeoLite2-City"
);

Map<String, Object> document = new HashMap<>();
document.put("source_field", "8.8.8.8");
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
processor.execute(ingestDocument);
assertThat(ingestDocument.getSourceAndMetadata().containsKey("target_field"), is(false));
assertThat(ingestDocument.getSourceAndMetadata(), hasEntry("tags", List.of("_geoip_database_unavailable_GeoLite2-City")));
}

public void testNoDatabase_ignoreMissing() throws Exception {
GeoIpProcessor processor = new GeoIpProcessor(
randomAlphaOfLength(10),
null,
"source_field",
() -> null,
() -> true,
"target_field",
EnumSet.allOf(GeoIpProcessor.Property.class),
true,
false,
"GeoLite2-City"
);

Map<String, Object> document = new HashMap<>();
document.put("source_field", "8.8.8.8");
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
processor.execute(ingestDocument);
assertIngestDocument(originalIngestDocument, ingestDocument);
}

private CheckedSupplier<DatabaseReaderLazyLoader, IOException> loader(final String path) {
final Supplier<InputStream> databaseInputStreamSupplier = () -> GeoIpProcessor.class.getResourceAsStream(path);
final CheckedSupplier<DatabaseReader, IOException> loader = () -> new DatabaseReader.Builder(databaseInputStreamSupplier.get())
Expand Down

0 comments on commit 81e948a

Please sign in to comment.