cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cxf git commit: CXF-6360: Integration with Apache HTrace
Date Mon, 15 Jun 2015 02:23:54 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 1542c8d62 -> b1f19a196


CXF-6360: Integration with Apache HTrace


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

Branch: refs/heads/master
Commit: b1f19a1962d3791211ce83038e8641598c6f5ccf
Parents: 1542c8d
Author: reta <drreta@gmail.com>
Authored: Sun Jun 14 22:23:39 2015 -0400
Committer: reta <drreta@gmail.com>
Committed: Sun Jun 14 22:23:39 2015 -0400

----------------------------------------------------------------------
 .../tracing/htrace/AbstractHTraceProvider.java  | 35 +------------
 .../htrace/jaxrs/HTraceClientProvider.java      | 20 ++------
 .../cxf/tracing/AbstractTracingProvider.java    | 53 ++++++++++++++++++++
 .../htrace/HTraceTracingCustomHeadersTest.java  | 38 ++++++++++++--
 4 files changed, 91 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/b1f19a19/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
index 29cedb0..7d68417 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
@@ -24,11 +24,8 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.tracing.TracerHeaders;
+import org.apache.cxf.tracing.AbstractTracingProvider;
 import org.apache.htrace.Sampler;
 import org.apache.htrace.Trace;
 import org.apache.htrace.TraceInfo;
@@ -36,10 +33,7 @@ import org.apache.htrace.TraceScope;
 import org.apache.htrace.Tracer;
 import org.apache.htrace.impl.MilliSpan;
 
-import static org.apache.cxf.tracing.TracerHeaders.DEFAULT_HEADER_SPAN_ID;
-import static org.apache.cxf.tracing.TracerHeaders.DEFAULT_HEADER_TRACE_ID;
-
-public abstract class AbstractHTraceProvider  { 
+public abstract class AbstractHTraceProvider extends AbstractTracingProvider { 
     protected static final Logger LOG = LogUtils.getL7dLogger(AbstractHTraceProvider.class);
     protected static final String TRACE_SPAN = "org.apache.cxf.tracing.htrace.span";
         
@@ -101,29 +95,4 @@ public abstract class AbstractHTraceProvider  {
         }
         return defaultValue;
     }
-    
-    private static String getSpanIdHeader() {
-        return getHeaderOrDefault(TracerHeaders.HEADER_SPAN_ID, DEFAULT_HEADER_SPAN_ID);
-    }
-    
-    private static String getTraceIdHeader() {
-        return getHeaderOrDefault(TracerHeaders.HEADER_TRACE_ID, DEFAULT_HEADER_TRACE_ID);
-    }
-
-    private static String getHeaderOrDefault(final String property, final String fallback)
{
-        final Message message = PhaseInterceptorChain.getCurrentMessage();
-        
-        if (message != null) {
-            final Object header = message.getContextualProperty(property);
-            
-            if (header instanceof String) {
-                final String name = (String)header;
-                if (!StringUtils.isEmpty(name)) {
-                    return name;
-                }
-            }
-        }
-        
-        return fallback;
-    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/b1f19a19/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceClientProvider.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceClientProvider.java
b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceClientProvider.java
index ff483e2..313cef3 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceClientProvider.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceClientProvider.java
@@ -27,18 +27,16 @@ import javax.ws.rs.client.ClientResponseFilter;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.Provider;
 
-import org.apache.cxf.tracing.TracerHeaders;
+import org.apache.cxf.tracing.AbstractTracingProvider;
 import org.apache.htrace.Sampler;
 import org.apache.htrace.Span;
 import org.apache.htrace.Trace;
 import org.apache.htrace.TraceScope;
 import org.apache.htrace.impl.NeverSampler;
 
-import static org.apache.cxf.tracing.TracerHeaders.DEFAULT_HEADER_SPAN_ID;
-import static org.apache.cxf.tracing.TracerHeaders.DEFAULT_HEADER_TRACE_ID;
-
 @Provider
-public class HTraceClientProvider implements ClientRequestFilter, ClientResponseFilter {
+public class HTraceClientProvider extends AbstractTracingProvider 
+        implements ClientRequestFilter, ClientResponseFilter {
     private static final String TRACE_SPAN = "org.apache.cxf.tracing.client.htrace.span";
     
     private final Sampler< ? > sampler;
@@ -85,16 +83,4 @@ public class HTraceClientProvider implements ClientRequestFilter, ClientResponse
             scope.close();
         }
     }
-    
-    private static String getSpanIdHeader() {
-        return getHeaderOrDefault(TracerHeaders.HEADER_SPAN_ID, DEFAULT_HEADER_SPAN_ID);
-    }
-    
-    private static String getTraceIdHeader() {
-        return getHeaderOrDefault(TracerHeaders.HEADER_TRACE_ID, DEFAULT_HEADER_TRACE_ID);
-    }
-
-    private static String getHeaderOrDefault(final String property, final String fallback)
{
-        return fallback;
-    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/b1f19a19/rt/management/src/main/java/org/apache/cxf/tracing/AbstractTracingProvider.java
----------------------------------------------------------------------
diff --git a/rt/management/src/main/java/org/apache/cxf/tracing/AbstractTracingProvider.java
b/rt/management/src/main/java/org/apache/cxf/tracing/AbstractTracingProvider.java
new file mode 100644
index 0000000..71263bf
--- /dev/null
+++ b/rt/management/src/main/java/org/apache/cxf/tracing/AbstractTracingProvider.java
@@ -0,0 +1,53 @@
+/**
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.cxf.tracing;
+
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.PhaseInterceptorChain;
+
+import static org.apache.cxf.tracing.TracerHeaders.DEFAULT_HEADER_SPAN_ID;
+import static org.apache.cxf.tracing.TracerHeaders.DEFAULT_HEADER_TRACE_ID;
+
+public abstract class AbstractTracingProvider {
+    protected static String getSpanIdHeader() {
+        return getHeaderOrDefault(TracerHeaders.HEADER_SPAN_ID, DEFAULT_HEADER_SPAN_ID);
+    }
+    
+    protected static String getTraceIdHeader() {
+        return getHeaderOrDefault(TracerHeaders.HEADER_TRACE_ID, DEFAULT_HEADER_TRACE_ID);
+    }
+
+    private static String getHeaderOrDefault(final String property, final String fallback)
{
+        final Message message = PhaseInterceptorChain.getCurrentMessage();
+        
+        if (message != null) {
+            final Object header = message.getContextualProperty(property);
+            
+            if (header instanceof String) {
+                final String name = (String)header;
+                if (!StringUtils.isEmpty(name)) {
+                    return name;
+                }
+            }
+        }
+        
+        return fallback;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/b1f19a19/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingCustomHeadersTest.java
----------------------------------------------------------------------
diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingCustomHeadersTest.java
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingCustomHeadersTest.java
index 69fb1a2..0371c9e 100644
--- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingCustomHeadersTest.java
+++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingCustomHeadersTest.java
@@ -29,6 +29,7 @@ import javax.ws.rs.core.Response.Status;
 import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
 
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.client.ClientConfiguration;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
@@ -36,16 +37,18 @@ import org.apache.cxf.systest.jaxrs.tracing.BookStore;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
 import org.apache.cxf.tracing.TracerHeaders;
+import org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider;
 import org.apache.cxf.tracing.htrace.jaxrs.HTraceFeature;
 import org.apache.htrace.HTraceConfiguration;
 import org.apache.htrace.impl.AlwaysSampler;
 import org.apache.htrace.impl.StandardOutSpanReceiver;
-
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.notNullValue;
 
 public class HTraceTracingCustomHeadersTest extends AbstractBusClientServerTestBase {
     public static final String PORT = allocatePort(HTraceTracingCustomHeadersTest.class);
@@ -53,6 +56,8 @@ public class HTraceTracingCustomHeadersTest extends AbstractBusClientServerTestB
     private static final String CUSTOM_HEADER_SPAN_ID = "My-Span-Id";
     private static final String CUSTOM_HEADER_TRACE_ID = "My-Trace-Id";
     
+    private HTraceClientProvider htraceClientProvider;
+    
     @Ignore
     public static class Server extends AbstractBusTestServerBase {
         protected void run() {
@@ -83,8 +88,14 @@ public class HTraceTracingCustomHeadersTest extends AbstractBusClientServerTestB
         createStaticBus();
     }
     
+    @Before
+    public void setUp() {
+        htraceClientProvider = new HTraceClientProvider(
+            new AlwaysSampler(HTraceConfiguration.EMPTY));
+    }
+    
     @Test
-    public void testThatNewInnerSpanIsCreated() {
+    public void testThatNewSpanIsCreated() {
         final Response r = createWebClient("/bookstore/books")
             .header(CUSTOM_HEADER_TRACE_ID, 10L)
             .header(CUSTOM_HEADER_SPAN_ID, 20L)
@@ -94,10 +105,27 @@ public class HTraceTracingCustomHeadersTest extends AbstractBusClientServerTestB
         assertThat((String)r.getHeaders().getFirst(CUSTOM_HEADER_TRACE_ID), equalTo("10"));
         assertThat((String)r.getHeaders().getFirst(CUSTOM_HEADER_SPAN_ID), equalTo("20"));
     }
+    
+    @Test
+    public void testThatNewChildSpanIsCreated() {
+        final Response r = createWebClient("/bookstore/books", htraceClientProvider).get();
+        assertEquals(Status.OK.getStatusCode(), r.getStatus());
+        
+        assertThat((String)r.getHeaders().getFirst(CUSTOM_HEADER_TRACE_ID), notNullValue());
+        assertThat((String)r.getHeaders().getFirst(CUSTOM_HEADER_SPAN_ID), notNullValue());
+    }
 
-    protected WebClient createWebClient(final String url) {
-        return WebClient
-            .create("http://localhost:" + PORT + url)
+    protected WebClient createWebClient(final String url, final Object ... providers) {
+        final WebClient client = WebClient
+            .create("http://localhost:" + PORT + url, Arrays.asList(providers))
             .accept(MediaType.APPLICATION_JSON);
+
+        if (providers.length > 0) {
+            final ClientConfiguration config = WebClient.getConfig(client);
+            config.getRequestContext().put(TracerHeaders.HEADER_SPAN_ID, CUSTOM_HEADER_SPAN_ID);
+            config.getRequestContext().put(TracerHeaders.HEADER_TRACE_ID, CUSTOM_HEADER_TRACE_ID);
+        }
+
+        return client;
     }
 }


Mime
View raw message