diff --git a/README.md b/README.md index f94f6a4..2857249 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,15 @@ x-xss-protection: 1; mode=block ] ``` +# Performance + +``` +Benchmark Mode Cnt Score Error Units +NormalizedFeignLoggerBenchmarkTest.testFeignWithoutLogger thrpt 25 16281.625 ± 279.774 ops/s +NormalizedFeignLoggerBenchmarkTest.testNormalizedFeignLogger thrpt 25 6081.675 ± 229.912 ops/s +NormalizedFeignLoggerBenchmarkTest.testSlf4jFeignLogger thrpt 25 16593.059 ± 151.327 ops/s +``` + # How to use In order to use Normalized Logger into the application they must the following. @@ -99,7 +108,7 @@ for Maven me.bvn13.openfeign.logger feign-normalized-logger - 0.1.4 + 0.2.1 ``` diff --git a/logger-testing/pom.xml b/logger-testing/pom.xml new file mode 100644 index 0000000..7315d0e --- /dev/null +++ b/logger-testing/pom.xml @@ -0,0 +1,97 @@ + + + + me.bvn13.openfeign.logger + feign-normalized-logger + 0.2.1-SNAPSHOT + + 4.0.0 + + me.bvn13.openfeign.logger.test + logger-testing + + + 17 + 17 + UTF-8 + + + + + me.bvn13.openfeign.logger + feign-normalized-logger + 0.2.1-SNAPSHOT + test + + + org.slf4j + slf4j-api + ${slf4j.version} + test + + + org.slf4j + slf4j-jdk14 + ${slf4j.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + org.eclipse.jetty + jetty-server + ${jetty-server.version} + test + + + org.eclipse.jetty + jetty-servlet + ${jetty-server.version} + test + + + org.openjdk.jmh + jmh-core + ${jmh.version} + test + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + test + + + io.github.openfeign + feign-core + ${feign.version} + test + + + io.github.openfeign + feign-gson + ${feign.version} + test + + + io.github.openfeign + feign-slf4j + ${feign.version} + test + + + me.bvn13.openfeign.logger + logger + 0.2.1-SNAPSHOT + test + + + + \ No newline at end of file diff --git a/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLoggerBenchmarkTest.java b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLoggerBenchmarkTest.java new file mode 100644 index 0000000..783dafd --- /dev/null +++ b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLoggerBenchmarkTest.java @@ -0,0 +1,107 @@ +package me.bvn13.openfeign.logger.normalized; + +import feign.Feign; +import feign.Logger; +import feign.gson.GsonDecoder; +import feign.slf4j.Slf4jLogger; +import org.junit.jupiter.api.Assertions; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; +import org.openjdk.jmh.annotations.Warmup; + +import static me.bvn13.openfeign.logger.normalized.TestJettyServer.PORT; + +public class NormalizedFeignLoggerBenchmarkTest { + @State(Scope.Benchmark) + public static class BenchmarkStateWithoutLogging { + TestJettyServer jettyServer; + TestFeignClient feignClient; + + @Setup + public void init() { + jettyServer = new TestJettyServer(); + jettyServer.start(); + feignClient = Feign.builder() + .decoder(new GsonDecoder()) + .target(TestFeignClient.class, "http://localhost:" + PORT); + } + + @TearDown + public void tearDown() { + jettyServer.stop(); + } + } + + @State(Scope.Benchmark) + public static class BenchmarkStateWithSlf4jLogging { + TestJettyServer jettyServer; + TestFeignClient feignClient; + + @Setup + public void init() { + jettyServer = new TestJettyServer(); + jettyServer.start(); + feignClient = Feign.builder() + .logger(new Slf4jLogger()) + .logLevel(Logger.Level.FULL) + .decoder(new GsonDecoder()) + .target(TestFeignClient.class, "http://localhost:" + PORT); + } + + @TearDown + public void tearDown() { + jettyServer.stop(); + } + } + + @State(Scope.Benchmark) + public static class BenchmarkStateWithNormalizedLogging { + TestJettyServer jettyServer; + TestFeignClient feignClient; + + @Setup + public void init() { + jettyServer = new TestJettyServer(); + jettyServer.start(); + feignClient = Feign.builder() + .logger(new NormalizedFeignLogger()) + .logLevel(Logger.Level.FULL) + .decoder(new GsonDecoder()) + .target(TestFeignClient.class, "http://localhost:" + PORT); + } + + @TearDown + public void tearDown() { + jettyServer.stop(); + } + } + + @Benchmark + @Warmup(iterations = 3) + public void testFeignLogger(BenchmarkStateWithoutLogging benchmarkState) { + final ResponseDto status = benchmarkState.feignClient.getStatus(); + Assertions.assertEquals("ok", status.getStatus()); + } + + @Benchmark + @Warmup(iterations = 3) + public void testSlf4jFeignLogger(BenchmarkStateWithSlf4jLogging benchmarkState) { + final ResponseDto status = benchmarkState.feignClient.getStatus(); + Assertions.assertEquals("ok", status.getStatus()); + } + + @Benchmark + @Warmup(iterations = 3) + public void testNormalizedFeignLogger(BenchmarkStateWithNormalizedLogging benchmarkState) { + final ResponseDto status = benchmarkState.feignClient.getStatus(); + Assertions.assertEquals("ok", status.getStatus()); + } + + public static void main(String[] args) throws Exception { + org.openjdk.jmh.Main.main(args); + } + +} diff --git a/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/ResponseDto.java b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/ResponseDto.java new file mode 100644 index 0000000..0306821 --- /dev/null +++ b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/ResponseDto.java @@ -0,0 +1,15 @@ +package me.bvn13.openfeign.logger.normalized; + +public class ResponseDto { + + private String status; + + public String getStatus() { + return status; + } + + public ResponseDto setStatus(String status) { + this.status = status; + return this; + } +} diff --git a/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestBlockingServlet.java b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestBlockingServlet.java new file mode 100644 index 0000000..bf111f3 --- /dev/null +++ b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestBlockingServlet.java @@ -0,0 +1,19 @@ +package me.bvn13.openfeign.logger.normalized; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; + +public class TestBlockingServlet extends HttpServlet { + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + response.setContentType("application/json"); + response.setStatus(HttpServletResponse.SC_OK); + response.getWriter().println("{ \"status\": \"ok\"}"); + } + +} diff --git a/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestFeignClient.java b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestFeignClient.java new file mode 100644 index 0000000..7e4088d --- /dev/null +++ b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestFeignClient.java @@ -0,0 +1,11 @@ +package me.bvn13.openfeign.logger.normalized; + + +import feign.RequestLine; + +public interface TestFeignClient { + + @RequestLine("GET /status") + ResponseDto getStatus(); + +} diff --git a/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestJettyServer.java b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestJettyServer.java new file mode 100644 index 0000000..985bc82 --- /dev/null +++ b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestJettyServer.java @@ -0,0 +1,51 @@ +package me.bvn13.openfeign.logger.normalized; + +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.servlet.ServletHandler; + +public class TestJettyServer { + + public static final int PORT = 8090; + private Server server; + + public TestJettyServer() { + server = new Server(); + ServerConnector connector = new ServerConnector(server); + connector.setPort(PORT); + server.setConnectors(new Connector[] {connector}); + } + + public void start() { + ServletHandler servletHandler = new ServletHandler(); + server.setHandler(servletHandler); + servletHandler.addServletWithMapping(TestBlockingServlet.class, "/status"); + new Thread(() -> { + try { + server.start(); + } catch (Exception e) { + throw new RuntimeException(e); + } + }).start(); + } + + public void stop() { + try { + server.stop(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static void main(String[] args) { + TestJettyServer jettyServer; + jettyServer = new TestJettyServer(); + try { + jettyServer.start(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + +} diff --git a/logger/pom.xml b/logger/pom.xml new file mode 100644 index 0000000..ee53cd9 --- /dev/null +++ b/logger/pom.xml @@ -0,0 +1,35 @@ + + + + me.bvn13.openfeign.logger + feign-normalized-logger + 0.2.1-SNAPSHOT + + 4.0.0 + + logger + + + 1.8 + 1.8 + UTF-8 + + + + + io.github.openfeign + feign-core + ${feign.version} + provided + + + org.slf4j + slf4j-api + ${slf4j.version} + provided + + + + \ No newline at end of file diff --git a/src/main/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLogger.java b/logger/src/main/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLogger.java similarity index 92% rename from src/main/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLogger.java rename to logger/src/main/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLogger.java index 3fc388f..ea32315 100644 --- a/src/main/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLogger.java +++ b/logger/src/main/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLogger.java @@ -6,6 +6,7 @@ import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -18,7 +19,7 @@ *
  * {@code
  *
- * normalized feign request (HERE-IS-CLASS-AND-METHOD): [
+ * Normalized feign request (HERE-ARE-CLASS-AND-METHOD): [
  *
  * ] has response [
  *
@@ -69,16 +70,16 @@ protected void log(String configKey, String format, Object... args) {
 
     private void init() {
         if (isResponse.get() == null) {
-            isResponse.set(new ConcurrentHashMap<>());
+            isResponse.set(new HashMap<>());
         }
         if (methodName.get() == null) {
-            methodName.set(new ConcurrentHashMap<>());
+            methodName.set(new HashMap<>());
         }
         if (logsRequest.get() == null) {
-            logsRequest.set(new ConcurrentHashMap<>());
+            logsRequest.set(new HashMap<>());
         }
         if (logsResponse.get() == null) {
-            logsResponse.set(new ConcurrentHashMap<>());
+            logsResponse.set(new HashMap<>());
         }
     }
 
diff --git a/pom.xml b/pom.xml
index 54bcb27..20cf963 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,9 +7,14 @@
 
     me.bvn13.openfeign.logger
     feign-normalized-logger
-    0.1.5-SNAPSHOT
+    0.2.1-SNAPSHOT
 
-    jar
+    
+        logger
+        logger-testing
+    
+
+    pom
 
     OpenFeign Normalized Logger
     Normalized Logger for OpenFeign
@@ -42,8 +47,32 @@
         1.6.13
         1.6
         1.18.0
+
+        
+        5.9.0
+        11.0.11
+        1.35
+        4.5.13
     
 
+    
+        
+            bvn13
+            Vyacheslav Boyko
+            dev@bvn13.me
+            
+                Developer
+            
+        
+    
+
+    
+        scm:git:git://github.com/bvn13/OpenFeign-NormalizedLogger.git
+        scm:git:ssh://git@github.com:bvn13/OpenFeign-NormalizedLogger.git
+        HEAD
+        https://github.com/bvn13/OpenFeign-NormalizedLogger.git
+    
+
 
     
         
@@ -53,28 +82,6 @@
         
     
 
-    
-        
-            io.github.openfeign
-            feign-core
-            ${feign.version}
-            provided
-        
-        
-            org.slf4j
-            slf4j-api
-            ${slf4j.version}
-            provided
-        
-
-        
-            junit
-            junit
-            4.12
-            test
-        
-    
-
     
         feign-normalized-logger
 
@@ -112,24 +119,6 @@
         
     
 
-    
-        
-            bvn13
-            Vyacheslav Boyko
-            dev@bvn13.me
-            
-                Developer
-            
-        
-    
-
-    
-        scm:git:git://github.com/bvn13/OpenFeign-NormalizedLogger.git
-        scm:git:ssh://git@github.com:bvn13/OpenFeign-NormalizedLogger.git
-        HEAD
-        https://github.com/bvn13/OpenFeign-NormalizedLogger.git
-    
-
     
         
             release
diff --git a/publish.sh b/publish.sh
index 6c40cd8..34d0a5f 100755
--- a/publish.sh
+++ b/publish.sh
@@ -8,6 +8,8 @@ git push --tags
 
 git push origin develop
 
+git checkout master
+
 read -p "Which version to publish? > " version
 
 git checkout $version