From f1c1a6b3685d0380968631b43d2cef9dd1b2d171 Mon Sep 17 00:00:00 2001 From: leekyoungil Date: Tue, 17 Dec 2019 16:19:15 +0900 Subject: [PATCH] add collec controller feature by profile - add ignore profile to the Illuminati annotation - add profile keyword too --- ApiServerSample/pom.xml | 4 +- .../service/ApiSampleService.java | 2 +- README.md | 12 ++--- illuminati/illuminati-annotation/README.md | 24 ++++++++-- illuminati/illuminati-annotation/pom.xml | 2 +- .../illuminati/annotation/Illuminati.java | 10 ++-- illuminati/illuminati-processor/README.md | 8 ++-- illuminati/illuminati-processor/pom.xml | 4 +- .../processor/init/IlluminatiClientInit.java | 47 +++++++++++++++---- 9 files changed, 80 insertions(+), 33 deletions(-) diff --git a/ApiServerSample/pom.xml b/ApiServerSample/pom.xml index 18b7874a..2fa1a647 100644 --- a/ApiServerSample/pom.xml +++ b/ApiServerSample/pom.xml @@ -54,7 +54,7 @@ me.phoboslabs.illuminati illuminati-annotation - 1.2.1 + 1.2.2 compile @@ -68,7 +68,7 @@ me.phoboslabs.illuminati illuminati-processor - 0.9.9.28 + 0.9.9.29 compile diff --git a/ApiServerSample/src/main/java/me/phoboslabs/illuminati/ApiServerSample/service/ApiSampleService.java b/ApiServerSample/src/main/java/me/phoboslabs/illuminati/ApiServerSample/service/ApiSampleService.java index 05965185..f4f6b537 100644 --- a/ApiServerSample/src/main/java/me/phoboslabs/illuminati/ApiServerSample/service/ApiSampleService.java +++ b/ApiServerSample/src/main/java/me/phoboslabs/illuminati/ApiServerSample/service/ApiSampleService.java @@ -18,7 +18,7 @@ public String sampleTest () { return "illuminati Cool"; } - @Illuminati(packageType = PackageType.SERVICE) + @Illuminati(packageType = PackageType.SERVICE, ignoreProfile = {"local"}) public String sampleTestByObject (TestModel testModel) { this.sampleTestByObject1(null); apiSampleService1.sampleTestByObject1(null); diff --git a/README.md b/README.md index 4432bd57..2a425645 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,9 @@ The illuminati is desinged to make collect all data easily and it can be possibl ## struct of illuminati Project - library - * [illuminati-annotation:1.2.1](https://github.com/LeeKyoungIl/illuminati/tree/master/illuminati/illuminati-annotation) + * [illuminati-annotation:1.2.2](https://github.com/LeeKyoungIl/illuminati/tree/master/illuminati/illuminati-annotation) * [illuminati-common:1.4.5](https://github.com/LeeKyoungIl/illuminati/tree/master/illuminati/illuminati-common) - * [illuminati-processor:0.9.9.28](https://github.com/LeeKyoungIl/illuminati/tree/master/illuminati/illuminati-processor) + * [illuminati-processor:0.9.9.29](https://github.com/LeeKyoungIl/illuminati/tree/master/illuminati/illuminati-processor) * [illuminati-switch:1.0.14](https://github.com/LeeKyoungIl/illuminati/tree/master/illuminati/illuminati-switch) * [illuminati-jscollector:0.5.15](https://github.com/LeeKyoungIl/illuminati/tree/master/illuminati/illuminati-jscollector) * [illuminati-elasticsearch:0.8.8](https://github.com/LeeKyoungIl/illuminati/tree/master/illuminati/illuminati-elasticsearch) @@ -90,13 +90,13 @@ The illuminati is desinged to make collect all data easily and it can be possibl me.phoboslabs.illuminati illuminati-annotation - 1.2.1 + 1.2.2 me.phoboslabs.illuminati illuminati-processor - 0.9.9.28 + 0.9.9.29 @@ -123,8 +123,8 @@ repositories { jcenter() } -compile 'me.phoboslabs.illuminati:illuminati-annotation:1.2.1' -compile 'me.phoboslabs.illuminati:illuminati-processor:0.9.9.28' +compile 'me.phoboslabs.illuminati:illuminati-annotation:1.2.2' +compile 'me.phoboslabs.illuminati:illuminati-processor:0.9.9.29' // This is an option. If you add the module, you can turn it on and off without deploying it. compile 'me.phoboslabs.illuminati:illuminati-switch:1.0.14' diff --git a/illuminati/illuminati-annotation/README.md b/illuminati/illuminati-annotation/README.md index 9b125774..e54378bd 100644 --- a/illuminati/illuminati-annotation/README.md +++ b/illuminati/illuminati-annotation/README.md @@ -14,13 +14,13 @@ me.phoboslabs.illuminati illuminati-annotation - 1.2.1 + 1.2.2 me.phoboslabs.illuminati illuminati-processor - 0.9.9.28 + 0.9.9.29 ``` @@ -28,8 +28,8 @@ * Gradle ```java -compile 'me.phoboslabs.illuminati:illuminati-annotation:1.2.1' -compile 'me.phoboslabs.illuminati:illuminati-processor:0.9.9.28' +compile 'me.phoboslabs.illuminati:illuminati-annotation:1.2.2' +compile 'me.phoboslabs.illuminati:illuminati-processor:0.9.9.29' ``` ## add @Illuminati to Class @@ -55,6 +55,8 @@ public class ApiSampleController { } ``` * apply to all sub methods, but if you want to exclude some method. + * you can select exclude by the Profiles. Basic Value is the value of the "spring.profiles.active". You can change the key by profileKeyword option. + ```java @Illuminati @RestController @@ -73,6 +75,20 @@ public class ApiSampleController { String testJson = "{\"test\" : 2}"; return testJson; } + + @Illuminati(ignoreProfile = {"local", "test"}) + @RequestMapping(value = "test2") + public String test3 (String a, Integer b) throws Exception { + String testJson = "{\"test\" : 3}"; + return testJson; + } + + @Illuminati(ignoreProfile = {"local", "test"}, profileKeyword = "another.profiles") + @RequestMapping(value = "test2") + public String test4 (String a, Integer b) throws Exception { + String testJson = "{\"test\" : 4}"; + return testJson; + } } ``` diff --git a/illuminati/illuminati-annotation/pom.xml b/illuminati/illuminati-annotation/pom.xml index e32e187d..3ce904d4 100644 --- a/illuminati/illuminati-annotation/pom.xml +++ b/illuminati/illuminati-annotation/pom.xml @@ -6,7 +6,7 @@ me.phoboslabs.illuminati illuminati-annotation - 1.2.1 + 1.2.2 jar diff --git a/illuminati/illuminati-annotation/src/main/java/me/phoboslabs/illuminati/annotation/Illuminati.java b/illuminati/illuminati-annotation/src/main/java/me/phoboslabs/illuminati/annotation/Illuminati.java index 922be7af..4442c797 100644 --- a/illuminati/illuminati-annotation/src/main/java/me/phoboslabs/illuminati/annotation/Illuminati.java +++ b/illuminati/illuminati-annotation/src/main/java/me/phoboslabs/illuminati/annotation/Illuminati.java @@ -14,9 +14,13 @@ @Retention(value = RetentionPolicy.RUNTIME) public @interface Illuminati { - boolean ignore () default false; + boolean ignore() default false; - int samplingRate () default 0; + int samplingRate() default 0; - PackageType packageType () default PackageType.DEFAULT; + PackageType packageType() default PackageType.DEFAULT; + + String[] ignoreProfile() default {}; + + String profileKeyword() default "spring.profiles.active"; } diff --git a/illuminati/illuminati-processor/README.md b/illuminati/illuminati-processor/README.md index 278528a4..0889b267 100644 --- a/illuminati/illuminati-processor/README.md +++ b/illuminati/illuminati-processor/README.md @@ -21,13 +21,13 @@ me.phoboslabs.illuminati illuminati-annotation - 1.2.1 + 1.2.2 me.phoboslabs.illuminati illuminati-processor - 0.9.9.28 + 0.9.9.29 @@ -55,8 +55,8 @@ repositories { jcenter() } -compile 'me.phoboslabs.illuminati:illuminati-annotation:1.2.1' -compile 'me.phoboslabs.illuminati:illuminati-processor:0.9.9.28' +compile 'me.phoboslabs.illuminati:illuminati-annotation:1.2.2' +compile 'me.phoboslabs.illuminati:illuminati-processor:0.9.9.29' // This is an option. If you add the module, you can turn it on and off without deploying it. compile 'me.phoboslabs.illuminati:illuminati-switch:1.0.14' // This is an option. If you add the module, you can back up to H2DB automatically when you have a problem with your broker. diff --git a/illuminati/illuminati-processor/pom.xml b/illuminati/illuminati-processor/pom.xml index 7936e70f..bffe4300 100644 --- a/illuminati/illuminati-processor/pom.xml +++ b/illuminati/illuminati-processor/pom.xml @@ -6,7 +6,7 @@ me.phoboslabs.illuminati illuminati-processor - 0.9.9.28 + 0.9.9.29 jar @@ -43,7 +43,7 @@ me.phoboslabs.illuminati illuminati-annotation - 1.2.1 + [1.2.2, ) compile diff --git a/illuminati/illuminati-processor/src/main/java/me/phoboslabs/illuminati/processor/init/IlluminatiClientInit.java b/illuminati/illuminati-processor/src/main/java/me/phoboslabs/illuminati/processor/init/IlluminatiClientInit.java index ed9ac560..648d3008 100644 --- a/illuminati/illuminati-processor/src/main/java/me/phoboslabs/illuminati/processor/init/IlluminatiClientInit.java +++ b/illuminati/illuminati-processor/src/main/java/me/phoboslabs/illuminati/processor/init/IlluminatiClientInit.java @@ -113,11 +113,7 @@ public boolean checkIlluminatiIsIgnore (final ProceedingJoinPoint pjp) throws Th } public Object executeIlluminati (final ProceedingJoinPoint pjp, final HttpServletRequest request) throws Throwable { - if (IlluminatiGracefulShutdownChecker.getIlluminatiReadyToShutdown()) { - return pjp.proceed(); - } - - if (this.isActivateIlluminatiSwitch() && this.isOnIlluminatiSwitch() == false) { + if (this.checkConditionOfIlluminatiBasicExecution(pjp) == false) { return pjp.proceed(); } @@ -139,11 +135,7 @@ public Object executeIlluminati (final ProceedingJoinPoint pjp, final HttpServle * @throws Throwable */ public Object executeIlluminatiByChaosBomber (final ProceedingJoinPoint pjp, final HttpServletRequest request) throws Throwable { - if (IlluminatiGracefulShutdownChecker.getIlluminatiReadyToShutdown()) { - return pjp.proceed(); - } - - if (this.isOnIlluminatiSwitch() == false) { + if (this.checkConditionOfIlluminatiBasicExecution(pjp) == false) { return pjp.proceed(); } @@ -158,6 +150,41 @@ public Object executeIlluminatiByChaosBomber (final ProceedingJoinPoint pjp, fin // ### private methods ### // ################################################################################################################ + private boolean checkConditionOfIlluminatiBasicExecution(final ProceedingJoinPoint pjp) { + if (IlluminatiGracefulShutdownChecker.getIlluminatiReadyToShutdown()) { + return false; + } + if (this.checkIgnoreProfile(pjp)) { + return false; + } + if (this.isActivateIlluminatiSwitch() && this.isOnIlluminatiSwitch() == false) { + return false; + } + + return true; + } + + private boolean checkIgnoreProfile(final ProceedingJoinPoint pjp) { + boolean checkResult = false; + try { + Illuminati illuminati = this.getIlluminatiAnnotation(pjp); + if (illuminati.ignoreProfile().length == 0) { + return false; + } + + final String activeProfileKeyword = illuminati.profileKeyword(); + final String activatedProfileKeyword = System.getProperty(activeProfileKeyword); + for (String checkKeyword : illuminati.ignoreProfile()) { + if (activatedProfileKeyword.equalsIgnoreCase(checkKeyword)) { + checkResult = true; + break; + } + } + } catch (Exception ignore) {} + + return checkResult; + } + private Illuminati getIlluminatiAnnotation (final ProceedingJoinPoint pjp) { final MethodSignature signature = (MethodSignature) pjp.getSignature(); final Method method = signature.getMethod();