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

Add metrics info for Mobile CSTG #585

Merged
merged 6 commits into from
May 31, 2024

Conversation

caroline-ttd
Copy link
Contributor

@caroline-ttd caroline-ttd commented May 26, 2024

uid2_token_response_status_count_total{advertising_token_version="V2", application="uid2-operator", cstg="true", instance="host.docker.internal:9080", job="services", platformType="HasOriginHeader", site_id="123", site_name="MegaTest Site", token_endpoint="ClientSideTokenGenerateV2", token_response_status="Success"}

uid2_token_response_status_count_total{advertising_token_version="null", application="uid2-operator", cstg="true", instance="host.docker.internal:9080", job="services", platformType="InApp", site_id="123", site_name="MegaTest Site", token_endpoint="ClientSideTokenGenerateV2", token_response_status="InvalidAppName"}

Slack discussions are here: https://thetradedesk.slack.com/archives/C051ELQ8JAC/p1716760305149009

Add the platformType for /token/client-generate, /token/refresh and /token/generate

@caroline-ttd caroline-ttd changed the title Add metrics info for Mobile CSTGi Add metrics info for Mobile CSTG May 26, 2024
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"))) {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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));
}

?

Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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".

Copy link
Contributor

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() ?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@caroline-ttd caroline-ttd requested review from sunnywu and jon8787 May 30, 2024 03:37
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).
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"origin" not original :)

Copy link
Contributor Author

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");
Copy link
Contributor

@jon8787 jon8787 May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic string, use ClientVersionHeader

Copy link
Contributor Author

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.

@caroline-ttd caroline-ttd requested a review from jon8787 May 31, 2024 01:35
@@ -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);
Copy link
Contributor

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?

Copy link
Contributor Author

@caroline-ttd caroline-ttd May 31, 2024

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

@caroline-ttd caroline-ttd merged commit d670c47 into main May 31, 2024
6 checks passed
@caroline-ttd caroline-ttd deleted the ccm-UID2-3486-add-metrics-info-for-mobile-CSTG branch May 31, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants