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
GeoIP2 implementation as a plugin #12699
Conversation
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.
Left some comments & suggestions, haven't tested locally yet.
if (file_exists($outputPath)) { | ||
unlink($outputPath); | ||
} | ||
unlink($path); |
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.
For debugging purposes, would we want to keep the files around so users can see what was downloaded? Maybe just the archive, not the extracted files.
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.
Haven't spent much thoughts on that. It's currently the same as it is done in the already existing GeoIPAutoUpdater.
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.
Any thoughts @mattab? If it is useful, I think it can be added in another PR, though, so no need to worry about it now.
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.
Let's keep the existing GeoipAutoUpdater behavior for now 👍
20577a6
to
26df27c
Compare
Noticed there's a bug in pear/archive_tar which piwik/decompress uses which causes a fatal error when downloading databases on PHP 7: https://pear.php.net/bugs/bug.php?id=21218 I think matomo/decompress uses the fixed version. EDIT: one way to fix this is to run composer require pear/archive_tar locally. |
@mattab tested locally all features seem to work, except unarchiving on PHP 7. Leaving up to you whether my remaining comments should be addressed. |
cff3c4d
to
8fbe252
Compare
@sgiehl Looked again, looks good to me except for php 7 archive tar fatal error (see my comment above for more info). |
I read it. But that seems not a "bug" related to the changes for GeoIP2, right? It should currently occur for GeoIP Legacy as well I guess. |
Easiest fix is to run |
PHP 7 bug no longer exists after 8fbe252, the offending method is no longer called. Moving back to extractInString fixed this. |
plugins/UserCountry/API.php
Outdated
$dt->filter('GroupBy', array( | ||
'label', | ||
function ($label) { | ||
if ($label == '1|ti') { | ||
return '14|cn'; |
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.
I guess this hard-coded conversion here and start from line 172 is still required for the old format.
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.
True. My original implementation converted all codes so it wasn't needed anymore, but with this implementation it's still needed. Will add it again
69e64d0
to
4e3a77b
Compare
I've now tested the maps with geoip2 changes_ Realtime map should work as before, as it doesn't use any region data. The other maps will lack some information on region level. (Country and City level will still work as before) All countries where the new iso codes do not match any old fips codes the map will show those visits as "unknown region". (Note: US and Canada are not affected, as they used iso codes before, also some countries where the codes didn't change between fips and iso will still show up correctly). To have working maps on region level with geoip2 we need to create completely new maps that also show correct regions (based in ISO) and then force all location providers to use ISO region codes in order to show region data on the map |
c8a5cc9
to
142316c
Compare
Did another code review, left two comments on the conversion command, will do another local test tomorrow. |
…n codes still need to be converted to iso
…e quite fast and this should not be an issue in theory
* require geoip2/geoip2 composer package * Determine region name based on Location Provider * Adds empty GeoIp2 plugin * move location_region column definition to GeoIp2 plugin so it's get changed as soon as the plugin is activated * Adds GeoIP2 location providers * ignore GeoIP2 mmdb files * Adds script to generate GeoIP2 test databases * Adds Command to convert region codes from FIPS to ISO for old log table records * Adds GeoIP2 AutoUpdater * Use GeoIP2 in tests * update test files * code fixes * adds tests * rename old GeoIP providers to Legacy * Let GeoIP autoupdater UI handle GeoIp2 as well * convert region codes to ISO in API after switch to GeoIP2 * do not show GeoIP providers if GeoIP2 plugin is enabled an no GeoIP Legacy provider is still in use * small fixes * review changes * Use correct region translations * Show correct message if no database can be found * if log tables have been converted, use archive date to check if region codes still need to be converted to iso * fix tests * Improves extracting GeoIP2 databases * Adjust GeoLocation diagnostics * readds old taiwan fixes * Assume all third party location providers as 'recommended' * Download database over HTTPS * remove outdated comment (see matomo-org#12411) * Remove indication that Geoip2 may be slow, since we found it should be quite fast and this should not be an issue in theory * skip detection if IP is empty & do not try convert IP to IPv4 * remove downloaded file if an error occurs while extracting * command should be runnable multiple times * use ISO codes for suggested region codes * reload after wizard success * Drop table if exists. * Fix two translation keys. * add special region handling for UK * update system test * update UI files * submodule update * update test files
As using GeoIP2 requires a schema change on log tables to be able to track ISO region codes, GeoIP2 will be included as a new plugin. This way we can avoid an automatic schema change while updating Matomo.
This plugin will be automatically enabled for new installs. Instances updating to the new version will have the plugin included disabled. Enabling the plugin will then trigger the schema change.
As long as the GeoIP2 plugin is disabled nothing will change for Geolocation configuration, tracked data and API.
As soon as the GeoIP2 plugin is enabled some stuff changes:
Autoupdating of GeoIP databases
Autoupdating feature for databases will switch to configure updates for GeoIP2 databases.
For existing installs with configured updates for GeoIP, it will still show those settings as read only. This settings will be automatically removed as soon as GeoIP2 updates are configured
Tracking
As soon as a GeoIP2 provider is chosen region codes will be stored as ISO codes. [GeoIP Legacy used FIPS codes]. To convert old log data from FIPS to ISO the command
usercountry:convert-region-codes
can be used. The command will convert all codes stored before the date of switching to a GeoIP2 provider.Changes in API
Until a GeoIP2 provider is selected nothing changes and still old FIPS codes and region names will be returned.
After switching to one all old codes included in archives will be converted [FIPS => ISO] if possible and region names will be used accordingly.
Switching back from GeoIP2 to GeoIP is only possible by disabling GeoIP2 plugin. This is on purpose as it may cause problems if FIPS and ISO codes are mixed too much in the database.
replaces #12553
fixes #4487