From ee2a6dfacd3287e0d05640e98608ef01f2633b35 Mon Sep 17 00:00:00 2001 From: Samin Rahman Date: Thu, 8 Jan 2026 15:23:42 +1100 Subject: [PATCH 1/4] Added optimized filter path for HTTPPathMetricFilter cases (like operator) without need for expensive path parameter resolution --- .../shared/util/HTTPPathMetricFilter.java | 33 ++++++++++++- .../shared/util/HTTPPathMetricFilterTest.java | 48 ++++++++++++++++++- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java b/src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java index 6c8f645d..f4af48f4 100644 --- a/src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java +++ b/src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java @@ -6,7 +6,13 @@ public class HTTPPathMetricFilter { public static String filterPath(String actualPath, Set pathSet) { try { - String normalized = HttpUtils.normalizePath(actualPath).split("\\?")[0]; + String normalized = HttpUtils.normalizePath(actualPath); + /* Optimization 1: Split that avoids array and regex initialization */ + int splitIndex = normalized.indexOf('?'); + if (splitIndex != -1) { + normalized = normalized.substring(0, splitIndex); + } + if (normalized.charAt(normalized.length() - 1) == '/') { normalized = normalized.substring(0, normalized.length() - 1); } @@ -25,4 +31,29 @@ public static String filterPath(String actualPath, Set pathSet) { return "/parsing_error"; } } + + public static String filterPathWithoutPathParameters(String actualPath, Set pathSet) { + try { + String normalized = HttpUtils.normalizePath(actualPath); + /* Optimization 1: Split that avoids array and regex initialization */ + int splitIndex = normalized.indexOf('?'); + if (splitIndex != -1) { + normalized = normalized.substring(0, splitIndex); + } + + if (normalized.charAt(normalized.length() - 1) == '/') { + normalized = normalized.substring(0, normalized.length() - 1); + } + normalized = normalized.toLowerCase(); + + if (pathSet == null || pathSet.isEmpty()) { return normalized; } + + /* Optimization 2: Remove for loop and regex matching */ + if (pathSet.contains(normalized)) { return normalized; } + + return "/unknown"; + } catch (IllegalArgumentException e) { + return "/parsing_error"; + } + } } diff --git a/src/test/java/com/uid2/shared/util/HTTPPathMetricFilterTest.java b/src/test/java/com/uid2/shared/util/HTTPPathMetricFilterTest.java index fac26482..94d1ff6a 100644 --- a/src/test/java/com/uid2/shared/util/HTTPPathMetricFilterTest.java +++ b/src/test/java/com/uid2/shared/util/HTTPPathMetricFilterTest.java @@ -8,7 +8,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class HTTPPathMetricFilterTest { +public class HTTPPathMetricFilterTest { + /* filterPathTests */ final Set pathSet = Set.of("/v1/identity/map", "/token/refresh", "/list", "/list/:siteId/:keyId"); @ParameterizedTest @@ -54,4 +55,49 @@ void testPathFiltering_ValidPaths_KnownEndpoints(String actualPath, String expec String filteredPath = HTTPPathMetricFilter.filterPath(actualPath, pathSet); assertEquals(expectedFilteredPath, filteredPath); } + + /* filterPathWithoutPathParameters tests */ + final Set pathSetWithoutParams = Set.of("/v1/identity/map", "/token/refresh", "/list"); + + @ParameterizedTest + @ValueSource(strings = { + "", + "/", + "/unknown-path", + "../", + "/v1/identity/map%55", + "/list/123", + }) + void testPathFilteringWithoutPathParameters_InvalidPaths_Unknown(String actualPath) { + String filteredPath = HTTPPathMetricFilter.filterPathWithoutPathParameters(actualPath, pathSetWithoutParams); + assertEquals("/unknown", filteredPath); + } + + @ParameterizedTest + @ValueSource(strings = { + "v1/identity/map?id=bad-escape-code%2", + "token/refresh?refresh_token=SOME_TOKEN<%=7485*4353%>", + "list/12%4/5435" + }) + void testPathFilteringWithoutPathParameters_InvalidPaths_ParsingError(String actualPath) { + String filteredPath = HTTPPathMetricFilter.filterPathWithoutPathParameters(actualPath, pathSetWithoutParams); + assertEquals("/parsing_error", filteredPath); + } + + @ParameterizedTest + @CsvSource(value = { + "/v1/identity/map, /v1/identity/map", + "v1/identity/map, /v1/identity/map", + "V1/IdenTity/mAp, /v1/identity/map", + "./v1//identity//map/, /v1/identity/map", + "../v1/identity/./map, /v1/identity/map", + "/v1/identity/new/path/../../map, /v1/identity/map", + "token/refresh?refresh_token=123%20%23, /token/refresh", + "v1/identity/map?identity/../map/, /v1/identity/map", + "/list, /list" + }) + void testPathFilteringWithoutPathParameters_ValidPaths_KnownEndpoints(String actualPath, String expectedFilteredPath) { + String filteredPath = HTTPPathMetricFilter.filterPathWithoutPathParameters(actualPath, pathSetWithoutParams); + assertEquals(expectedFilteredPath, filteredPath); + } } From 8642ad5e404fbff31406c33b0ff85c1af1fea591 Mon Sep 17 00:00:00 2001 From: Release Workflow Date: Thu, 8 Jan 2026 04:56:42 +0000 Subject: [PATCH 2/4] [CI Pipeline] Released Snapshot version: 11.3.4-alpha-334-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0eb36c82..ea50188a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.uid2 uid2-shared - 11.3.3 + 11.3.4-alpha-334-SNAPSHOT ${project.groupId}:${project.artifactId} Library for all the shared uid2 operations https://github.com/IABTechLab/uid2docs From af68175b46191231065af876df4e7afbfcdd8e52 Mon Sep 17 00:00:00 2001 From: Samin Rahman Date: Mon, 12 Jan 2026 09:22:37 +1100 Subject: [PATCH 3/4] Removed redundant commits --- src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java b/src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java index f4af48f4..43a3a2fc 100644 --- a/src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java +++ b/src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java @@ -7,7 +7,7 @@ public class HTTPPathMetricFilter { public static String filterPath(String actualPath, Set pathSet) { try { String normalized = HttpUtils.normalizePath(actualPath); - /* Optimization 1: Split that avoids array and regex initialization */ + int splitIndex = normalized.indexOf('?'); if (splitIndex != -1) { normalized = normalized.substring(0, splitIndex); @@ -35,7 +35,7 @@ public static String filterPath(String actualPath, Set pathSet) { public static String filterPathWithoutPathParameters(String actualPath, Set pathSet) { try { String normalized = HttpUtils.normalizePath(actualPath); - /* Optimization 1: Split that avoids array and regex initialization */ + int splitIndex = normalized.indexOf('?'); if (splitIndex != -1) { normalized = normalized.substring(0, splitIndex); @@ -48,7 +48,6 @@ public static String filterPathWithoutPathParameters(String actualPath, Set Date: Mon, 12 Jan 2026 14:23:32 +1100 Subject: [PATCH 4/4] Extracted HTTP Path normalization as a Utils function --- src/main/java/com/uid2/shared/Utils.java | 17 ++++++++++++ .../shared/util/HTTPPathMetricFilter.java | 26 +++---------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/uid2/shared/Utils.java b/src/main/java/com/uid2/shared/Utils.java index 92c9180b..230709ee 100644 --- a/src/main/java/com/uid2/shared/Utils.java +++ b/src/main/java/com/uid2/shared/Utils.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.uid2.shared.util.Mapper; +import io.vertx.core.http.impl.HttpUtils; import io.vertx.core.json.Json; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; @@ -190,4 +191,20 @@ public static MessageDigest createMessageDigestSHA512() { throw new RuntimeException(e); } } + + public static String getNormalizedHttpPath(String path) { + String normalized = HttpUtils.normalizePath(path); + + int splitIndex = normalized.indexOf('?'); + if (splitIndex != -1) { + normalized = normalized.substring(0, splitIndex); + } + + if (normalized.charAt(normalized.length() - 1) == '/') { + normalized = normalized.substring(0, normalized.length() - 1); + } + normalized = normalized.toLowerCase(); + + return normalized; + } } diff --git a/src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java b/src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java index 43a3a2fc..ba7ffaae 100644 --- a/src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java +++ b/src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java @@ -1,22 +1,12 @@ package com.uid2.shared.util; -import io.vertx.core.http.impl.HttpUtils; +import com.uid2.shared.Utils; import java.util.Set; public class HTTPPathMetricFilter { public static String filterPath(String actualPath, Set pathSet) { try { - String normalized = HttpUtils.normalizePath(actualPath); - - int splitIndex = normalized.indexOf('?'); - if (splitIndex != -1) { - normalized = normalized.substring(0, splitIndex); - } - - if (normalized.charAt(normalized.length() - 1) == '/') { - normalized = normalized.substring(0, normalized.length() - 1); - } - normalized = normalized.toLowerCase(); + String normalized = Utils.getNormalizedHttpPath(actualPath); if (pathSet == null || pathSet.isEmpty()) { return normalized; } @@ -34,17 +24,7 @@ public static String filterPath(String actualPath, Set pathSet) { public static String filterPathWithoutPathParameters(String actualPath, Set pathSet) { try { - String normalized = HttpUtils.normalizePath(actualPath); - - int splitIndex = normalized.indexOf('?'); - if (splitIndex != -1) { - normalized = normalized.substring(0, splitIndex); - } - - if (normalized.charAt(normalized.length() - 1) == '/') { - normalized = normalized.substring(0, normalized.length() - 1); - } - normalized = normalized.toLowerCase(); + String normalized = Utils.getNormalizedHttpPath(actualPath); if (pathSet == null || pathSet.isEmpty()) { return normalized; }