This is an automated email from the ASF dual-hosted git repository.
smolnar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git
The following commit(s) were added to refs/heads/master by this push:
new bf96e8f7b fix_metric_name_contain_rowkey1 (#791)
bf96e8f7b is described below
commit bf96e8f7bc7fe10c96f61421cd798739201ce93b
Author: Liang Feng <[email protected]>
AuthorDate: Thu Jul 17 18:19:02 2025 +0800
fix_metric_name_contain_rowkey1 (#791)
---
.../impl/instr/InstrHttpClientBuilderProvider.java | 2 +-
.../services/metrics/impl/instr/InstrUtils.java | 32 ++++++++++++++++++++--
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git
a/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
index f1133107c..6a44a0909 100644
---
a/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
+++
b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
@@ -57,7 +57,7 @@ public class InstrHttpClientBuilderProvider implements
}
RequestLine requestLine = request.getRequestLine();
URIBuilder uriBuilder = new URIBuilder(requestLine.getUri());
- String resourcePath =
InstrUtils.getResourcePath(uriBuilder.removeQuery().build().toString());
+ String resourcePath =
InstrUtils.getServiceResourcePath(uriBuilder.removeQuery().build().toString());
return MetricRegistry.name("service", name, context + resourcePath,
methodNameString(request));
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
diff --git
a/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrUtils.java
b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrUtils.java
index f550ca7e7..ab8afa668 100644
---
a/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrUtils.java
+++
b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrUtils.java
@@ -26,7 +26,13 @@ public class InstrUtils {
//of a path. For example, if the path is “/webhdfs/v1/d1/d2/d2/d4”, this
pattern
//can be used to get the first two ("/webhdfs/v1/"). The "?" in pattern
//ensures not to be greedy in matching.
- private static Pattern p = Pattern.compile("/.*?/.*?/");
+ private static final Pattern p = Pattern.compile("/.*?/.*?/");
+
+ //This regular expression pattern is used to parse the *first* element
+ //of a path. For example, if the path is “/webhdfs/v1/d1/d2/d2/d4”, this
pattern
+ //can be used to get the first ("/webhdfs/"). The "?" in pattern
+ //ensures not to be greedy in matching.
+ private static final Pattern serviceP = Pattern.compile("/.*?/");
/**
* This function parses the pathinfo provided in any servlet context and
@@ -37,9 +43,31 @@ public class InstrUtils {
* @return resource path
*/
public static String getResourcePath(String fullPath) {
+ return getMatchedPath(fullPath, p);
+ }
+
+ /**
+ * This function parses the pathinfo provided in any servlet context and
+ * returns the segment that is related to the resource.
+ * For example, if the path is "/webhdfs/v1/d1/d2/d2/d4". it returns
"/webhdfs/v1"
+ *
+ * @param fullPath full path to determine the resource from
+ * @return resource path
+ */
+ public static String getServiceResourcePath(String fullPath) {
+ return getMatchedPath(fullPath, serviceP);
+ }
+
+ /**
+ * This function return match Pattern pathinfo
+ * @param fullPath full path to determine the resource from
+ * @param pattern this regular expression pattern is used to parse element
+ * @return matched path
+ */
+ private static String getMatchedPath(String fullPath, Pattern pattern) {
String resourcePath = "";
if (fullPath != null && !fullPath.isEmpty()) {
- Matcher m = p.matcher(fullPath);
+ Matcher m = pattern.matcher(fullPath);
if (m.find()) {
resourcePath = m.group(0);
} else {