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

Buyeruid Scrubbed Metric #3674

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
AntoxaAntoxic marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public Future<List<BidderPrivacyResult>> enforce(AuctionContext auctionContext,

final MetricName requestType = auctionContext.getRequestTypeMetric();
final ActivityInfrastructure activityInfrastructure = auctionContext.getActivityInfrastructure();
final Account account = auctionContext.getAccount();
final Set<String> bidders = results.stream()
.map(BidderPrivacyResult::getRequestBidder)
.collect(Collectors.toSet());
Expand All @@ -75,9 +76,15 @@ public Future<List<BidderPrivacyResult>> enforce(AuctionContext auctionContext,
bidders,
VendorIdResolver.of(aliases),
auctionContext.getPrivacyContext().getTcfContext(),
accountGdprConfig(auctionContext.getAccount()))
accountGdprConfig(account))
.map(TcfResponse::getActions)
.map(enforcements -> updateMetrics(activityInfrastructure, enforcements, aliases, requestType, results))
.map(enforcements -> updateMetrics(
activityInfrastructure,
enforcements,
aliases,
requestType,
results,
account))
.map(enforcements -> applyEnforcements(enforcements, results));
}

Expand All @@ -86,11 +93,28 @@ private static AccountGdprConfig accountGdprConfig(Account account) {
return privacyConfig != null ? privacyConfig.getGdpr() : null;
}

private static boolean isBuyerUidSet(User user) {
AntoxaAntoxic marked this conversation as resolved.
Show resolved Hide resolved
return user != null && user.getBuyeruid() != null;
}

private static boolean shouldRemoveUserData(User user) {
return user != null && ObjectUtils.anyNotNull(
user.getId(),
user.getBuyeruid(),
user.getYob(),
user.getGender(),
user.getKeywords(),
user.getKwarray(),
user.getData(),
ObjectUtil.getIfNotNull(user.getExt(), ExtUser::getData));
}

AntoxaAntoxic marked this conversation as resolved.
Show resolved Hide resolved
private Map<String, PrivacyEnforcementAction> updateMetrics(ActivityInfrastructure activityInfrastructure,
Map<String, PrivacyEnforcementAction> enforcements,
BidderAliases aliases,
MetricName requestType,
List<BidderPrivacyResult> results) {
List<BidderPrivacyResult> results,
Account account) {

// Metrics should represent real picture of the bidding process, so if bidder request is blocked
// by privacy then no reason to increment another metrics, like geo masked, etc.
Expand Down Expand Up @@ -120,6 +144,10 @@ private Map<String, PrivacyEnforcementAction> updateMetrics(ActivityInfrastructu
requestBlocked,
isLmtEnforcedAndEnabled);

if (isBuyerUidSet(user) && ufpdRemoved) {
metrics.updateAdapterRequestBuyerUidScrubbedMetrics(bidder, account);
}

if (ufpdRemoved) {
logger.warn("The UFPD fields have been removed due to a consent check.");
}
Expand All @@ -128,18 +156,6 @@ private Map<String, PrivacyEnforcementAction> updateMetrics(ActivityInfrastructu
return enforcements;
}

private static boolean shouldRemoveUserData(User user) {
return user != null && ObjectUtils.anyNotNull(
user.getId(),
user.getBuyeruid(),
user.getYob(),
user.getGender(),
user.getKeywords(),
user.getKwarray(),
user.getData(),
ObjectUtil.getIfNotNull(user.getExt(), ExtUser::getData));
}

private static boolean shouldRemoveDeviceData(Device device) {
return device != null && ObjectUtils.anyNotNull(
device.getIfa(),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/prebid/server/metric/MetricName.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public enum MetricName {
unknown_error,
err,
networkerr,
buyeruid_scrubbed,

// bids validation
warn,
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/prebid/server/metric/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ public void updateAdapterRequestTypeAndNoCookieMetrics(String bidder, MetricName
}
}

public void updateAdapterRequestBuyerUidScrubbedMetrics(String bidder, Account account) {
forAdapter(bidder).request().incCounter(MetricName.buyeruid_scrubbed);
if (accountMetricsVerbosityResolver.forAccount(account).isAtLeast(AccountMetricsVerbosityLevel.detailed)) {
forAccount(account.getId()).adapter().forAdapter(bidder).request().incCounter(MetricName.buyeruid_scrubbed);
}
}

public void updateAdapterResponseTime(String bidder, Account account, int responseTime) {
final AdapterTypeMetrics adapterTypeMetrics = forAdapter(bidder);
adapterTypeMetrics.updateTimer(MetricName.request_time, responseTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mock.Strictness.LENIENT;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -169,6 +170,44 @@ public void enforceShouldEmitExpectedMetricsWhenUserHasPrivacyData() {
verifyMetric("bidder2", true, false, false, false, false, false);
}

@Test
public void enforceShouldEmitBuyerUidScrubbedMetricsWhenUserHasBuyerUid() {
// give
givenPrivacyEnforcementActions(Map.of(
"bidder0", givenEnforcementAction(PrivacyEnforcementAction::setMaskGeo),
"bidder1", givenEnforcementAction(PrivacyEnforcementAction::setMaskDeviceInfo),
"bidder2", givenEnforcementAction(PrivacyEnforcementAction::setRemoveUserFpd),
"bidder3", givenEnforcementAction(PrivacyEnforcementAction::setMaskDeviceInfo),
"bidder4", givenEnforcementAction(PrivacyEnforcementAction::setRemoveUserFpd),
"bidder5", givenEnforcementAction(PrivacyEnforcementAction::setMaskDeviceInfo)));

final User givenUserWithoutBuyerUid = givenUserWithPrivacyData();

final User givenUserWithBuyerUid = givenUserWithoutBuyerUid.toBuilder()
.buyeruid("buyeruid")
.build();

final AuctionContext auctionContext = givenAuctionContext(givenDeviceWithNoPrivacyData());
final List<BidderPrivacyResult> initialResults = List.of(
givenBidderPrivacyResult("bidder0", givenUserWithBuyerUid, givenDeviceWithNoPrivacyData()),
givenBidderPrivacyResult("bidder1", givenUserWithBuyerUid, givenDeviceWithNoPrivacyData()),
givenBidderPrivacyResult("bidder2", givenUserWithoutBuyerUid, givenDeviceWithNoPrivacyData()),
givenBidderPrivacyResult("bidder3", givenUserWithoutBuyerUid, givenDeviceWithPrivacyData()),
givenBidderPrivacyResult("bidder4", givenUserWithBuyerUid, givenDeviceWithNoPrivacyData()),
givenBidderPrivacyResult("bidder5", givenUserWithBuyerUid, givenDeviceWithPrivacyData()));

// when
target.enforce(auctionContext, aliases, initialResults);

// then
verify(metrics, never()).updateAdapterRequestBuyerUidScrubbedMetrics(eq("bidder0"), any());
verify(metrics, never()).updateAdapterRequestBuyerUidScrubbedMetrics(eq("bidder1"), any());
verify(metrics, never()).updateAdapterRequestBuyerUidScrubbedMetrics(eq("bidder2"), any());
verify(metrics, never()).updateAdapterRequestBuyerUidScrubbedMetrics(eq("bidder3"), any());
verify(metrics).updateAdapterRequestBuyerUidScrubbedMetrics(eq("bidder4"), any());
verify(metrics).updateAdapterRequestBuyerUidScrubbedMetrics(eq("bidder5"), any());
}

@Test
public void enforceShouldEmitExpectedMetricsWhenDeviceHavePrivacyData() {
// give
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/org/prebid/server/metric/MetricsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,28 @@ public void updateAdapterResponseTimeShouldUpdateMetrics() {
assertThat(metricRegistry.timer("account.accountId.adapter.conversant.request_time").getCount()).isEqualTo(2);
}

@Test
public void updateAdapterRequestBuyerUidScrubbedMetricsShouldIncrementMetrics() {
// when
metrics.updateAdapterRequestBuyerUidScrubbedMetrics(RUBICON, Account.empty(ACCOUNT_ID));
metrics.updateAdapterRequestBuyerUidScrubbedMetrics(CONVERSANT, Account.empty(ACCOUNT_ID));
metrics.updateAdapterRequestBuyerUidScrubbedMetrics(CONVERSANT, Account.empty(ACCOUNT_ID));

// then
assertThat(metricRegistry.counter("adapter.rubicon.requests.buyeruid_scrubbed")
.getCount())
.isOne();
assertThat(metricRegistry.counter("account.accountId.adapter.rubicon.requests.buyeruid_scrubbed")
.getCount())
.isOne();
assertThat(metricRegistry.counter("adapter.conversant.requests.buyeruid_scrubbed")
.getCount())
.isEqualTo(2);
assertThat(metricRegistry.counter("account.accountId.adapter.conversant.requests.buyeruid_scrubbed")
.getCount())
.isEqualTo(2);
}

@Test
public void updateAdapterRequestNobidMetricsShouldIncrementMetrics() {
// when
Expand Down
Loading