knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [56/64] knox git commit: Merge branch 'master' into KNOX-998-Package_Restructuring
Date Fri, 01 Sep 2017 13:17:54 GMT
Merge branch 'master' into KNOX-998-Package_Restructuring


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

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: a4ba9bb5c46a36649907b9662ee7686c2c1d943a
Parents: af9b0c3 ac532bd
Author: Sandeep More <more@apache.org>
Authored: Tue Aug 29 10:34:03 2017 -0400
Committer: Sandeep More <more@apache.org>
Committed: Tue Aug 29 10:34:03 2017 -0400

----------------------------------------------------------------------
 .../services/metrics/impl/instr/InstrUtils.java | 54 ++++++++++++++++++++
 .../instr/InstrHttpClientBuilderProvider.java   |  3 +-
 .../impl/instr/InstrumentedGatewayFilter.java   |  2 +-
 .../services/zeppelinui/0.6.0/rewrite.xml       |  4 +-
 4 files changed, 60 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/a4ba9bb5/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
----------------------------------------------------------------------
diff --cc gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
index 341b35c,0000000..073adcd
mode 100644,000000..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
@@@ -1,70 -1,0 +1,71 @@@
 +/**
 + * 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.knox.gateway.services.metrics.impl.instr;
 +
 +import com.codahale.metrics.MetricRegistry;
 +import com.codahale.metrics.httpclient.HttpClientMetricNameStrategy;
 +import com.codahale.metrics.httpclient.InstrumentedHttpRequestExecutor;
 +import org.apache.knox.gateway.services.metrics.InstrumentationProvider;
 +import org.apache.knox.gateway.services.metrics.MetricsContext;
 +import org.apache.knox.gateway.services.metrics.impl.DefaultMetricsService;
 +import org.apache.http.Header;
 +import org.apache.http.HttpRequest;
 +import org.apache.http.RequestLine;
 +import org.apache.http.client.utils.URIBuilder;
 +import org.apache.http.impl.client.HttpClientBuilder;
 +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 +
 +import java.net.URISyntaxException;
 +
 +public class InstrHttpClientBuilderProvider implements
 +    InstrumentationProvider<HttpClientBuilder> {
 +
 +  @Override
 +  public HttpClientBuilder getInstrumented(MetricsContext metricsContext) {
 +    MetricRegistry registry = (MetricRegistry) metricsContext.getProperty(DefaultMetricsService.METRICS_REGISTRY);
 +    return  HttpClientBuilder.create().setRequestExecutor(new InstrumentedHttpRequestExecutor(registry,
TOPOLOGY_URL_AND_METHOD)).
 +        setConnectionManager(new PoolingHttpClientConnectionManager());
 +  }
 +
 +  @Override
 +  public HttpClientBuilder getInstrumented(HttpClientBuilder instanceClass, MetricsContext
metricsContext) {
 +    throw new UnsupportedOperationException();
 +  }
 +
 +  private static final HttpClientMetricNameStrategy TOPOLOGY_URL_AND_METHOD = new HttpClientMetricNameStrategy()
{
 +    public String getNameFor(String name, HttpRequest request) {
 +      try {
 +        String context = "";
 +        Header header = request.getFirstHeader("X-Forwarded-Context");
 +        if (header != null) {
 +          context = header.getValue();
 +        }
 +        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);
 +      }
 +    }
 +
 +    private String methodNameString(HttpRequest request) {
 +      return request.getRequestLine().getMethod().toLowerCase() + "-requests";
 +    }
 +  };
 +}

http://git-wip-us.apache.org/repos/asf/knox/blob/a4ba9bb5/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrumentedGatewayFilter.java
----------------------------------------------------------------------
diff --cc gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrumentedGatewayFilter.java
index 4d0b74f,0000000..a9009db
mode 100644,000000..100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrumentedGatewayFilter.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrumentedGatewayFilter.java
@@@ -1,99 -1,0 +1,99 @@@
 +/**
 + * 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.knox.gateway.services.metrics.impl.instr;
 +
 +import com.codahale.metrics.MetricRegistry;
 +import com.codahale.metrics.Timer;
 +import org.apache.knox.gateway.GatewayFilter;
 +
 +import javax.servlet.Filter;
 +import javax.servlet.FilterChain;
 +import javax.servlet.FilterConfig;
 +import javax.servlet.ServletException;
 +import javax.servlet.ServletRequest;
 +import javax.servlet.ServletResponse;
 +import javax.servlet.http.HttpServletRequest;
 +import java.io.IOException;
 +import java.net.URISyntaxException;
 +import java.util.Map;
 +
 +public class InstrumentedGatewayFilter extends GatewayFilter {
 +
 +  private GatewayFilter gatewayFilter;
 +
 +  private MetricRegistry metricRegistry;
 +
 +  public InstrumentedGatewayFilter(GatewayFilter gatewayFilter, MetricRegistry metricRegistry)
{
 +    this.gatewayFilter = gatewayFilter;
 +    this.metricRegistry = metricRegistry;
 +  }
 +
 +  @Override
 +  public void init(FilterConfig filterConfig) throws ServletException {
 +    gatewayFilter.init(filterConfig);
 +  }
 +
 +  @Override
 +  public void destroy() {
 +    gatewayFilter.destroy();
 +  }
 +
 +  @Override
 +  public void addFilter(String path, String name, Filter filter, Map<String, String>
params, String resourceRole) throws URISyntaxException {
 +    gatewayFilter.addFilter(path, name, filter, params, resourceRole);
 +  }
 +
 +  @Override
 +  public void addFilter(String path, String name, String clazz, Map<String, String>
params, String resourceRole) throws URISyntaxException {
 +    gatewayFilter.addFilter(path, name, clazz, params, resourceRole);
 +  }
 +
 +  @Override
 +  public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain
filterChain) throws IOException, ServletException {
 +    Timer.Context timerContext = this.timer(servletRequest).time();
 +    try {
 +      gatewayFilter.doFilter(servletRequest, servletResponse, filterChain);
 +    } finally {
 +      timerContext.stop();
 +    }
 +  }
 +
 +  @Override
 +  public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws
IOException, ServletException {
 +    Timer.Context timerContext = this.timer(servletRequest).time();
 +    try {
 +      gatewayFilter.doFilter(servletRequest, servletResponse);
 +    } finally {
 +      timerContext.stop();
 +    }
 +  }
 +
 +  private Timer timer(ServletRequest request) {
 +    StringBuilder builder = new StringBuilder();
 +    builder.append("client.");
 +    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");
 +    }
 +    return metricRegistry.timer(builder.toString());
 +  }
 +}


Mime
View raw message