Search in sources :

Example 6 with GeoIpCache

use of org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache in project OpenSearch by opensearch-project.

the class GeoIpProcessorFactoryTests method testBuildDefaults.

public void testBuildDefaults() throws Exception {
    GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseReaders, new GeoIpCache(1000));
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    String processorTag = randomAlphaOfLength(10);
    GeoIpProcessor processor = factory.create(null, processorTag, null, config);
    assertThat(processor.getTag(), equalTo(processorTag));
    assertThat(processor.getField(), equalTo("_field"));
    assertThat(processor.getTargetField(), equalTo("geoip"));
    assertThat(processor.getDatabaseType(), equalTo("GeoLite2-City"));
    assertThat(processor.getProperties(), sameInstance(GeoIpProcessor.Factory.DEFAULT_CITY_PROPERTIES));
    assertFalse(processor.isIgnoreMissing());
}
Also used : HashMap(java.util.HashMap) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) GeoIpCache(org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)

Example 7 with GeoIpCache

use of org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache in project OpenSearch by opensearch-project.

the class GeoIpProcessorFactoryTests method testBuildWithAsnDbAndCityFields.

public void testBuildWithAsnDbAndCityFields() throws Exception {
    GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseReaders, new GeoIpCache(1000));
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("database_file", "GeoLite2-ASN.mmdb");
    EnumSet<GeoIpProcessor.Property> cityOnlyProperties = EnumSet.copyOf(GeoIpProcessor.Property.ALL_CITY_PROPERTIES);
    cityOnlyProperties.remove(GeoIpProcessor.Property.IP);
    String cityProperty = RandomPicks.randomFrom(Randomness.get(), cityOnlyProperties).toString();
    config.put("properties", Collections.singletonList(cityProperty));
    Exception e = expectThrows(OpenSearchParseException.class, () -> factory.create(null, null, null, config));
    assertThat(e.getMessage(), equalTo("[properties] illegal property value [" + cityProperty + "]. valid values are [IP, ASN, ORGANIZATION_NAME, NETWORK]"));
}
Also used : HashMap(java.util.HashMap) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) GeoIpCache(org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache) OpenSearchParseException(org.opensearch.OpenSearchParseException) IOException(java.io.IOException)

Example 8 with GeoIpCache

use of org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache in project OpenSearch by opensearch-project.

the class IngestGeoIpPluginTests method testInvalidInit.

public void testInvalidInit() {
    IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> new GeoIpCache(-1));
    assertEquals("geoip max cache size must be 0 or greater", ex.getMessage());
}
Also used : GeoIpCache(org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)

Example 9 with GeoIpCache

use of org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache in project OpenSearch by opensearch-project.

the class GeoIpProcessorTests method testAddressIsNotInTheDatabase.

public void testAddressIsNotInTheDatabase() throws Exception {
    GeoIpProcessor processor = new GeoIpProcessor(randomAlphaOfLength(10), null, "source_field", loader("/GeoLite2-City.mmdb"), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class), false, new GeoIpCache(1000), false);
    Map<String, Object> document = new HashMap<>();
    document.put("source_field", "127.0.0.1");
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getSourceAndMetadata().containsKey("target_field"), is(false));
}
Also used : HashMap(java.util.HashMap) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString) GeoIpCache(org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)

Example 10 with GeoIpCache

use of org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache in project OpenSearch by opensearch-project.

the class GeoIpProcessorTests method testNonExistentWithIgnoreMissing.

public void testNonExistentWithIgnoreMissing() throws Exception {
    GeoIpProcessor processor = new GeoIpProcessor(randomAlphaOfLength(10), null, "source_field", loader("/GeoLite2-City.mmdb"), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class), true, new GeoIpCache(1000), false);
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    processor.execute(ingestDocument);
    assertIngestDocument(originalIngestDocument, ingestDocument);
}
Also used : IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument) GeoIpCache(org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)

Aggregations

GeoIpCache (org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)33 HashMap (java.util.HashMap)26 Matchers.containsString (org.hamcrest.Matchers.containsString)26 IngestDocument (org.opensearch.ingest.IngestDocument)19 IngestDocumentMatcher.assertIngestDocument (org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument)17 Matchers.hasToString (org.hamcrest.Matchers.hasToString)13 Map (java.util.Map)9 IOException (java.io.IOException)7 OpenSearchParseException (org.opensearch.OpenSearchParseException)4 AbstractResponse (com.maxmind.geoip2.model.AbstractResponse)2 Path (java.nio.file.Path)2 List (java.util.List)2 Mockito.mock (org.mockito.Mockito.mock)2 InetAddresses (org.opensearch.common.network.InetAddresses)2 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)2 ArrayList (java.util.ArrayList)1