-
Notifications
You must be signed in to change notification settings - Fork 187
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
Greenbids fix geolookup: fetch from official MaxMind URL + mock dbReader UT #3626
Greenbids fix geolookup: fetch from official MaxMind URL + mock dbReader UT #3626
Conversation
e5faad5
to
ee640d3
Compare
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...server/hooks/modules/greenbids/real/time/data/config/GreenbidsRealTimeDataConfiguration.java
Outdated
Show resolved
Hide resolved
...prebid/server/hooks/modules/greenbids/real/time/data/core/GreenbidsInferenceDataService.java
Outdated
Show resolved
Hide resolved
Groovy IT is failing
I will push an empty commit to see if it is a flaky one |
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...id/server/hooks/modules/greenbids/real/time/data/config/GreenbidsRealTimeDataProperties.java
Outdated
Show resolved
Hide resolved
...prebid/server/hooks/modules/greenbids/real/time/data/core/GreenbidsInferenceDataService.java
Outdated
Show resolved
Hide resolved
Also need to not forget to remove As we discussed on Slack on the current state the usage of As the current objective of this PR is to fix the PBS codebase I propose to find the solution in the PR #3596 |
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...prebid/server/hooks/modules/greenbids/real/time/data/core/GreenbidsInferenceDataService.java
Outdated
Show resolved
Hide resolved
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
final Locale local = new Locale("", isoCode); | ||
return local.getDisplayCountry(); | ||
} | ||
|
||
private String getCountry(String ip) { | ||
if (ip == null) { | ||
return null; | ||
} | ||
|
||
final DatabaseReader databaseReader = databaseReaderFactory.getDatabaseReader(); |
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.
NPE is possible
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.
Added optional chain
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 don't see the change
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.
the nature of NPE here is the case when the geolookup database hasn't been loaded, so the underlying question here is whether it's fine and the PBS should be started up in that case at all, if yes then you'd better to handle this situation appropriately
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.
Modified to
private static String getCountryNameFromAlpha2(String isoCode) {
return Optional.ofNullable(isoCode)
.filter(code -> !code.isBlank())
.map(code -> new Locale("", code))
.map(Locale::getDisplayCountry)
.orElse("");
}
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.
databaseReaderFactory.getDatabaseReader()
returns null if the file has been loaded
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.
added optional chain + moved country extracting logic to a separate method
private String getCountry(String ip) {
if (ip == null) {
return null;
}
return Optional.ofNullable(databaseReaderFactory.getDatabaseReader())
.map(dbReader -> getCountryFromIpUsingDatabase(dbReader, ip))
.orElse(null);
}
private String getCountryFromIpUsingDatabase(DatabaseReader databaseReader, String ip) {
try {
final InetAddress inetAddress = InetAddress.getByName(ip);
final CountryResponse response = databaseReader.country(inetAddress);
final Country country = response.getCountry();
return country.getName();
} catch (IOException | GeoIp2Exception e) {
throw new PreBidException("Failed to fetch country from geoLite DB", e);
}
}
...id/server/hooks/modules/greenbids/real/time/data/core/GreenbidsInferenceDataServiceTest.java
Outdated
Show resolved
Hide resolved
...va/org/prebid/server/hooks/modules/greenbids/real/time/data/util/TestBidRequestProvider.java
Show resolved
Hide resolved
...prebid/server/hooks/modules/greenbids/real/time/data/core/GreenbidsInferenceDataService.java
Outdated
Show resolved
Hide resolved
6bea4a6
to
cc4d6a6
Compare
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.
What about to use RemoteFileSyncerV2
instead of this class? Just configure update-interval-ms: 0
. You can see example of using it with MaxMindGeoLocationService
.
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 I remember from our discussion with @AntoxaAntoxic , we have discussed whether to reuse or not RemoteFileSyncerV2 and the public get() method of RemoteFileSupplier
called in syncer and decided to not do that and to proceed with defining methods validateResponse
, sendHttpRequest
, downloadFile
on the side of RTD module
...a/org/prebid/server/hooks/modules/greenbids/real/time/data/config/DatabaseReaderFactory.java
Outdated
Show resolved
Hide resolved
private Future<Void> downloadFile(String downloadUrl, String tmpPath) { | ||
return fileSystem.open(tmpPath, new OpenOptions()) | ||
.compose(tmpFile -> sendHttpRequest(downloadUrl) | ||
.compose(response -> response.pipeTo(tmpFile)) |
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.
.compose(response -> response.pipeTo(tmpFile))
.onComplete(result -> tmpFile.close()))
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.
Adding tmpFile.close()
manual tmpFile closing results in java.lang.IllegalStateException: File handle is closed
. The reason is that after invoking response.pipeTo(tmpFile)
it closes tmpFile automatically by default and then .onComplete(result -> mpFile.close())
trying double close it and fails. We previously discussed with @AntoxaAntoxic and tried to replace onComplete
with .eventually(v -> tmpFile.close())
but result was the same.
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.
@EvgeniiMunin Seems you are right. Then please, change it a bit in your code and in RemoteFileSupplier
if you don't mind:
.compose(tmpFile -> sendHttpRequest(...)
.onFailure(ignore -> tmpFile.close())
.compose(response -> response.pipeTo(tmpFile)))
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.
fixed
🔧 Type of changes
✨ What's the context?
🧠 Rationale behind the change
GeoLite2-Country.mmdb
in Greenbids GCS bucket instead of open source URL: gs://greenbids-europe-west1-prebid-server-staging/GeoLite2-Country.mmdbgetCountry(ip)
only in case ifDevice::getGeo
is null (geoLookupEnabled is false in GeoLocationServiceWrapper)🔎 New Bid Adapter Checklist
🧪 Test plan
How do you know the changes are safe to ship to production?
🏎 Quality check