Skip to content
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

agma: bugfixes #3495

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ public AgmaAnalyticsReporter(AgmaAnalyticsProperties agmaAnalyticsProperties,

@Override
public void initialize(Promise<Void> initializePromise) {
vertx.setPeriodic(bufferTimeoutMs, ignored -> sendEvents(buffer.pollAll()));
vertx.setPeriodic(bufferTimeoutMs, ignored -> {
final List<String> toFlush = buffer.pollAll();
if (!toFlush.isEmpty()) {
sendEvents(toFlush);
}
});
initializePromise.complete();
}

Expand Down Expand Up @@ -190,17 +195,17 @@ private static String getPublisherId(BidRequest bidRequest) {

final String publisherId = Optional.ofNullable(site).map(Site::getPublisher).map(Publisher::getId)
.or(() -> Optional.ofNullable(app).map(App::getPublisher).map(Publisher::getId))
.orElse(null);
.orElse("");
final String appSiteId = Optional.ofNullable(site).map(Site::getId)
.or(() -> Optional.ofNullable(app).map(App::getId))
.or(() -> Optional.ofNullable(app).map(App::getBundle))
.orElse(null);

if (publisherId == null && appSiteId == null) {
if (publisherId.equals("") && appSiteId == null) {
return null;
}

return publisherId;
return appSiteId != null ? publisherId + "_" + appSiteId : publisherId;
}

private void sendEvents(List<String> events) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@ private static class AgmaAnalyticsConfigurationProperties {
public AgmaAnalyticsProperties toComponentProperties() {
final Map<String, String> accountsByPublisherId = accounts.stream()
.collect(Collectors.toMap(
AgmaAnalyticsAccountProperties::getPublisherId,
AgmaAnalyticsAccountProperties::getCode));
account -> {
final String publisherId = account.getPublisherId();
final String siteAppId = account.getSiteAppId();
return (siteAppId != null && !siteAppId.isEmpty())
? publisherId + "_" + siteAppId
: publisherId;
},
AgmaAnalyticsAccountProperties::getCode
));

return AgmaAnalyticsProperties.builder()
.url(endpoint.getUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,124 @@ public void processEventShouldNotSendAnythingWhenAccountsDoesNotHaveConfiguredPu
assertThat(result.succeeded()).isTrue();
}

@Test
public void processEventShouldSendWhenAccountsHasConfiguredAppsOrSites() {
// given
final AgmaAnalyticsProperties properties = AgmaAnalyticsProperties.builder()
.url("http://endpoint.com")
.gzip(false)
.bufferSize(100000)
.bufferTimeoutMs(10000L)
.maxEventsCount(0)
.httpTimeoutMs(1000L)
.accounts(Map.of("publisherId_bundleId", "accountCode"))
.build();

target = new AgmaAnalyticsReporter(properties, versionProvider, jacksonMapper, clock, httpClient, vertx);

// given
final App givenApp = App.builder().bundle("bundleId")
.publisher(Publisher.builder().id("publisherId").build()).build();
final Device givenDevice = Device.builder().build();
final User givenUser = User.builder().build();

final AuctionEvent auctionEvent = AuctionEvent.builder()
.auctionContext(AuctionContext.builder()
.privacyContext(PrivacyContext.of(
null, TcfContext.builder().consent(PARSED_VALID_CONSENT).build()))
.timeoutContext(TimeoutContext.of(clock.millis(), null, 1))
.bidRequest(BidRequest.builder()
.id("requestId")
.app(givenApp)
.app(givenApp)
.device(givenDevice)
.user(givenUser)
.build())
.build())
.build();

// when
final Future<Void> result = target.processEvent(auctionEvent);

// then
final AgmaEvent expectedEvent = AgmaEvent.builder()
.eventType("auction")
.accountCode("accountCode")
.requestId("requestId")
.app(givenApp)
.device(givenDevice)
.user(givenUser)
.startTime(ZonedDateTime.parse("2024-09-03T15:00:00+05:00"))
.build();

final String expectedEventPayload = "[" + jacksonMapper.encodeToString(expectedEvent) + "]";

verify(httpClient).request(
eq(POST),
eq("http://endpoint.com"),
any(),
eq(expectedEventPayload),
eq(1000L));
}

@Test
public void processEventShouldSendWhenAccountsHasConfiguredAppsOrSitesOnly() {
// given
final AgmaAnalyticsProperties properties = AgmaAnalyticsProperties.builder()
.url("http://endpoint.com")
.gzip(false)
.bufferSize(100000)
.bufferTimeoutMs(10000L)
.maxEventsCount(0)
.httpTimeoutMs(1000L)
.accounts(Map.of("_mySite", "accountCode"))
.build();

target = new AgmaAnalyticsReporter(properties, versionProvider, jacksonMapper, clock, httpClient, vertx);

// given
final Site givenSite = Site.builder().id("mySite").build();
final Device givenDevice = Device.builder().build();
final User givenUser = User.builder().build();

final AuctionEvent auctionEvent = AuctionEvent.builder()
.auctionContext(AuctionContext.builder()
.privacyContext(PrivacyContext.of(
null, TcfContext.builder().consent(PARSED_VALID_CONSENT).build()))
.timeoutContext(TimeoutContext.of(clock.millis(), null, 1))
.bidRequest(BidRequest.builder()
.id("requestId")
.site(givenSite)
.device(givenDevice)
.user(givenUser)
.build())
.build())
.build();

// when
final Future<Void> result = target.processEvent(auctionEvent);

// then
final AgmaEvent expectedEvent = AgmaEvent.builder()
.eventType("auction")
.accountCode("accountCode")
.requestId("requestId")
.site(givenSite)
.device(givenDevice)
.user(givenUser)
.startTime(ZonedDateTime.parse("2024-09-03T15:00:00+05:00"))
.build();

final String expectedEventPayload = "[" + jacksonMapper.encodeToString(expectedEvent) + "]";

verify(httpClient).request(
eq(POST),
eq("http://endpoint.com"),
any(),
eq(expectedEventPayload),
eq(1000L));
}

@Test
public void processEventShouldSendEncodingGzipHeaderAndCompressedPayload() {
// given
Expand Down