Skip to content

Commit ac25dbe

Browse files
authored
Fix IPinfo geolocation schema (#115147)
1 parent 68f0f00 commit ac25dbe

File tree

10 files changed

+50
-43
lines changed

10 files changed

+50
-43
lines changed

docs/changelog/115147.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 115147
2+
summary: Fix IPinfo geolocation schema
3+
area: Ingest Node
4+
type: bug
5+
issues: []

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/IpinfoIpDataLookups.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ public record CountryResult(
218218
public record GeolocationResult(
219219
String city,
220220
String country,
221-
Double latitude,
222-
Double longitude,
221+
Double lat,
222+
Double lng,
223223
String postalCode,
224224
String region,
225225
String timezone
@@ -229,14 +229,15 @@ public record GeolocationResult(
229229
public GeolocationResult(
230230
@MaxMindDbParameter(name = "city") String city,
231231
@MaxMindDbParameter(name = "country") String country,
232-
@MaxMindDbParameter(name = "latitude") String latitude,
233-
@MaxMindDbParameter(name = "longitude") String longitude,
234-
// @MaxMindDbParameter(name = "network") String network, // for now we're not exposing this
232+
// @MaxMindDbParameter(name = "geoname_id") String geonameId, // for now we're not exposing this
233+
@MaxMindDbParameter(name = "lat") String lat,
234+
@MaxMindDbParameter(name = "lng") String lng,
235235
@MaxMindDbParameter(name = "postal_code") String postalCode,
236236
@MaxMindDbParameter(name = "region") String region,
237+
// @MaxMindDbParameter(name = "region_code") String regionCode, // for now we're not exposing this
237238
@MaxMindDbParameter(name = "timezone") String timezone
238239
) {
239-
this(city, country, parseLocationDouble(latitude), parseLocationDouble(longitude), postalCode, region, timezone);
240+
this(city, country, parseLocationDouble(lat), parseLocationDouble(lng), postalCode, region, timezone);
240241
}
241242
}
242243

@@ -395,8 +396,8 @@ protected Map<String, Object> transform(final Result<GeolocationResult> result)
395396
}
396397
}
397398
case LOCATION -> {
398-
Double latitude = response.latitude;
399-
Double longitude = response.longitude;
399+
Double latitude = response.lat;
400+
Double longitude = response.lng;
400401
if (latitude != null && longitude != null) {
401402
Map<String, Object> locationObject = new HashMap<>();
402403
locationObject.put("lat", latitude);

modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ public void testMaxmindCity() throws Exception {
8282
}
8383

8484
public void testIpinfoGeolocation() throws Exception {
85-
String ip = "13.107.39.238";
85+
String ip = "72.20.12.220";
8686
GeoIpProcessor processor = new GeoIpProcessor(
8787
IP_LOCATION_TYPE, // n.b. this is an "ip_location" processor
8888
randomAlphaOfLength(10),
8989
null,
9090
"source_field",
91-
loader("ipinfo/ip_geolocation_sample.mmdb"),
91+
loader("ipinfo/ip_geolocation_standard_sample.mmdb"),
9292
() -> true,
9393
"target_field",
9494
getIpinfoGeolocationLookup(),
@@ -107,7 +107,7 @@ public void testIpinfoGeolocation() throws Exception {
107107
Map<String, Object> data = (Map<String, Object>) ingestDocument.getSourceAndMetadata().get("target_field");
108108
assertThat(data, notNullValue());
109109
assertThat(data.get("ip"), equalTo(ip));
110-
assertThat(data.get("city_name"), equalTo("Des Moines"));
110+
assertThat(data.get("city_name"), equalTo("Chicago"));
111111
// see IpinfoIpDataLookupsTests for more tests of the data lookup behavior
112112
}
113113

modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/IpinfoIpDataLookupsTests.java

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -102,35 +102,35 @@ public void testParseLocationDouble() {
102102
public void testAsnFree() {
103103
assumeFalse("https://github.com/elastic/elasticsearch/issues/114266", Constants.WINDOWS);
104104
String databaseName = "ip_asn_sample.mmdb";
105-
String ip = "5.182.109.0";
105+
String ip = "23.32.184.0";
106106
assertExpectedLookupResults(
107107
databaseName,
108108
ip,
109109
new IpinfoIpDataLookups.Asn(Database.AsnV2.properties()),
110110
Map.ofEntries(
111111
entry("ip", ip),
112-
entry("organization_name", "M247 Europe SRL"),
113-
entry("asn", 9009L),
114-
entry("network", "5.182.109.0/24"),
115-
entry("domain", "m247.com")
112+
entry("organization_name", "Akamai Technologies, Inc."),
113+
entry("asn", 16625L),
114+
entry("network", "23.32.184.0/21"),
115+
entry("domain", "akamai.com")
116116
)
117117
);
118118
}
119119

120120
public void testAsnStandard() {
121121
assumeFalse("https://github.com/elastic/elasticsearch/issues/114266", Constants.WINDOWS);
122122
String databaseName = "asn_sample.mmdb";
123-
String ip = "23.53.116.0";
123+
String ip = "69.19.224.0";
124124
assertExpectedLookupResults(
125125
databaseName,
126126
ip,
127127
new IpinfoIpDataLookups.Asn(Database.AsnV2.properties()),
128128
Map.ofEntries(
129129
entry("ip", ip),
130-
entry("organization_name", "Akamai Technologies, Inc."),
131-
entry("asn", 32787L),
132-
entry("network", "23.53.116.0/24"),
133-
entry("domain", "akamai.com"),
130+
entry("organization_name", "TPx Communications"),
131+
entry("asn", 14265L),
132+
entry("network", "69.19.224.0/22"),
133+
entry("domain", "tpx.com"),
134134
entry("type", "hosting"),
135135
entry("country_iso_code", "US")
136136
)
@@ -177,25 +177,25 @@ public void testAsnInvariants() {
177177
public void testCountryFree() {
178178
assumeFalse("https://github.com/elastic/elasticsearch/issues/114266", Constants.WINDOWS);
179179
String databaseName = "ip_country_sample.mmdb";
180-
String ip = "4.221.143.168";
180+
String ip = "20.33.76.0";
181181
assertExpectedLookupResults(
182182
databaseName,
183183
ip,
184184
new IpinfoIpDataLookups.Country(Database.CountryV2.properties()),
185185
Map.ofEntries(
186186
entry("ip", ip),
187-
entry("country_name", "South Africa"),
188-
entry("country_iso_code", "ZA"),
189-
entry("continent_name", "Africa"),
190-
entry("continent_code", "AF")
187+
entry("country_name", "Ireland"),
188+
entry("country_iso_code", "IE"),
189+
entry("continent_name", "Europe"),
190+
entry("continent_code", "EU")
191191
)
192192
);
193193
}
194194

195195
public void testGeolocationStandard() {
196196
assumeFalse("https://github.com/elastic/elasticsearch/issues/114266", Constants.WINDOWS);
197-
String databaseName = "ip_geolocation_sample.mmdb";
198-
String ip = "2.124.90.182";
197+
String databaseName = "ip_geolocation_standard_sample.mmdb";
198+
String ip = "62.69.48.19";
199199
assertExpectedLookupResults(
200200
databaseName,
201201
ip,
@@ -215,36 +215,37 @@ public void testGeolocationStandard() {
215215
public void testGeolocationInvariants() {
216216
assumeFalse("https://github.com/elastic/elasticsearch/issues/114266", Constants.WINDOWS);
217217
Path configDir = tmpDir;
218-
copyDatabase("ipinfo/ip_geolocation_sample.mmdb", configDir.resolve("ip_geolocation_sample.mmdb"));
218+
copyDatabase("ipinfo/ip_geolocation_standard_sample.mmdb", configDir.resolve("ip_geolocation_standard_sample.mmdb"));
219219

220220
{
221221
final Set<String> expectedColumns = Set.of(
222-
"network",
223222
"city",
223+
"geoname_id",
224224
"region",
225+
"region_code",
225226
"country",
226227
"postal_code",
227228
"timezone",
228-
"latitude",
229-
"longitude"
229+
"lat",
230+
"lng"
230231
);
231232

232-
Path databasePath = configDir.resolve("ip_geolocation_sample.mmdb");
233+
Path databasePath = configDir.resolve("ip_geolocation_standard_sample.mmdb");
233234
assertDatabaseInvariants(databasePath, (ip, row) -> {
234235
assertThat(row.keySet(), equalTo(expectedColumns));
235236
{
236-
String latitude = (String) row.get("latitude");
237+
String latitude = (String) row.get("lat");
237238
assertThat(latitude, equalTo(latitude.trim()));
238239
Double parsed = parseLocationDouble(latitude);
239240
assertThat(parsed, notNullValue());
240-
assertThat(latitude, equalTo(Double.toString(parsed))); // reverse it
241+
assertThat(Double.parseDouble(latitude), equalTo(Double.parseDouble(Double.toString(parsed)))); // reverse it
241242
}
242243
{
243-
String longitude = (String) row.get("longitude");
244+
String longitude = (String) row.get("lng");
244245
assertThat(longitude, equalTo(longitude.trim()));
245246
Double parsed = parseLocationDouble(longitude);
246247
assertThat(parsed, notNullValue());
247-
assertThat(longitude, equalTo(Double.toString(parsed))); // reverse it
248+
assertThat(Double.parseDouble(longitude), equalTo(Double.parseDouble(Double.toString(parsed)))); // reverse it
248249
}
249250
});
250251
}
@@ -253,7 +254,7 @@ public void testGeolocationInvariants() {
253254
public void testPrivacyDetectionStandard() {
254255
assumeFalse("https://github.com/elastic/elasticsearch/issues/114266", Constants.WINDOWS);
255256
String databaseName = "privacy_detection_sample.mmdb";
256-
String ip = "1.53.59.33";
257+
String ip = "2.57.109.154";
257258
assertExpectedLookupResults(
258259
databaseName,
259260
ip,
@@ -272,16 +273,16 @@ public void testPrivacyDetectionStandard() {
272273
public void testPrivacyDetectionStandardNonEmptyService() {
273274
assumeFalse("https://github.com/elastic/elasticsearch/issues/114266", Constants.WINDOWS);
274275
String databaseName = "privacy_detection_sample.mmdb";
275-
String ip = "216.131.74.65";
276+
String ip = "59.29.201.246";
276277
assertExpectedLookupResults(
277278
databaseName,
278279
ip,
279280
new IpinfoIpDataLookups.PrivacyDetection(Database.PrivacyDetection.properties()),
280281
Map.ofEntries(
281282
entry("ip", ip),
282-
entry("hosting", true),
283+
entry("hosting", false),
283284
entry("proxy", false),
284-
entry("service", "FastVPN"),
285+
entry("service", "VPNGate"),
285286
entry("relay", false),
286287
entry("tor", false),
287288
entry("vpn", true)
@@ -391,13 +392,13 @@ public void testDatabaseTypeParsing() throws IOException {
391392
// pedantic about where precisely it should be.
392393

393394
copyDatabase("ipinfo/ip_asn_sample.mmdb", tmpDir.resolve("ip_asn_sample.mmdb"));
394-
copyDatabase("ipinfo/ip_geolocation_sample.mmdb", tmpDir.resolve("ip_geolocation_sample.mmdb"));
395+
copyDatabase("ipinfo/ip_geolocation_standard_sample.mmdb", tmpDir.resolve("ip_geolocation_standard_sample.mmdb"));
395396
copyDatabase("ipinfo/asn_sample.mmdb", tmpDir.resolve("asn_sample.mmdb"));
396397
copyDatabase("ipinfo/ip_country_sample.mmdb", tmpDir.resolve("ip_country_sample.mmdb"));
397398
copyDatabase("ipinfo/privacy_detection_sample.mmdb", tmpDir.resolve("privacy_detection_sample.mmdb"));
398399

399400
assertThat(parseDatabaseFromType("ip_asn_sample.mmdb"), is(Database.AsnV2));
400-
assertThat(parseDatabaseFromType("ip_geolocation_sample.mmdb"), is(Database.CityV2));
401+
assertThat(parseDatabaseFromType("ip_geolocation_standard_sample.mmdb"), is(Database.CityV2));
401402
assertThat(parseDatabaseFromType("asn_sample.mmdb"), is(Database.AsnV2));
402403
assertThat(parseDatabaseFromType("ip_country_sample.mmdb"), is(Database.CountryV2));
403404
assertThat(parseDatabaseFromType("privacy_detection_sample.mmdb"), is(Database.PrivacyDetection));
518 Bytes
Binary file not shown.
877 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)