-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GitHub-issue#253 : Implemented GeoIP processor integration test #2927
Merged
kkondaka
merged 8 commits into
opensearch-project:main
from
venkataraopasyavula:geoip-processor-integration-test
Jul 14, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
607bba5
GitHub-issue#253 : Implemented GeoIP processor integration test
venkataraopasyavula 063851e
Merge branch 'opensearch-project:main' into geoip-processor-integrati…
venkataraopasyavula c2357f4
GitHub-issue#253 : Implemented GeoIP processor integration test
venkataraopasyavula d4a3d31
Merge branch 'opensearch-project:main' into geoip-processor-integrati…
venkataraopasyavula 4099f54
GitHub-issue#253 : Implemented GeoIP processor integration test
venkataraopasyavula 248d527
GitHub-issue#253 : Implemented GeoIP processor integration test
venkataraopasyavula a0dbffd
Merge branch 'opensearch-project:main' into geoip-processor-integrati…
venkataraopasyavula 53d7e26
GitHub-issue#253 : Implemented GeoIP processor integration test
venkataraopasyavula File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 26 additions & 0 deletions
26
...src/integrationTest/java/org/opensearch/dataprepper/plugins/processor/GeoIPInputJson.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,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.processor; | ||
|
||
public class GeoIPInputJson { | ||
Peer PeerObject; | ||
private String status; | ||
|
||
// Getter Methods | ||
public Peer getPeer() { | ||
return PeerObject; | ||
} | ||
public String getStatus() { | ||
return status; | ||
} | ||
// Setter Methods | ||
public void setPeer( Peer peerObject ) { | ||
this.PeerObject = peerObject; | ||
} | ||
public void setStatus( String status ) { | ||
this.status = status; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
...ionTest/java/org/opensearch/dataprepper/plugins/processor/GeoIPProcessorUrlServiceIT.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,102 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.processor; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.opensearch.dataprepper.plugins.processor.utils.IPValidationcheck; | ||
|
||
import java.io.File; | ||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class GeoIPProcessorUrlServiceIT { | ||
|
||
private ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory().enable(YAMLGenerator.Feature.USE_PLATFORM_LINE_BREAKS)); | ||
private String tempPath; | ||
private GeoIPProcessorConfig geoIPProcessorConfig; | ||
private String maxmindLicenseKey; | ||
private GeoIPProcessorService geoIPProcessorService; | ||
private GeoIPInputJson geoIPInputJson; | ||
private String jsonInput; | ||
private static final String TEMP_PATH_FOLDER = "GeoIP"; | ||
public static final String DATABASE_1 = "first_database"; | ||
public static final String URL_SUFFIX = "&suffix=tar.gz"; | ||
|
||
@BeforeEach | ||
public void setUp() throws JsonProcessingException { | ||
|
||
maxmindLicenseKey = System.getProperty("tests.geoipProcessor.maxmindLicenseKey"); | ||
|
||
jsonInput = "{\"peer\": {\"ip\": \"8.8.8.8\", \"host\": \"example.org\" }, \"status\": \"success\"}"; | ||
|
||
geoIPInputJson = objectMapper.readValue(jsonInput, GeoIPInputJson.class); | ||
tempPath = System.getProperty("java.io.tmpdir")+ File.separator + TEMP_PATH_FOLDER; | ||
|
||
String asnUrl = "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=" + maxmindLicenseKey + URL_SUFFIX; | ||
String cityUrl = "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=" + maxmindLicenseKey + URL_SUFFIX; | ||
String countryUrl = "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=" + maxmindLicenseKey + URL_SUFFIX; | ||
|
||
String pipelineConfig = " aws:\n" + | ||
" region: us-east-2\n" + | ||
" sts_role_arn: \"arn:aws:iam::123456789:role/data-prepper-execution-role\"\n" + | ||
" keys:\n" + | ||
" - key:\n" + | ||
" source: \"/peer/ip\"\n" + | ||
" target: \"target1\"\n" + | ||
" - key:\n" + | ||
" source: \"/peer/ip2\"\n" + | ||
" target: \"target2\"\n" + | ||
" attributes: [\"city_name\",\"country_name\"]\n" + | ||
" service_type:\n" + | ||
" maxmind:\n" + | ||
" database_path:\n" + | ||
" - url: " + asnUrl + "\n" + | ||
" - url: " + cityUrl + "\n" + | ||
" - url: " + countryUrl + "\n" + | ||
" load_type: \"cache\"\n" + | ||
" cache_size: 8192\n" + | ||
" cache_refresh_schedule: PT3M"; | ||
|
||
objectMapper.registerModule(new JavaTimeModule()); | ||
this.geoIPProcessorConfig = objectMapper.readValue(pipelineConfig, GeoIPProcessorConfig.class); | ||
} | ||
|
||
public GeoIPProcessorService createObjectUnderTest() { | ||
return new GeoIPProcessorService(geoIPProcessorConfig, tempPath); | ||
} | ||
|
||
@Test | ||
void verify_enrichment_of_data_from_maxmind_url() throws UnknownHostException { | ||
|
||
Map<String, Object> geoData = new HashMap<>(); | ||
this.geoIPProcessorService = createObjectUnderTest(); | ||
String ipAddress = geoIPInputJson.getPeer().getIp(); | ||
if (IPValidationcheck.isPublicIpAddress(ipAddress)) { | ||
InetAddress inetAddress = InetAddress.getByName(ipAddress); | ||
//All attributes are considered by default with the null value | ||
geoData = geoIPProcessorService.getGeoData(inetAddress, null); | ||
|
||
assertThat(geoData.get("country_iso_code"), equalTo("US")); | ||
assertThat(geoData.get("ip"), equalTo("8.8.8.8")); | ||
assertThat(geoData.get("country_name"), equalTo("United States")); | ||
assertThat(geoData.get("organization_name"), equalTo("GOOGLE")); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...processor/src/integrationTest/java/org/opensearch/dataprepper/plugins/processor/Peer.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,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.processor; | ||
|
||
public class Peer { | ||
private String ip; | ||
private String host; | ||
|
||
// Getter Methods | ||
public String getIp() { | ||
return ip; | ||
} | ||
public String getHost() { | ||
return host; | ||
} | ||
// Setter Methods | ||
public void setIp( String ip ) { | ||
this.ip = ip; | ||
} | ||
public void setHost( String host ) { | ||
this.host = host; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually, you can do this by Mocking the config. There are many IT.java files where you can see how to do this. Take a look at
./data-prepper-plugins/aggregate-processor/src/test/java/org/opensearch/dataprepper/plugins/processor/aggregate/AggregateProcessorIT.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per David suggestion, we have added yaml input (configuration) in other plugins like S3Source.
For example in S3Source: S3SelectCSVOptionTest.java, S3ScanScanOptionsTest.java.
In case integration testing, the mocking should be avoided as much as possible.