-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add metrics info for Mobile CSTG #585
Add metrics info for Mobile CSTG #585
Conversation
src/main/java/com/uid2/operator/monitoring/TokenResponseStatsCollector.java
Outdated
Show resolved
Hide resolved
src/main/java/com/uid2/operator/monitoring/TokenResponseStatsCollector.java
Outdated
Show resolved
Hide resolved
src/main/java/com/uid2/operator/monitoring/TokenResponseStatsCollector.java
Outdated
Show resolved
Hide resolved
src/main/java/com/uid2/operator/monitoring/TokenResponseStatsCollector.java
Outdated
Show resolved
Hide resolved
if (siteStore == null) return "unknown"; //this is expected if CSTG is not enabled, eg for private operators | ||
|
||
final Site site = siteStore.getSite(siteId); | ||
return (site == null) ? "unknown" : site.getName(); | ||
} | ||
|
||
private TokenResponseStatsCollector.PlatformType getPlatformType(RoutingContext rc) { | ||
final String clientVersion = rc.request().getHeader("X-UID2-Client-Version"); | ||
if (clientVersion != null && (clientVersion.contains("Android") || clientVersion.contains("ios") || clientVersion.contains("tvos"))) { |
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.
curious, what's tvos
, if it's a CTV string, are there others?
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.
tvOS is essentially iOS of Apple TV.
https://en.wikipedia.org/wiki/TvOS
depends on what os the sdk is built with the client version would say ios or tvos.
no there is no other platform string variants that will appear on X-UID2-Client-Version at this stage.
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.
Just a suggestion not advocating hard for it: maybe we should hardcode the android/ios/tvos list somewhere and then use it like:
public static boolean containsKnownPlatformType(String str, List<String> substrings) {
return substrings.stream().anyMatch(substring -> str.contains(substring));
}
?
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.
We should definitely do that once there's a 2nd use-case. Not sure I'd use stream()
though.
is "tvos" and "ios" case sensitive?
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.
well we are using String.contains which is case sensitive ?
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 added the URL as a comment and created a HashSet for "Android", "ios", "tvOS".
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.
Does it need to be a HashSet? are we ever calling hashSet.contains()
?
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.
Nope, we are only using String.contains SUPPORTED_IN_APP.stream().anyMatch(clientVersionHeader::contains))
.
It can also be an array list, I just feel as the values are unique, maybe good to use HashSet?
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 think we need hashSet.contains()
function, I will change it to an array.
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.
Yes, we're mainly doing iteration, with is faster with an array (not that it matters much). Uniqueness is a good feature but since we're providing all the values, we can already ensure they're unique.
public static void record(ISiteStore siteStore, Integer siteId, Endpoint endpoint, TokenVersion advertisingTokenVersion, ResponseStatus responseStatus) { | ||
recordInternal(siteStore, siteId, endpoint, responseStatus, advertisingTokenVersion, endpoint == Endpoint.ClientSideTokenGenerateV2); | ||
public enum PlatformType { | ||
InApp, // Request containing the "X-UID2-Client-Version" header, typically originating from Android, iOS, or tvOS (Apple TV). |
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.
Not just "X-UID2-Client-Version", since server and JS SDKs contain this as well. It has to specifically contain ios/android/tvos in this header.
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.
Yeah, that makes sense.
recordInternal(siteStore, siteId, endpoint, responseStatus, advertisingTokenVersion, endpoint == Endpoint.ClientSideTokenGenerateV2); | ||
public enum PlatformType { | ||
InApp, // Request containing the "X-UID2-Client-Version" header, typically originating from Android, iOS, or tvOS (Apple TV). | ||
HasOriginHeader, // Request containing the "original" header, originating from the web. |
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.
"origin" not original :)
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.
Thank you for catching it!
@@ -1793,6 +1806,17 @@ public static String getSiteName(ISiteStore siteStore, Integer siteId) { | |||
return (site == null) ? "unknown" : site.getName(); | |||
} | |||
|
|||
private TokenResponseStatsCollector.PlatformType getPlatformType(RoutingContext rc) { | |||
final String clientVersionHeader = rc.request().getHeader("X-UID2-Client-Version"); |
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.
magic string, use ClientVersionHeader
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.
Oh, sorry, I got it. Will change.
@@ -518,7 +525,7 @@ private OriginOrAppNameValidationResult validateOriginOrAppName(RoutingContext r | |||
: OriginOrAppNameValidationResult.invalidAppName(appName); | |||
} | |||
|
|||
final String origin = rc.request().getHeader("origin"); | |||
final String origin = rc.request().getHeader(ORIGIN_HEADER); |
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.
It's actually the whole expression rc.request().getHeader(ORIGIN_HEADER);
that's duplicated many times, not just the "origin" string. So we should instead have a method getOriginHeader(rc)
.
But that raises a question - why do we sometimes have rc.request().headers().contains(ORIGIN_HEADER));
instead of getHeader
?
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.
From the doc, getHeader vs headers looks like no difference.
rc.request().headers().contains(ORIGIN_HEADER));
from the MR.
Hi Vishal, looks like you made this change, do you have any input @vishalegbert-ttd
Slack discussions are here: https://thetradedesk.slack.com/archives/C051ELQ8JAC/p1716760305149009
Add the platformType for
/token/client-generate
,/token/refresh
and/token/generate