From 9e87048ae093fa05972049ff1523614ae85ddd82 Mon Sep 17 00:00:00 2001 From: leekyoungil Date: Wed, 6 Dec 2017 18:27:08 +0900 Subject: [PATCH 1/2] The Client init code be improved. --- ApiServerSample/pom.xml | 2 +- .../illuminati-client-processor/pom.xml | 2 +- .../impl/IlluminatiDataExecutorImpl.java | 32 ++++--- .../impl/IlluminatiTemplateExecutorImpl.java | 16 ++++ .../prossor/init/IlluminatiClientInit.java | 89 +++++++++++-------- .../processor/IlluminatiProcessor.java | 13 +-- 6 files changed, 94 insertions(+), 60 deletions(-) diff --git a/ApiServerSample/pom.xml b/ApiServerSample/pom.xml index 634307dd..88957354 100644 --- a/ApiServerSample/pom.xml +++ b/ApiServerSample/pom.xml @@ -82,7 +82,7 @@ com.leekyoungil.illuminati illuminati-client-processor - 0.9.7 + 0.9.8 compile diff --git a/illuminati-client/illuminati-client-processor/pom.xml b/illuminati-client/illuminati-client-processor/pom.xml index c267fa0f..4ff602d6 100644 --- a/illuminati-client/illuminati-client-processor/pom.xml +++ b/illuminati-client/illuminati-client-processor/pom.xml @@ -6,7 +6,7 @@ com.leekyoungil.illuminati illuminati-client-processor - 0.9.7 + 0.9.8 jar diff --git a/illuminati-client/illuminati-client-processor/src/main/java/com/leekyoungil/illuminati/client/prossor/executor/impl/IlluminatiDataExecutorImpl.java b/illuminati-client/illuminati-client-processor/src/main/java/com/leekyoungil/illuminati/client/prossor/executor/impl/IlluminatiDataExecutorImpl.java index 7eac9c68..fedfefcb 100644 --- a/illuminati-client/illuminati-client-processor/src/main/java/com/leekyoungil/illuminati/client/prossor/executor/impl/IlluminatiDataExecutorImpl.java +++ b/illuminati-client/illuminati-client-processor/src/main/java/com/leekyoungil/illuminati/client/prossor/executor/impl/IlluminatiDataExecutorImpl.java @@ -23,8 +23,10 @@ public class IlluminatiDataExecutorImpl implements IlluminatiExecutor ILLUMINATI_TEMPLATE_EXECUTOR = new IlluminatiTemplateExecutorImpl(); + private static IlluminatiExecutor ILLUMINATI_TEMPLATE_EXECUTOR = IlluminatiTemplateExecutorImpl.getInstance(); // ################################################################################################################ // ### init illuminati basic system variables ### // ################################################################################################################ - private static String PARENT_MODULE_NAME; - private static ServerInfo SERVER_INFO; - private static Map JVM_INFO; + private final static String PARENT_MODULE_NAME = IlluminatiPropertiesHelper.getPropertiesValueByKey(IlluminatiPropertiesImpl.class, null, "illuminati", "parentModuleName"); + private final static ServerInfo SERVER_INFO = new ServerInfo(true);; + // get basic JVM setting info only once. + private final static Map JVM_INFO = SystemUtil.getJvmInfo();; + + private IlluminatiDataExecutorImpl () { } + + public static IlluminatiDataExecutorImpl getInstance () { + if (ILLUMINATI_DATA_EXECUTOR_IMPL == null) { + synchronized (IlluminatiDataExecutorImpl.class) { + if (ILLUMINATI_DATA_EXECUTOR_IMPL == null) { + ILLUMINATI_DATA_EXECUTOR_IMPL = new IlluminatiDataExecutorImpl(); + } + } + } + + return ILLUMINATI_DATA_EXECUTOR_IMPL; + } @Override public synchronized void init () { ILLUMINATI_TEMPLATE_EXECUTOR.init(); - PARENT_MODULE_NAME = IlluminatiPropertiesHelper.getPropertiesValueByKey(IlluminatiPropertiesImpl.class, null, "illuminati", "parentModuleName"); - SERVER_INFO = new ServerInfo(true); - // get basic JVM setting info only once. - JVM_INFO = SystemUtil.getJvmInfo(); - // create illuminati template queue thread for send to the IlluminatiDataInterfaceModel. this.createSystemThread(); // if you set debug is true diff --git a/illuminati-client/illuminati-client-processor/src/main/java/com/leekyoungil/illuminati/client/prossor/executor/impl/IlluminatiTemplateExecutorImpl.java b/illuminati-client/illuminati-client-processor/src/main/java/com/leekyoungil/illuminati/client/prossor/executor/impl/IlluminatiTemplateExecutorImpl.java index 8e800a7e..be85ef30 100644 --- a/illuminati-client/illuminati-client-processor/src/main/java/com/leekyoungil/illuminati/client/prossor/executor/impl/IlluminatiTemplateExecutorImpl.java +++ b/illuminati-client/illuminati-client-processor/src/main/java/com/leekyoungil/illuminati/client/prossor/executor/impl/IlluminatiTemplateExecutorImpl.java @@ -23,6 +23,8 @@ public class IlluminatiTemplateExecutorImpl implements IlluminatiExecutor ILLUMINATI_DATA_EXECUTOR = new IlluminatiDataExecutorImpl(); + private static final IlluminatiExecutor ILLUMINATI_DATA_EXECUTOR = IlluminatiDataExecutorImpl.getInstance(); - public synchronized static void init () { + static { IlluminatiCommon.init(); ILLUMINATI_DATA_EXECUTOR.init(); @@ -41,11 +43,25 @@ public synchronized static void init () { SAMPLING_RATE = StringObjectUtils.isValid(samplingRate) ? Integer.valueOf(samplingRate) : SAMPLING_RATE; } + private IlluminatiClientInit () {} + + public static IlluminatiClientInit getInstance () { + if (ILLUMINATI_CLIENT_INIT_INSTANCE == null) { + synchronized (IlluminatiClientInit.class) { + if (ILLUMINATI_CLIENT_INIT_INSTANCE == null) { + ILLUMINATI_CLIENT_INIT_INSTANCE = new IlluminatiClientInit(); + } + } + } + + return ILLUMINATI_CLIENT_INIT_INSTANCE; + } + // ################################################################################################################ // ### public methods ### // ################################################################################################################ - public static boolean checkIlluminatiIsIgnore (final ProceedingJoinPoint pjp) throws Throwable { + public boolean checkIlluminatiIsIgnore (final ProceedingJoinPoint pjp) throws Throwable { try { final MethodSignature signature = (MethodSignature) pjp.getSignature(); final Method method = signature.getMethod(); @@ -67,34 +83,17 @@ public static boolean checkIlluminatiIsIgnore (final ProceedingJoinPoint pjp) th } } - public static Object executeIlluminati (final ProceedingJoinPoint pjp, final HttpServletRequest request) throws Throwable { - if (IlluminatiConstant.ILLUMINATI_SWITCH_ACTIVATION == true && IlluminatiConstant.ILLUMINATI_SWITCH_VALUE.get() == false) { - ILLUMINATI_INIT_LOGGER.debug("iilluminati processor is now off."); + public Object executeIlluminati (final ProceedingJoinPoint pjp, final HttpServletRequest request) throws Throwable { + if (this.isOnIlluminatiSwitch() == false) { return pjp.proceed(); } - if (IlluminatiTemplateExecutorImpl.illuminatiTemplateIsActive() == false || !IlluminatiClientInit.checkSamplingRate()) { + if (IlluminatiTemplateExecutorImpl.illuminatiTemplateIsActive() == false || !this.checkSamplingRate()) { ILLUMINATI_INIT_LOGGER.debug("ignore illuminati processor."); return pjp.proceed(); } - final long start = System.currentTimeMillis(); - final Map originMethodExecute = getMethodExecuteResult(pjp); - final long elapsedTime = System.currentTimeMillis() - start; - - final Object output = originMethodExecute.get("result"); - Throwable throwable = null; - if (originMethodExecute.containsKey("throwable")) { - throwable = (Throwable) originMethodExecute.get("throwable"); - } - - ILLUMINATI_DATA_EXECUTOR.addToQueue(new IlluminatiDataInterfaceModel(request, (MethodSignature) pjp.getSignature(), pjp.getArgs(), elapsedTime, output)); - - if (throwable != null) { - throw throwable; - } - - return output; + return addToQueue(pjp, request, false); } /** @@ -106,21 +105,37 @@ public static Object executeIlluminati (final ProceedingJoinPoint pjp, final Htt * @return * @throws Throwable */ - public static Object executeIlluminatiByChaosBomber (final ProceedingJoinPoint pjp, final HttpServletRequest request) throws Throwable { - if (IlluminatiConstant.ILLUMINATI_SWITCH_VALUE.get() == false) { - ILLUMINATI_INIT_LOGGER.debug("illuminati processor is now off."); + public Object executeIlluminatiByChaosBomber (final ProceedingJoinPoint pjp, final HttpServletRequest request) throws Throwable { + if (this.isOnIlluminatiSwitch() == false) { + return pjp.proceed(); + } + + if (IlluminatiTemplateExecutorImpl.illuminatiTemplateIsActive() == false) { + ILLUMINATI_INIT_LOGGER.debug("ignore illuminati processor and the ChaosBomber mode is not effect of sampling rate."); return pjp.proceed(); } if (IlluminatiConstant.ILLUMINATI_DEBUG == false) { - return IlluminatiClientInit.executeIlluminati(pjp, request); + return addToQueue(pjp, request, false); } - if (IlluminatiTemplateExecutorImpl.illuminatiTemplateIsActive() == false) { - ILLUMINATI_INIT_LOGGER.debug("ignore illuminati processor."); - return pjp.proceed(); + return addToQueue(pjp, request, true); + } + + // ################################################################################################################ + // ### private methods ### + // ################################################################################################################ + + private boolean isOnIlluminatiSwitch () { + if (IlluminatiConstant.ILLUMINATI_SWITCH_ACTIVATION == true && IlluminatiConstant.ILLUMINATI_SWITCH_VALUE.get() == false) { + ILLUMINATI_INIT_LOGGER.debug("illuminati processor is now off."); + return false; } + return true; + } + + private Object addToQueue (final ProceedingJoinPoint pjp, final HttpServletRequest request, final boolean isActiveChaosBomber) throws Throwable { final long start = System.currentTimeMillis(); final Map originMethodExecute = getMethodExecuteResult(pjp); final long elapsedTime = System.currentTimeMillis() - start; @@ -129,7 +144,9 @@ public static Object executeIlluminatiByChaosBomber (final ProceedingJoinPoint p Throwable throwable = null; if (originMethodExecute.containsKey("throwable")) { throwable = (Throwable) originMethodExecute.get("throwable"); - } else if (CHAOSBOMBER_NUMBER == ((int) (Math.random() * 100) + 1)) { + } + + if (isActiveChaosBomber == true && throwable == null && CHAOSBOMBER_NUMBER == ((int) (Math.random() * 100) + 1)) { throwable = new Throwable("Illuminati ChaosBomber Exception Activate"); request.setAttribute("ChaosBomber", "true"); } @@ -143,11 +160,7 @@ public static Object executeIlluminatiByChaosBomber (final ProceedingJoinPoint p return output; } - // ################################################################################################################ - // ### private methods ### - // ################################################################################################################ - - private static boolean checkSamplingRate () { + private boolean checkSamplingRate () { //SAMPLING_RATE_CHECKER.compareAndSet(100, 1); // sometimes compareAndSet does not work. @@ -164,7 +177,7 @@ private static boolean checkSamplingRate () { return false; } - private static Map getMethodExecuteResult (final ProceedingJoinPoint pjp) { + private Map getMethodExecuteResult (final ProceedingJoinPoint pjp) { final Map originMethodExecute = new HashMap(); try { diff --git a/illuminati-client/illuminati-client-processor/src/main/java/com/leekyoungil/illuminati/client/prossor/processor/IlluminatiProcessor.java b/illuminati-client/illuminati-client-processor/src/main/java/com/leekyoungil/illuminati/client/prossor/processor/IlluminatiProcessor.java index 58e4e7ab..2235ace8 100644 --- a/illuminati-client/illuminati-client-processor/src/main/java/com/leekyoungil/illuminati/client/prossor/processor/IlluminatiProcessor.java +++ b/illuminati-client/illuminati-client-processor/src/main/java/com/leekyoungil/illuminati/client/prossor/processor/IlluminatiProcessor.java @@ -124,14 +124,7 @@ private boolean setGeneratedIlluminatiTemplate (final String basePackageName) { //BrokerType brokerType = BrokerType.getEnumType(illuminatiProperties.getBroker()); - final String staticConfigurationTemplate = "" - + " static {\r\n" - + " try {\r\n" - + " IlluminatiClientInit.init();\r\n" - + " } catch (Exception ex) {\r\n" - + " // ignore\r\n" - + " }\r\n" - + " }\r\n"; + final String staticConfigurationTemplate = " private final IlluminatiClientInit illuminatiClientInit = IlluminatiClientInit.getInstance();\r\n"; // step 3. properties by broker String implClassName; @@ -163,7 +156,7 @@ private boolean setGeneratedIlluminatiTemplate (final String basePackageName) { + " @Around(\"illuminatiPointcutMethod()\")\r\n" + " public Object profile (ProceedingJoinPoint pjp) throws Throwable {\r\n" - + " if (IlluminatiClientInit.checkIlluminatiIsIgnore(pjp) == true) {\r\n" + + " if (illuminatiClientInit.checkIlluminatiIsIgnore(pjp) == true) {\r\n" + " return pjp.proceed();\r\n" + " }\r\n" + " HttpServletRequest request = null;\r\n" @@ -172,7 +165,7 @@ private boolean setGeneratedIlluminatiTemplate (final String basePackageName) { + " } catch (Exception ex) {\r\n" + " //ignore this exception.\r\n" + " }\r\n" - + " return IlluminatiClientInit.executeIlluminati"+illuminatiExecuteMethod+"(pjp, request);\r\n" + + " return illuminatiClientInit.executeIlluminati"+illuminatiExecuteMethod+"(pjp, request);\r\n" + " }\r\n" + "}\r\n" ; From 727003b96480ef58006e3ded97d68536f503d78d Mon Sep 17 00:00:00 2001 From: leekyoungil Date: Wed, 6 Dec 2017 19:00:36 +0900 Subject: [PATCH 2/2] Readme version up --- .../illuminati-client-annotation/README.md | 8 ++++---- .../illuminati-client-elasticsearch/README.md | 8 ++++---- .../illuminati-client-elasticsearch/pom.xml | 4 ++-- .../illuminati-client-processor/README.md | 10 +++++----- illuminati-consumer-es-sample/README.md | 8 ++++---- illuminati-consumer-es-sample/pom.xml | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/illuminati-client/illuminati-client-annotation/README.md b/illuminati-client/illuminati-client-annotation/README.md index d235465f..3e39535b 100644 --- a/illuminati-client/illuminati-client-annotation/README.md +++ b/illuminati-client/illuminati-client-annotation/README.md @@ -20,7 +20,7 @@ com.leekyoungil.illuminati illuminati-client-processor - 0.9.7 + 0.9.8 ``` @@ -29,7 +29,7 @@ ```java compile 'com.leekyoungil.illuminati:illuminati-client-annotation:1.1.1' -compile 'com.leekyoungil.illuminati:illuminati-client-processor:0.9.7' +compile 'com.leekyoungil.illuminati:illuminati-client-processor:0.9.8' ``` ## add @Illuminati to Class @@ -121,7 +121,7 @@ public class ApiSampleController { com.leekyoungil.illuminati illuminati-client-processor - 0.9.7 + 0.9.8 ``` @@ -130,7 +130,7 @@ public class ApiSampleController { ```java compile 'com.leekyoungil.illuminati:illuminati-client-annotation:1.1.1' -compile 'com.leekyoungil.illuminati:illuminati-client-processor:0.9.7' +compile 'com.leekyoungil.illuminati:illuminati-client-processor:0.9.8' ``` diff --git a/illuminati-client/illuminati-client-elasticsearch/README.md b/illuminati-client/illuminati-client-elasticsearch/README.md index 4c0897e1..1855d6cd 100644 --- a/illuminati-client/illuminati-client-elasticsearch/README.md +++ b/illuminati-client/illuminati-client-elasticsearch/README.md @@ -14,7 +14,7 @@ com.leekyoungil.illuminati illuminati-client-elasticsearch - 0.7.7 + 0.7.8 ``` @@ -22,7 +22,7 @@ * Gradle ```java -compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.7' +compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.8' ``` =============================================================================== @@ -42,7 +42,7 @@ compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.7' com.leekyoungil.illuminati illuminati-client-elasticsearch - 0.7.7 + 0.7.8 ``` @@ -50,5 +50,5 @@ compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.7' * Gradle ```java -compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.7' +compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.8' ``` diff --git a/illuminati-client/illuminati-client-elasticsearch/pom.xml b/illuminati-client/illuminati-client-elasticsearch/pom.xml index b4f9e082..3db140ed 100644 --- a/illuminati-client/illuminati-client-elasticsearch/pom.xml +++ b/illuminati-client/illuminati-client-elasticsearch/pom.xml @@ -6,7 +6,7 @@ com.leekyoungil.illuminati illuminati-client-elasticsearch - 0.7.7 + 0.7.8 jar @@ -20,7 +20,7 @@ com.leekyoungil.illuminati illuminati-client-processor - 0.9.7 + 0.9.8 compile diff --git a/illuminati-client/illuminati-client-processor/README.md b/illuminati-client/illuminati-client-processor/README.md index ffe5fd9d..0596dcba 100644 --- a/illuminati-client/illuminati-client-processor/README.md +++ b/illuminati-client/illuminati-client-processor/README.md @@ -6,7 +6,7 @@ * RabbitMQ - completed test of heavy traffic * Kafka - not yet complete -## I recommend the RabbitMQ for the current version.(0.8.3) +## I recommend the RabbitMQ for the current version.(0.9.8) ## add to Maven Dependency * Maven @@ -29,7 +29,7 @@ com.leekyoungil.illuminati illuminati-client-processor - 0.9.7 + 0.9.8 @@ -50,7 +50,7 @@ repositories { } compile 'com.leekyoungil.illuminati:illuminati-client-annotation:1.1.1' -compile 'com.leekyoungil.illuminati:illuminati-client-processor:0.9.7' +compile 'com.leekyoungil.illuminati:illuminati-client-processor:0.9.8' // This is an option. If you add the module, you can turn it on and off without deploying it. compile 'com.leekyoungil.illuminati:illuminati-client-switch:1.0.2' ``` @@ -190,7 +190,7 @@ chaosBomber: true com.leekyoungil.illuminati illuminati-client-processor - 0.9.7 + 0.9.8 @@ -212,7 +212,7 @@ repositories { compile 'com.leekyoungil.illuminati:illuminati-client-annotation:1.1.1' //이것은 옵션 입니다. 해당 모듈을 추가하면 대시 배포 없이 on, off할수 있습니다. -compile 'com.leekyoungil.illuminati:illuminati-client-processor:0.9.7' +compile 'com.leekyoungil.illuminati:illuminati-client-processor:0.9.8' ``` ## Class에 @Illuminati 추가 diff --git a/illuminati-consumer-es-sample/README.md b/illuminati-consumer-es-sample/README.md index b6d475af..60cb97ea 100644 --- a/illuminati-consumer-es-sample/README.md +++ b/illuminati-consumer-es-sample/README.md @@ -15,7 +15,7 @@ com.leekyoungil.illuminati illuminati-client-elasticsearch - 0.7.7 + 0.7.8 ``` @@ -23,7 +23,7 @@ * Gradle ```java -compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.7' +compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.8' ``` @@ -45,7 +45,7 @@ compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.7' com.leekyoungil.illuminati illuminati-client-elasticsearch - 0.7.7 + 0.7.8 ``` @@ -53,5 +53,5 @@ compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.7' * Gradle ```java -compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.7' +compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.8' ``` diff --git a/illuminati-consumer-es-sample/pom.xml b/illuminati-consumer-es-sample/pom.xml index c0a6d267..b4011700 100644 --- a/illuminati-consumer-es-sample/pom.xml +++ b/illuminati-consumer-es-sample/pom.xml @@ -77,7 +77,7 @@ com.leekyoungil.illuminati illuminati-client-elasticsearch - 0.7.7 + 0.7.8 compile