Skip to content

Commit

Permalink
Merge pull request #25 from LeeKyoungIl/feature/refactoring
Browse files Browse the repository at this point in the history
Feature/refactoring
  • Loading branch information
LeeKyoungIl authored Dec 6, 2017
2 parents 2f64e9f + 727003b commit 06d56ac
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 80 deletions.
2 changes: 1 addition & 1 deletion ApiServerSample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<dependency>
<groupId>com.leekyoungil.illuminati</groupId>
<artifactId>illuminati-client-processor</artifactId>
<version>0.9.7</version>
<version>0.9.8</version>
<scope>compile</scope>
</dependency>

Expand Down
8 changes: 4 additions & 4 deletions illuminati-client/illuminati-client-annotation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>com.leekyoungil.illuminati</groupId>
<artifactId>illuminati-client-processor</artifactId>
<version>0.9.7</version>
<version>0.9.8</version>
</dependency>
```

Expand All @@ -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
Expand Down Expand Up @@ -121,7 +121,7 @@ public class ApiSampleController {
<dependency>
<groupId>com.leekyoungil.illuminati</groupId>
<artifactId>illuminati-client-processor</artifactId>
<version>0.9.7</version>
<version>0.9.8</version>
</dependency>
```

Expand All @@ -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'
```


Expand Down
8 changes: 4 additions & 4 deletions illuminati-client/illuminati-client-elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
<dependency>
<groupId>com.leekyoungil.illuminati</groupId>
<artifactId>illuminati-client-elasticsearch</artifactId>
<version>0.7.7</version>
<version>0.7.8</version>
</dependency>
```

## add to Gradle Dependency
* Gradle

```java
compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.7'
compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.8'
```

===============================================================================
Expand All @@ -42,13 +42,13 @@ compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.7'
<dependency>
<groupId>com.leekyoungil.illuminati</groupId>
<artifactId>illuminati-client-elasticsearch</artifactId>
<version>0.7.7</version>
<version>0.7.8</version>
</dependency>
```

## Gradle Dependency 추가
* Gradle

```java
compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.7'
compile 'com.leekyoungil.illuminati:illuminati-client-elasticsearch:0.7.8'
```
4 changes: 2 additions & 2 deletions illuminati-client/illuminati-client-elasticsearch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.leekyoungil.illuminati</groupId>
<artifactId>illuminati-client-elasticsearch</artifactId>
<version>0.7.7</version>
<version>0.7.8</version>
<packaging>jar</packaging>

<properties>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>com.leekyoungil.illuminati</groupId>
<artifactId>illuminati-client-processor</artifactId>
<version>0.9.7</version>
<version>0.9.8</version>
<scope>compile</scope>
</dependency>

Expand Down
10 changes: 5 additions & 5 deletions illuminati-client/illuminati-client-processor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +29,7 @@
<dependency>
<groupId>com.leekyoungil.illuminati</groupId>
<artifactId>illuminati-client-processor</artifactId>
<version>0.9.7</version>
<version>0.9.8</version>
</dependency>

<!-- This is an option. If you add the module, you can turn it on and off without deploying it. -->
Expand All @@ -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'
```
Expand Down Expand Up @@ -190,7 +190,7 @@ chaosBomber: true
<dependency>
<groupId>com.leekyoungil.illuminati</groupId>
<artifactId>illuminati-client-processor</artifactId>
<version>0.9.7</version>
<version>0.9.8</version>
</dependency>

<!-- 이것은 옵션 입니다. 해당 모듈을 추가하면 대시 배포 없이 on, off할수 있습니다. -->
Expand All @@ -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 추가
Expand Down
2 changes: 1 addition & 1 deletion illuminati-client/illuminati-client-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.leekyoungil.illuminati</groupId>
<artifactId>illuminati-client-processor</artifactId>
<version>0.9.7</version>
<version>0.9.8</version>
<packaging>jar</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public class IlluminatiDataExecutorImpl implements IlluminatiExecutor<Illuminati

private static final Logger ILLUMINATI_DATA_EXECUTOR_LOGGER = LoggerFactory.getLogger(IlluminatiDataExecutorImpl.class);

private static IlluminatiDataExecutorImpl ILLUMINATI_DATA_EXECUTOR_IMPL;

// ################################################################################################################
// ### init illuminati data queue z ###
// ### init illuminati data queue ###
// ################################################################################################################
private static final int ILLUMINATI_DATA_BAK_LOG = 10000;
private static final long ILLUMINATI_DATA_DEQUEUING_TIMEOUT_MS = 1000;
Expand All @@ -35,23 +37,33 @@ public class IlluminatiDataExecutorImpl implements IlluminatiExecutor<Illuminati
// ################################################################################################################
// ### init illuminati template executor ###
// ################################################################################################################
private static IlluminatiExecutor<IlluminatiTemplateInterfaceModel> ILLUMINATI_TEMPLATE_EXECUTOR = new IlluminatiTemplateExecutorImpl();
private static IlluminatiExecutor<IlluminatiTemplateInterfaceModel> ILLUMINATI_TEMPLATE_EXECUTOR = IlluminatiTemplateExecutorImpl.getInstance();

// ################################################################################################################
// ### init illuminati basic system variables ###
// ################################################################################################################
private static String PARENT_MODULE_NAME;
private static ServerInfo SERVER_INFO;
private static Map<String, Object> 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<String, Object> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class IlluminatiTemplateExecutorImpl implements IlluminatiExecutor<Illumi

private static final Logger ILLUMINATI_TEMPLATE_EXECUTOR_LOGGER = LoggerFactory.getLogger(IlluminatiTemplateExecutorImpl.class);

private static IlluminatiTemplateExecutorImpl ILLUMINATI_TEMPLATE_EXECUTOR_IMPL;

// ################################################################################################################
// ### init illuminati template queue ###
// ################################################################################################################
Expand All @@ -37,6 +39,20 @@ public class IlluminatiTemplateExecutorImpl implements IlluminatiExecutor<Illumi
// ################################################################################################################
private static IlluminatiInfraTemplate ILLUMINATI_TEMPLATE;

private IlluminatiTemplateExecutorImpl () { }

public static IlluminatiTemplateExecutorImpl getInstance () {
if (ILLUMINATI_TEMPLATE_EXECUTOR_IMPL == null) {
synchronized (IlluminatiTemplateExecutorImpl.class) {
if (ILLUMINATI_TEMPLATE_EXECUTOR_IMPL == null) {
ILLUMINATI_TEMPLATE_EXECUTOR_IMPL = new IlluminatiTemplateExecutorImpl();
}
}
}

return ILLUMINATI_TEMPLATE_EXECUTOR_IMPL;
}

@Override public synchronized void init () {
if (ILLUMINATI_TEMPLATE == null) {
ILLUMINATI_TEMPLATE = this.initIlluminatiTemplate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,41 @@ public class IlluminatiClientInit {

private static final Logger ILLUMINATI_INIT_LOGGER = LoggerFactory.getLogger(IlluminatiClientInit.class);

private static IlluminatiClientInit ILLUMINATI_CLIENT_INIT_INSTANCE;

private static final AtomicInteger SAMPLING_RATE_CHECKER = new AtomicInteger(1);
private static int SAMPLING_RATE = 20;
private static int CHAOSBOMBER_NUMBER = (int) (Math.random() * 100) + 1;

private static final IlluminatiExecutor<IlluminatiDataInterfaceModel> ILLUMINATI_DATA_EXECUTOR = new IlluminatiDataExecutorImpl();
private static final IlluminatiExecutor<IlluminatiDataInterfaceModel> ILLUMINATI_DATA_EXECUTOR = IlluminatiDataExecutorImpl.getInstance();

public synchronized static void init () {
static {
IlluminatiCommon.init();
ILLUMINATI_DATA_EXECUTOR.init();

final String samplingRate = IlluminatiPropertiesHelper.getPropertiesValueByKey(IlluminatiPropertiesImpl.class, null, "illuminati", "samplingRate");
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();
Expand All @@ -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<String, Object> 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);
}

/**
Expand All @@ -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<String, Object> originMethodExecute = getMethodExecuteResult(pjp);
final long elapsedTime = System.currentTimeMillis() - start;
Expand All @@ -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");
}
Expand All @@ -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.
Expand All @@ -164,7 +177,7 @@ private static boolean checkSamplingRate () {
return false;
}

private static Map<String, Object> getMethodExecuteResult (final ProceedingJoinPoint pjp) {
private Map<String, Object> getMethodExecuteResult (final ProceedingJoinPoint pjp) {
final Map<String, Object> originMethodExecute = new HashMap<String, Object>();

try {
Expand Down
Loading

0 comments on commit 06d56ac

Please sign in to comment.