-
Notifications
You must be signed in to change notification settings - Fork 216
Live intent omni channel module #4127
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
Merged
Merged
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
bf8c1fa
WIP - LiveIntent Module
3link 8429f34
Adjust the hook code
3link 459028d
WIP - polish, add config tests
3link c846d1c
Add unit tests
3link 8348d46
Add auth token
3link c0f6566
Add README.md
3link 4f90c17
Fix stage
3link c6dc20e
Add logging
3link a863d0a
Add docs
3link 62a4508
Format
3link e45ccbc
Impro docs
3link 3dbb46a
Add IdResResponse decode test
3link 69fc413
Improve code style
3link c1ad22f
Fix Collections API usage
3link 26288b7
Clean up/format
3link 4192fa8
Merge branch 'prebid:master' into cm-1776
SuperIzya 1f1a7cf
Format
3link c9659ad
Add treatment rate
3link 3ed7ee8
Remove superflous JsonProperty annotation
3link bedb969
Separate field by line
3link d94e06f
Use RandomGenerator + ThreadLocalRandom instead of Random
3link 61ceeed
Apply code style
3link fa66d18
Apply style guide: method order
3link 09450d2
Add empty lines to separate test stages
3link b588f6a
Use NoArgsConstructor instead of Jacksonized
3link 1ae6da8
Merge branch 'master' into cm-1776
3link f597339
Bump dependency version
3link 5f15bf1
cm-1776: PR issues fixed
d6dfcc7
Merge branch 'master' into cm-1776
53ca621
Merge branch 'master' into cm-1776
b61986a
cm-1776: PR issues fixed
e458a4c
cm-1776: PR issues fixed
bf7d54a
LiveIntent Omni Channel Module Refactoring
AntoxaAntoxic 88d0bc8
Fix checkstyle
AntoxaAntoxic c0901b3
Merge remote-tracking branch 'origin/master' into live-intent-omni-ch…
AntoxaAntoxic 53a6e6f
Fix version
AntoxaAntoxic 4d6a603
Fix comments
AntoxaAntoxic cc3e092
fix comments
AntoxaAntoxic d8cb2fa
Fix comments
AntoxaAntoxic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Overview | ||
|
||
This module enriches bid requests with user EIDs. | ||
|
||
The user EIDs to be enriched are configured per partner as part of the LiveIntent HIRO onboarding process. As part of this onboarding process, partners will also be provided with the `identity-resolution-endpoint` URL as well as with the `auth-token`. | ||
|
||
`treatment-rate` is a value between 0.0 and 1.0 (including 0.0 and 1.0) and defines the percentage of requests for which identity enrichment should be performed. This value can be freely picked. We recommend a value between 0.9 and 0.95 | ||
|
||
## Configuration | ||
|
||
To start using the LiveIntent Omni Channel Identity module you have to enable it and add configuration: | ||
|
||
```yaml | ||
hooks: | ||
liveintent-omni-channel-identity: | ||
enabled: true | ||
host-execution-plan: > | ||
{ | ||
"endpoints": { | ||
"/openrtb2/auction": { | ||
"stages": { | ||
"processed-auction-request": { | ||
"groups": [ | ||
{ | ||
"timeout": 100, | ||
"hook-sequence": [ | ||
{ | ||
"module-code": "liveintent-omni-channel-identity", | ||
"hook-impl-code": "liveintent-omni-channel-identity-enrichment-hook" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
modules: | ||
liveintent-omni-channel-identity: | ||
request-timeout-ms: 2000 | ||
identity-resolution-endpoint: "https://liveintent.com/idx" | ||
auth-token: "secret-token" | ||
treatment-rate: 0.9 | ||
``` | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.prebid.server.hooks.modules</groupId> | ||
<artifactId>all-modules</artifactId> | ||
<version>3.31.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>live-intent-omni-channel-identity</artifactId> | ||
|
||
<name>live-intent-omni-channel-identity</name> | ||
<description>LiveIntent Omni-Channel Identity</description> | ||
|
||
<dependencies> | ||
</dependencies> | ||
</project> |
43 changes: 43 additions & 0 deletions
43
...s/liveintent/omni/channel/identity/config/LiveIntentOmniChannelIdentityConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.prebid.server.hooks.modules.liveintent.omni.channel.identity.config; | ||
|
||
import org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model.config.LiveIntentOmniChannelProperties; | ||
import org.prebid.server.hooks.modules.liveintent.omni.channel.identity.v1.LiveIntentOmniChannelIdentityModule; | ||
import org.prebid.server.hooks.modules.liveintent.omni.channel.identity.v1.hooks.LiveIntentOmniChannelIdentityProcessedAuctionRequestHook; | ||
import org.prebid.server.hooks.v1.Module; | ||
import org.prebid.server.json.JacksonMapper; | ||
import org.prebid.server.vertx.httpclient.HttpClient; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.Collections; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
@Configuration | ||
@ConditionalOnProperty( | ||
prefix = "hooks." + LiveIntentOmniChannelIdentityModule.CODE, | ||
name = "enabled", | ||
havingValue = "true") | ||
public class LiveIntentOmniChannelIdentityConfiguration { | ||
|
||
@Bean | ||
@ConfigurationProperties(prefix = "hooks.modules." + LiveIntentOmniChannelIdentityModule.CODE) | ||
LiveIntentOmniChannelProperties properties() { | ||
return new LiveIntentOmniChannelProperties(); | ||
} | ||
|
||
@Bean | ||
Module liveIntentOmniChannelIdentityModule(LiveIntentOmniChannelProperties properties, | ||
JacksonMapper mapper, | ||
HttpClient httpClient, | ||
@Value("${logging.sampling-rate:0.01}") double logSamplingRate) { | ||
|
||
final LiveIntentOmniChannelIdentityProcessedAuctionRequestHook hook = | ||
new LiveIntentOmniChannelIdentityProcessedAuctionRequestHook( | ||
properties, mapper, httpClient, () -> ThreadLocalRandom.current().nextLong(), logSamplingRate); | ||
|
||
return new LiveIntentOmniChannelIdentityModule(Collections.singleton(hook)); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...org/prebid/server/hooks/modules/liveintent/omni/channel/identity/model/IdResResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model; | ||
|
||
import com.iab.openrtb.request.Eid; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor(staticName = "of") | ||
public class IdResResponse { | ||
|
||
List<Eid> eids; | ||
} |
15 changes: 15 additions & 0 deletions
15
...odules/liveintent/omni/channel/identity/model/config/LiveIntentOmniChannelProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model.config; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public final class LiveIntentOmniChannelProperties { | ||
|
||
long requestTimeoutMs; | ||
|
||
String identityResolutionEndpoint; | ||
|
||
String authToken; | ||
|
||
float treatmentRate; | ||
} |
23 changes: 23 additions & 0 deletions
23
...ooks/modules/liveintent/omni/channel/identity/v1/LiveIntentOmniChannelIdentityModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.prebid.server.hooks.modules.liveintent.omni.channel.identity.v1; | ||
|
||
import org.prebid.server.hooks.v1.Hook; | ||
import org.prebid.server.hooks.v1.InvocationContext; | ||
import org.prebid.server.hooks.v1.Module; | ||
|
||
import java.util.Collection; | ||
|
||
public record LiveIntentOmniChannelIdentityModule( | ||
Collection<? extends Hook<?, ? extends InvocationContext>> hooks) implements Module { | ||
|
||
public static final String CODE = "liveintent-omni-channel-identity"; | ||
|
||
@Override | ||
public String code() { | ||
return CODE; | ||
} | ||
|
||
@Override | ||
public Collection<? extends Hook<?, ? extends InvocationContext>> hooks() { | ||
return hooks; | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
...i/channel/identity/v1/hooks/LiveIntentOmniChannelIdentityProcessedAuctionRequestHook.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package org.prebid.server.hooks.modules.liveintent.omni.channel.identity.v1.hooks; | ||
|
||
import com.iab.openrtb.request.BidRequest; | ||
import com.iab.openrtb.request.Eid; | ||
import com.iab.openrtb.request.User; | ||
import io.vertx.core.Future; | ||
import io.vertx.core.MultiMap; | ||
import org.apache.commons.collections4.ListUtils; | ||
import org.prebid.server.hooks.execution.v1.InvocationResultImpl; | ||
import org.prebid.server.hooks.execution.v1.auction.AuctionRequestPayloadImpl; | ||
import org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model.IdResResponse; | ||
import org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model.config.LiveIntentOmniChannelProperties; | ||
import org.prebid.server.hooks.v1.InvocationAction; | ||
import org.prebid.server.hooks.v1.InvocationResult; | ||
import org.prebid.server.hooks.v1.InvocationStatus; | ||
import org.prebid.server.hooks.v1.auction.AuctionInvocationContext; | ||
import org.prebid.server.hooks.v1.auction.AuctionRequestPayload; | ||
import org.prebid.server.hooks.v1.auction.ProcessedAuctionRequestHook; | ||
import org.prebid.server.json.JacksonMapper; | ||
import org.prebid.server.log.ConditionalLogger; | ||
import org.prebid.server.log.LoggerFactory; | ||
import org.prebid.server.util.HttpUtil; | ||
import org.prebid.server.util.ListUtil; | ||
import org.prebid.server.vertx.httpclient.HttpClient; | ||
import org.prebid.server.vertx.httpclient.model.HttpClientResponse; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.random.RandomGenerator; | ||
|
||
public class LiveIntentOmniChannelIdentityProcessedAuctionRequestHook implements ProcessedAuctionRequestHook { | ||
|
||
private static final ConditionalLogger conditionalLogger = new ConditionalLogger(LoggerFactory.getLogger( | ||
LiveIntentOmniChannelIdentityProcessedAuctionRequestHook.class)); | ||
|
||
private static final String CODE = "liveintent-omni-channel-identity-enrichment-hook"; | ||
|
||
private final LiveIntentOmniChannelProperties config; | ||
private final JacksonMapper mapper; | ||
private final HttpClient httpClient; | ||
private final RandomGenerator random; | ||
private final double logSamplingRate; | ||
|
||
public LiveIntentOmniChannelIdentityProcessedAuctionRequestHook(LiveIntentOmniChannelProperties config, | ||
JacksonMapper mapper, | ||
HttpClient httpClient, | ||
RandomGenerator random, | ||
double logSamplingRate) { | ||
|
||
this.config = Objects.requireNonNull(config); | ||
HttpUtil.validateUrlSyntax(config.getIdentityResolutionEndpoint()); | ||
this.mapper = Objects.requireNonNull(mapper); | ||
this.httpClient = Objects.requireNonNull(httpClient); | ||
this.random = Objects.requireNonNull(random); | ||
this.logSamplingRate = logSamplingRate; | ||
} | ||
|
||
@Override | ||
public Future<InvocationResult<AuctionRequestPayload>> call(AuctionRequestPayload auctionRequestPayload, | ||
AuctionInvocationContext invocationContext) { | ||
|
||
return config.getTreatmentRate() <= random.nextFloat() | ||
? noAction() | ||
: requestIdentities(auctionRequestPayload.bidRequest()) | ||
.<InvocationResult<AuctionRequestPayload>>map(this::update) | ||
.onFailure(throwable -> conditionalLogger.error( | ||
"Failed enrichment: %s".formatted(throwable.getMessage()), logSamplingRate)); | ||
} | ||
|
||
private Future<IdResResponse> requestIdentities(BidRequest bidRequest) { | ||
return httpClient.post( | ||
config.getIdentityResolutionEndpoint(), | ||
headers(), | ||
mapper.encodeToString(bidRequest), | ||
config.getRequestTimeoutMs()) | ||
.map(this::processResponse); | ||
} | ||
|
||
private MultiMap headers() { | ||
return MultiMap.caseInsensitiveMultiMap() | ||
.add(HttpUtil.AUTHORIZATION_HEADER, "Bearer " + config.getAuthToken()); | ||
} | ||
|
||
private IdResResponse processResponse(HttpClientResponse response) { | ||
return mapper.decodeValue(response.getBody(), IdResResponse.class); | ||
} | ||
|
||
private static Future<InvocationResult<AuctionRequestPayload>> noAction() { | ||
return Future.succeededFuture(InvocationResultImpl.<AuctionRequestPayload>builder() | ||
.status(InvocationStatus.success) | ||
.action(InvocationAction.no_action) | ||
.build()); | ||
} | ||
|
||
private InvocationResultImpl<AuctionRequestPayload> update(IdResResponse resolutionResult) { | ||
return InvocationResultImpl.<AuctionRequestPayload>builder() | ||
.status(InvocationStatus.success) | ||
.action(InvocationAction.update) | ||
.payloadUpdate(payload -> updatedPayload(payload, resolutionResult.getEids())) | ||
.build(); | ||
} | ||
|
||
private AuctionRequestPayload updatedPayload(AuctionRequestPayload requestPayload, List<Eid> resolvedEids) { | ||
final List<Eid> eids = ListUtils.emptyIfNull(resolvedEids); | ||
final BidRequest bidRequest = requestPayload.bidRequest(); | ||
final User updatedUser = Optional.ofNullable(bidRequest.getUser()) | ||
.map(user -> user.toBuilder().eids(ListUtil.union(ListUtils.emptyIfNull(user.getEids()), eids))) | ||
.orElseGet(() -> User.builder().eids(eids)) | ||
.build(); | ||
|
||
return AuctionRequestPayloadImpl.of(bidRequest.toBuilder().user(updatedUser).build()); | ||
} | ||
|
||
@Override | ||
public String code() { | ||
return CODE; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.