-
-
Notifications
You must be signed in to change notification settings - Fork 575
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
[management] Auto update geolite #2297
Conversation
547018f
to
446f67f
Compare
I can go ahead and refactor the |
446f67f
to
2427f1b
Compare
847e88e
to
6b49362
Compare
Hi @benniekiss, Thank you for your valuable contribution!. How does it handle automatic geolite db's updates? For instance, I'm currently running the |
It just downloads the new files and recreates them with the fresh data. The way it decides to download the new files is whether or not the files posted at https://docs.netbird.io/selfhosted/geo-support#downloading-the-databases have changed filenames. None of the logic around database creation has changed -- I really only changed the filename parsing and the heuristics around deciding when to recreate the databases. Regarding whether it will auto-download when updates are released, I am not 100% sure. However, I have tested by naming the Geolite db's something like I noticed that both the geonames.db and Geolite2-Cities.mmdb filenames were hardcoded, and the function Beyond the auto-updating feature, the new functions name the databases based on the filenames parsed from the The reason I put this together was because I was reviewing the documentation and saw the need to manually run |
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.
Could you please add an environment flag to allow skipping the auto-update? Since updates occur frequently (1-2 times a week), this could impact self-hosted users with restricted download speeds.
Additionally, we can remove the download-geolite2.sh
script, as it's no longer needed. We should also remove the reloader that checks for changes to geodatabase files and reloads them, as this functionality is no longer necessary with automatic updates.
netbird/management/server/geolocation/geolocation.go
Lines 169 to 207 in af1b42e
func (gl *Geolocation) reloader(ctx context.Context) { | |
for { | |
select { | |
case <-gl.stopCh: | |
return | |
case <-time.After(gl.reloadCheckInterval): | |
if err := gl.locationDB.reload(ctx); err != nil { | |
log.WithContext(ctx).Errorf("geonames db reload failed: %s", err) | |
} | |
newSha256sum1, err := calculateFileSHA256(gl.mmdbPath) | |
if err != nil { | |
log.WithContext(ctx).Errorf("failed to calculate sha256 sum for '%s': %s", gl.mmdbPath, err) | |
continue | |
} | |
if !bytes.Equal(gl.sha256sum, newSha256sum1) { | |
// we check sum twice just to avoid possible case when we reload during update of the file | |
// considering the frequency of file update (few times a week) checking sum twice should be enough | |
time.Sleep(50 * time.Millisecond) | |
newSha256sum2, err := calculateFileSHA256(gl.mmdbPath) | |
if err != nil { | |
log.WithContext(ctx).Errorf("failed to calculate sha256 sum for '%s': %s", gl.mmdbPath, err) | |
continue | |
} | |
if !bytes.Equal(newSha256sum1, newSha256sum2) { | |
log.WithContext(ctx).Errorf("sha256 sum changed during reloading of '%s'", gl.mmdbPath) | |
continue | |
} | |
err = gl.reload(ctx, newSha256sum2) | |
if err != nil { | |
log.WithContext(ctx).Errorf("mmdb reload failed: %s", err) | |
} | |
} else { | |
log.WithContext(ctx).Tracef("No changes in '%s', no need to reload. Next check is in %.0f seconds.", | |
gl.mmdbPath, gl.reloadCheckInterval.Seconds()) | |
} | |
} | |
} | |
} |
How should I go about implementing a disable flag? Since the check only happens when the management service is started, I could add a flag, |
You’re on the right track with the If the flag is set, the system should skip the process of checking whether the local databases are outdated by comparing the names from the download URLs. This means that no further updates are attempted unless the user explicitly opts to check for updates on every restart of the management service. |
6b49362
to
c973006
Compare
Had to do some refactoring to allow disabling the auto-update feature, but I think this is a little cleaner approach. I consolidated I added a unit test for Finally, I changed the If users want to migrate to the new auto-update functionality, they have to manually remove the old databases. Otherwise, once I remove the |
Before I remove the reloader functions and It would be a little more work, but I could also refactor the reloader functions so that it can periodically poll the url for new database updates if enabled, that way the management service doesn't have to be restarted to get new database updates |
The database names have changed from the previous ones. We need to either update the documentation for manual updates or adjust the script to use the new names. Since we have an auto-update option that triggers on management restart, updating the script might be redundant. We should remove them. |
79b6d36
to
398eff9
Compare
* add exported function to get database filenames * return old database names if auto-update is disabled and new database filenames cannot be found
* invert the flag value since `true` means disable, and `false` means enable
197e709
to
37a2f67
Compare
@benniekiss can you fix test |
could you share the logs again? I can't access them. I think this is because I'm using the |
Here is the updated link: logs |
I think this should fix it I think. I don't have a windows environment to test locally, though. |
If the auto update is disabled, the management download the files using previous format (GeoLite2-City.mmdb and geonames.db) instead of the new format (GeoLite2-City-geonames_20240305.db and GeoLite2-City-maxmind_20240305.mmdb)
731b9b5
to
7c59902
Compare
Do you want me to rebase onto main, or anything else before merging? I can create a PR updating the docs here, but I was not sure if there were any other places where documentation should be updated. |
We're good to merge this PR without a rebase. For the documentation, it would be great to update the page since we’ve moved away from manual downloads to using the auto-download flag. |
# Conflicts: # .github/workflows/test-infrastructure-files.yml
|
Describe your changes
Introduces automated updates for GeoLite databases, eliminating the need to manually run the
download-geolite2.sh
script. Key changes include functions to fetch and update database files based on versioned filenames, auto-download logic when outdated files are detected, and a new--disable-geolite-update
flag.By default, this flag is set to true, disabling automatic updates. Users who want to enable auto-updates can do so by setting
--disable-geolite-update=false
. Additionally, obsolete scripts and reload functions have been removed.This update simplifies version tracking and ensures database consistency without manual intervention while offering flexibility for self-hosted users.
Issue ticket number and link
Checklist