Skip to content

Commit c4e3f7d

Browse files
committed
add more metrics
1 parent 80ec15d commit c4e3f7d

2 files changed

Lines changed: 65 additions & 21 deletions

File tree

src/main/java/com/uid2/operator/vertx/UIDOperatorVerticle.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ private void handleTokenValidateV2(RoutingContext rc) {
910910
recordTokenValidateStats(participantSiteId, "invalid_input");
911911
return;
912912
}
913-
recordRawEmailDotMetric(input, rc.request().path());
913+
recordRawEmailMetrics(input, rc.request().path());
914914

915915
final Instant now = Instant.now();
916916
final String token = req.getString("token");
@@ -953,7 +953,7 @@ private void handleTokenGenerateV2(RoutingContext rc) {
953953

954954
final InputUtil.InputVal input = this.getTokenInputV2(req);
955955
if (isTokenInputValid(input, rc)) {
956-
recordRawEmailDotMetric(input, rc.request().path());
956+
recordRawEmailMetrics(input, rc.request().path());
957957
final String apiContact = getApiContact(rc);
958958

959959
switch (validateUserConsent(req, apiContact)) {
@@ -1010,7 +1010,7 @@ private Future handleLogoutAsyncV2(RoutingContext rc) {
10101010
final InputUtil.InputVal input = getTokenInputV2(req);
10111011
final String uidTraceId = rc.request().getHeader(Audit.UID_TRACE_ID_HEADER);
10121012
if (input != null && input.isValid()) {
1013-
recordRawEmailDotMetric(input, rc.request().path());
1013+
recordRawEmailMetrics(input, rc.request().path());
10141014
final Instant now = Instant.now();
10151015

10161016
Promise promise = Promise.promise();
@@ -1237,7 +1237,7 @@ private void handleIdentityMapV2(RoutingContext rc) {
12371237

12381238
if (v2Input.diiType().equals("email")) {
12391239
for (InputUtil.InputVal input : v2Input.inputList()) {
1240-
recordRawEmailDotMetric(input, rc.request().path());
1240+
recordRawEmailMetrics(input, rc.request().path());
12411241
}
12421242
}
12431243

@@ -1307,7 +1307,7 @@ private void handleIdentityMapV3(RoutingContext rc) {
13071307
InputUtil.InputVal[] emailInputs = normalizedInput.get("email");
13081308
if (emailInputs != null) {
13091309
for (InputUtil.InputVal emailInput : emailInputs) {
1310-
recordRawEmailDotMetric(emailInput, rc.request().path());
1310+
recordRawEmailMetrics(emailInput, rc.request().path());
13111311
}
13121312
}
13131313

@@ -1523,22 +1523,50 @@ public TokenVersion getRefreshTokenVersion(String s) {
15231523
return null;
15241524
}
15251525

1526-
private void recordRawEmailDotMetric(InputUtil.InputVal input, String path) {
1526+
private void recordRawEmailMetrics(InputUtil.InputVal input, String path) {
15271527
if (!input.isValid() || input.getInputType() != InputUtil.IdentityInputType.Raw
15281528
|| input.getIdentityType() != IdentityType.Email) {
15291529
return;
15301530
}
15311531
String provided = input.getProvided();
15321532
int atIndex = provided.indexOf('@');
1533-
boolean hasDot = atIndex > 0 && provided.lastIndexOf('.', atIndex) >= 0;
15341533
boolean isGmail = input.getNormalized().endsWith("@gmail.com");
1534+
1535+
boolean hasDot = atIndex > 0 && provided.lastIndexOf('.', atIndex) >= 0;
15351536
Counter.builder("uid2_operator_raw_email_dot_total")
1536-
.description("Count of valid raw emails processed, by presence of dot before @ and gmail domain")
1537+
.description("Count of valid raw emails processed, by presence of dot before @")
15371538
.tag("path", path)
15381539
.tag("has_dot", String.valueOf(hasDot))
15391540
.tag("is_gmail", String.valueOf(isGmail))
15401541
.register(Metrics.globalRegistry)
15411542
.increment();
1543+
1544+
int plusIndex = provided.indexOf('+');
1545+
boolean hasPlus = plusIndex >= 0 && plusIndex < atIndex;
1546+
Counter.builder("uid2_operator_raw_email_plus_total")
1547+
.description("Count of valid raw emails processed, by presence of + before @")
1548+
.tag("path", path)
1549+
.tag("has_plus", String.valueOf(hasPlus))
1550+
.tag("is_gmail", String.valueOf(isGmail))
1551+
.register(Metrics.globalRegistry)
1552+
.increment();
1553+
1554+
boolean hasTrailingDot = provided.charAt(provided.length() - 1) == '.';
1555+
Counter.builder("uid2_operator_raw_email_trailing_dot_total")
1556+
.description("Count of valid raw emails processed, by presence of trailing dot at end of address")
1557+
.tag("path", path)
1558+
.tag("has_trailing_dot", String.valueOf(hasTrailingDot))
1559+
.register(Metrics.globalRegistry)
1560+
.increment();
1561+
1562+
boolean hasWhitespace = provided.strip().chars().anyMatch(Character::isWhitespace);
1563+
Counter.builder("uid2_operator_raw_email_whitespace_total")
1564+
.description("Count of valid raw emails processed, by presence of internal whitespace and gmail domain")
1565+
.tag("path", path)
1566+
.tag("has_whitespace", String.valueOf(hasWhitespace))
1567+
.tag("is_gmail", String.valueOf(isGmail))
1568+
.register(Metrics.globalRegistry)
1569+
.increment();
15421570
}
15431571

15441572
private void recordRefreshTokenVersionCount(String siteId, TokenVersion tokenVersion) {

src/test/java/com/uid2/operator/UIDOperatorVerticleTest.java

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5254,37 +5254,53 @@ void asyncBatchRequestEnabledLogsCorrectMessage(Vertx vertx, VertxTestContext te
52545254
}
52555255

52565256
@Test
5257-
void rawEmailDotMetricRecorded(Vertx vertx, VertxTestContext testContext) {
5257+
void rawEmailMetricsRecorded(Vertx vertx, VertxTestContext testContext) {
52585258
fakeAuth(201, Role.GENERATOR, Role.MAPPER);
52595259
setupSalts();
52605260
setupKeys();
52615261

5262-
// /v2/token/generate
5262+
// /v2/token/generate — one email per characteristic being tested
52635263
String emailHash = TokenUtils.getIdentityHashString("hash@example.com");
5264-
sendTokenGenerate(vertx, new JsonObject().put("email", "john.doe@example.com"), 200, json -> {}); // dot, non-gmail
5265-
sendTokenGenerate(vertx, new JsonObject().put("email", "johndoe@example.com"), 200, json -> {}); // no dot, non-gmail
5266-
sendTokenGenerate(vertx, new JsonObject().put("email", "john.doe@gmail.com"), 200, json -> {}); // dot, gmail
5267-
sendTokenGenerate(vertx, new JsonObject().put("email_hash", emailHash), 200, json -> { // hash - should not record
5268-
5264+
sendTokenGenerate(vertx, new JsonObject().put("email", "john.doe@example.com"), 200, json -> {}); // dot, no plus, non-gmail
5265+
sendTokenGenerate(vertx, new JsonObject().put("email", "johndoe@example.com"), 200, json -> {}); // no dot, non-gmail
5266+
sendTokenGenerate(vertx, new JsonObject().put("email", "john.doe@gmail.com"), 200, json -> {}); // dot, gmail
5267+
sendTokenGenerate(vertx, new JsonObject().put("email", "john+tag@example.com"), 200, json -> {}); // plus, non-gmail
5268+
sendTokenGenerate(vertx, new JsonObject().put("email", "john+tag@gmail.com"), 200, json -> {}); // plus, gmail
5269+
sendTokenGenerate(vertx, new JsonObject().put("email", "john@example.com."), 200, json -> {}); // trailing dot
5270+
sendTokenGenerate(vertx, new JsonObject().put("email_hash", emailHash), 200, json -> { // hash - should not record
5271+
5272+
// dot metric
52695273
assertEquals(1, Metrics.globalRegistry
52705274
.get("uid2_operator_raw_email_dot_total")
52715275
.tag("path", "/v2/token/generate").tag("has_dot", "true").tag("is_gmail", "false")
52725276
.counter().count());
52735277
assertEquals(1, Metrics.globalRegistry
5278+
.get("uid2_operator_raw_email_dot_total")
5279+
.tag("path", "/v2/token/generate").tag("has_dot", "true").tag("is_gmail", "true")
5280+
.counter().count());
5281+
// has_dot=false, is_gmail=false count is 3 (johndoe, john+tag@example.com, john@example.com.) — hash did not increment
5282+
assertEquals(3, Metrics.globalRegistry
52745283
.get("uid2_operator_raw_email_dot_total")
52755284
.tag("path", "/v2/token/generate").tag("has_dot", "false").tag("is_gmail", "false")
52765285
.counter().count());
5286+
5287+
// plus metric
52775288
assertEquals(1, Metrics.globalRegistry
5278-
.get("uid2_operator_raw_email_dot_total")
5279-
.tag("path", "/v2/token/generate").tag("has_dot", "true").tag("is_gmail", "true")
5289+
.get("uid2_operator_raw_email_plus_total")
5290+
.tag("path", "/v2/token/generate").tag("has_plus", "true").tag("is_gmail", "false")
52805291
.counter().count());
5281-
// has_dot=false, is_gmail=false count is still 1 — hash request did not increment it
52825292
assertEquals(1, Metrics.globalRegistry
5283-
.get("uid2_operator_raw_email_dot_total")
5284-
.tag("path", "/v2/token/generate").tag("has_dot", "false").tag("is_gmail", "false")
5293+
.get("uid2_operator_raw_email_plus_total")
5294+
.tag("path", "/v2/token/generate").tag("has_plus", "true").tag("is_gmail", "true")
5295+
.counter().count());
5296+
5297+
// trailing dot metric
5298+
assertEquals(1, Metrics.globalRegistry
5299+
.get("uid2_operator_raw_email_trailing_dot_total")
5300+
.tag("path", "/v2/token/generate").tag("has_trailing_dot", "true")
52855301
.counter().count());
52865302

5287-
// /v2/identity/map — batch with two dot emails to verify counter reaches 2
5303+
// /v2/identity/map — batch with two emails to verify counter reaches 2
52885304
JsonObject mapReq = new JsonObject().put("email", new JsonArray()
52895305
.add("a.b@example.com")
52905306
.add("c.d@example.com"));

0 commit comments

Comments
 (0)