You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by mo...@apache.org on 2017/08/25 16:10:56 UTC

knox git commit: KNOX-989 - Report metrics at service level (/webhdfs/v1) instead of url with args (/webhdfs/v1/?op=LISTSTATUS) (Mohammad Kamrul Islam via Sandeep More)

Repository: knox
Updated Branches:
  refs/heads/master bea3974a8 -> ac532bd73


KNOX-989 - Report metrics at service level (/webhdfs/v1) instead of url with args (/webhdfs/v1/?op=LISTSTATUS) (Mohammad Kamrul Islam via Sandeep More)


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/ac532bd7
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/ac532bd7
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/ac532bd7

Branch: refs/heads/master
Commit: ac532bd73c5da8997f865e048b36c76fd3c11301
Parents: bea3974
Author: Sandeep More <mo...@apache.org>
Authored: Fri Aug 25 12:08:17 2017 -0400
Committer: Sandeep More <mo...@apache.org>
Committed: Fri Aug 25 12:09:21 2017 -0400

----------------------------------------------------------------------
 .../instr/InstrHttpClientBuilderProvider.java   |  3 +-
 .../services/metrics/impl/instr/InstrUtils.java | 54 ++++++++++++++++++++
 .../impl/instr/InstrumentedGatewayFilter.java   |  2 +-
 3 files changed, 57 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/ac532bd7/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
index eb3ec57..e96c05e 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
@@ -57,7 +57,8 @@ public class InstrHttpClientBuilderProvider implements InstrumentationProvider<H
         }
         RequestLine requestLine = request.getRequestLine();
         URIBuilder uriBuilder = new URIBuilder(requestLine.getUri());
-        return MetricRegistry.name("service", new String[]{name, context + uriBuilder.removeQuery().build().toString(), methodNameString(request)});
+        String resourcePath = InstrUtils.getResourcePath(uriBuilder.removeQuery().build().toString());
+        return MetricRegistry.name("service", new String[]{name, context + resourcePath, methodNameString(request)});
       } catch (URISyntaxException e) {
         throw new IllegalArgumentException(e);
       }

http://git-wip-us.apache.org/repos/asf/knox/blob/ac532bd7/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrUtils.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrUtils.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrUtils.java
new file mode 100644
index 0000000..20e359b
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrUtils.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.services.metrics.impl.instr;
+
+import com.google.common.base.Strings;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class InstrUtils {
+
+    //This regular expression pattern is used to parse the *first* two elements
+    //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("/.*?/.*?/");
+
+    /**
+     * 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
+     * @return
+     */
+    public static String getResourcePath(String fullPath) {
+        String resourcePath = "";
+        if (!Strings.isNullOrEmpty(fullPath)) {
+            Matcher m = p.matcher(fullPath);
+            if (m.find()) {
+                resourcePath = m.group(0);
+            } else {
+                resourcePath = fullPath;
+            }
+        }
+        return resourcePath;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/ac532bd7/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrumentedGatewayFilter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrumentedGatewayFilter.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrumentedGatewayFilter.java
index a3c75f6..063d79a 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrumentedGatewayFilter.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrumentedGatewayFilter.java
@@ -89,7 +89,7 @@ public class InstrumentedGatewayFilter extends GatewayFilter {
     builder.append(request.getServletContext().getContextPath());
     if (request instanceof HttpServletRequest) {
       HttpServletRequest httpServletRequest = (HttpServletRequest) request;
-      builder.append(httpServletRequest.getPathInfo());
+      builder.append(InstrUtils.getResourcePath(httpServletRequest.getPathInfo()));
       builder.append(".");
       builder.append(httpServletRequest.getMethod());
       builder.append("-requests");