- 
                Notifications
    You must be signed in to change notification settings 
- Fork 25.6k
Refactor geoip cache for MaxMind databases #125527
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
Refactor geoip cache for MaxMind databases #125527
Conversation
CityResponse and EnterpriseResponse use the null-object pattern here, so postal is never null.
Allow a given lookup to create a cache-able record from the response from the database. At the moment every lookup just uses its response from the database as the cache-able record (this is fine).
so that it can be reused. Of course that means that we have to tweak all the existing callers to use method access rather than field access, hence the bigger diff than one might otherwise imagine.
| Pinging @elastic/es-data-management (Team:Data Management) | 
| } | ||
|  | ||
| @Override | ||
| protected AnonymousIpResponse record(AnonymousIpResponse response) { | 
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 kind of wonder if this method name is going to cause confusion for future maintainers, since as you've pointed out your first thought when you see this is the verb -- what am I recording? What about cacheableRecord?
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.
Indeed, my unwavering love of short names is definitely at odds with the desire for a clear name in this case. I renamed it to cacheableRecord for now via 9dd8964, but I think I'm going to polish things a little more (on subsequent PRs).
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.
LGTM
There's too many nearby things named record or result or response. So here's a new word, 'entry'. A database has a bunch of entries in it.
| 💚 Backport successful
 | 
This PR adds another degree of freedom in the
MaxmindIpDataLookups. Rather than requiring that the response from theReaderis necessarily the same object as we keep in theGeoIpCache, it adds a newrecord(...)method (read as a noun, like "the record for storing in the cache") that allows a given MaxMindIpDataLookupto build a different object out of the response and then cache that object.In this PR, only the
CountryResponseis refactored to use this new capability -- it's the smallest of the response objects that would benefit from a change, so it's the easiest one to review at the same time as the rest of the machinery changes.We'll benefit from this new capability in two ways:
IngestDocumentfrom a record faster than we can update from a properResponse(as a simple example, the commongetName()method of various responses iterates over a collection -- now we'll do that just once when we populate the cache rather than every time we have a cache hit)Or, to put it simply, things are faster and use less memory this way.