-
Notifications
You must be signed in to change notification settings - Fork 224
Support GET on the /vtrack endpoint #4073
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eee8e53
Add Get /vtrack
AntoxaAntoxic fa4b64d
Add metrics
AntoxaAntoxic c5b8c7f
Merge remote-tracking branch 'origin/master' into vtrack-get
AntoxaAntoxic 98c48bc
Add creative_size and creative_ttl metrics for Vtrack
AntoxaAntoxic 4814383
small fix
AntoxaAntoxic 2f20c82
Merge remote-tracking branch 'origin/master' into vtrack-get
AntoxaAntoxic 9b0588c
Fix comments
AntoxaAntoxic a1591f9
Test: get `/vtrack` endpoint (#4238)
marki1an 70fd130
fix test
osulzhenko 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
19 changes: 19 additions & 0 deletions
19
src/main/java/org/prebid/server/cache/proto/response/CacheErrorResponse.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,19 @@ | ||
| package org.prebid.server.cache.proto.response; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Value; | ||
|
|
||
| @Value | ||
| @Builder | ||
| public class CacheErrorResponse { | ||
|
|
||
| String error; | ||
|
|
||
| Integer status; | ||
|
|
||
| String path; | ||
|
|
||
| String message; | ||
|
|
||
| Long timestamp; | ||
| } |
108 changes: 108 additions & 0 deletions
108
src/main/java/org/prebid/server/handler/GetVtrackHandler.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,108 @@ | ||
| package org.prebid.server.handler; | ||
|
|
||
| import io.netty.handler.codec.http.HttpHeaderValues; | ||
| import io.netty.handler.codec.http.HttpResponseStatus; | ||
| import io.vertx.core.AsyncResult; | ||
| import io.vertx.core.MultiMap; | ||
| import io.vertx.core.http.HttpMethod; | ||
| import io.vertx.ext.web.RoutingContext; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.prebid.server.cache.CoreCacheService; | ||
| import org.prebid.server.execution.timeout.Timeout; | ||
| import org.prebid.server.execution.timeout.TimeoutFactory; | ||
| import org.prebid.server.log.Logger; | ||
| import org.prebid.server.log.LoggerFactory; | ||
| import org.prebid.server.model.Endpoint; | ||
| import org.prebid.server.util.HttpUtil; | ||
| import org.prebid.server.vertx.httpclient.model.HttpClientResponse; | ||
| import org.prebid.server.vertx.verticles.server.HttpEndpoint; | ||
| import org.prebid.server.vertx.verticles.server.application.ApplicationResource; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| public class GetVtrackHandler implements ApplicationResource { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(GetVtrackHandler.class); | ||
|
|
||
| private static final String UUID_PARAMETER = "uuid"; | ||
| private static final String CH_PARAMETER = "ch"; | ||
|
|
||
| private final long defaultTimeout; | ||
| private final CoreCacheService coreCacheService; | ||
| private final TimeoutFactory timeoutFactory; | ||
|
|
||
| public GetVtrackHandler(long defaultTimeout, CoreCacheService coreCacheService, TimeoutFactory timeoutFactory) { | ||
| this.defaultTimeout = defaultTimeout; | ||
| this.coreCacheService = Objects.requireNonNull(coreCacheService); | ||
| this.timeoutFactory = Objects.requireNonNull(timeoutFactory); | ||
| } | ||
|
|
||
| @Override | ||
| public List<HttpEndpoint> endpoints() { | ||
| return Collections.singletonList(HttpEndpoint.of(HttpMethod.GET, Endpoint.vtrack.value())); | ||
| } | ||
|
|
||
| @Override | ||
| public void handle(RoutingContext routingContext) { | ||
| final String uuid = routingContext.request().getParam(UUID_PARAMETER); | ||
| final String ch = routingContext.request().getParam(CH_PARAMETER); | ||
| if (StringUtils.isBlank(uuid)) { | ||
| respondWith( | ||
| routingContext, | ||
| HttpResponseStatus.BAD_REQUEST, | ||
| "'%s' is a required query parameter and can't be empty".formatted(UUID_PARAMETER)); | ||
| return; | ||
| } | ||
|
|
||
| final Timeout timeout = timeoutFactory.create(defaultTimeout); | ||
|
|
||
| coreCacheService.getCachedObject(uuid, ch, timeout) | ||
| .onComplete(asyncCache -> handleCacheResult(asyncCache, routingContext)); | ||
| } | ||
|
|
||
| private static void respondWithServerError(RoutingContext routingContext, Throwable exception) { | ||
| logger.error("Error occurred while sending request to cache", exception); | ||
| respondWith(routingContext, HttpResponseStatus.INTERNAL_SERVER_ERROR, | ||
| "%s: %s".formatted("Error occurred while sending request to cache", exception.getMessage())); | ||
| } | ||
|
|
||
| private static void respondWith(RoutingContext routingContext, | ||
| HttpResponseStatus status, | ||
| MultiMap headers, | ||
| String body) { | ||
|
|
||
| HttpUtil.executeSafely( | ||
| routingContext, | ||
| Endpoint.vtrack, | ||
| response -> { | ||
| headers.forEach(response::putHeader); | ||
| response.setStatusCode(status.code()) .end(body); | ||
| }); | ||
AntoxaAntoxic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private static void respondWith(RoutingContext routingContext, HttpResponseStatus status, String body) { | ||
| HttpUtil.executeSafely( | ||
| routingContext, | ||
| Endpoint.vtrack, | ||
| response -> response | ||
| .putHeader(HttpUtil.CONTENT_TYPE_HEADER, HttpHeaderValues.APPLICATION_JSON) | ||
| .setStatusCode(status.code()) | ||
| .end(body)); | ||
| } | ||
|
|
||
| private void handleCacheResult(AsyncResult<HttpClientResponse> async, RoutingContext routingContext) { | ||
| if (async.failed()) { | ||
| respondWithServerError(routingContext, async.cause()); | ||
| } else { | ||
| final HttpClientResponse response = async.result(); | ||
| final HttpResponseStatus status = HttpResponseStatus.valueOf(response.getStatusCode()); | ||
| if (status == HttpResponseStatus.OK) { | ||
| respondWith(routingContext, status, response.getHeaders(), response.getBody()); | ||
| } else { | ||
| respondWith(routingContext, status, response.getBody()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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
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.
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.
No need for lambdas, just pass
accountIdas method argumentThere 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 get, you mean it should be two separate
updateCreativeMetricsmethods for vtrack and auction?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.
No need, it seemed to me that the methods were the same