-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
batch/src/main/java/com/navercorp/pinpoint/batch/alarm/checker/ApdexScoreChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2022 NAVER Corp. | ||
* | ||
* Licensed 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 com.navercorp.pinpoint.batch.alarm.checker; | ||
|
||
import com.navercorp.pinpoint.batch.alarm.collector.ResponseTimeDataCollector; | ||
import com.navercorp.pinpoint.web.alarm.vo.Rule; | ||
import com.navercorp.pinpoint.web.applicationmap.histogram.ApdexScore; | ||
|
||
/** | ||
* @author youngjin.kim2 | ||
*/ | ||
public class ApdexScoreChecker extends LongValueAlarmChecker { | ||
|
||
public ApdexScoreChecker(ResponseTimeDataCollector dataCollector, Rule rule) { | ||
super(rule, "%", dataCollector); | ||
} | ||
|
||
@Override | ||
protected Long getDetectedValue() { | ||
final ResponseTimeDataCollector dataCollector = (ResponseTimeDataCollector) this.dataCollector; | ||
|
||
final long satisfiedCount = dataCollector.getFastCount(); | ||
final long toleratingCount = dataCollector.getNormalCount(); | ||
final long totalSamples = dataCollector.getTotalCount(); | ||
final double score = (new ApdexScore(satisfiedCount, toleratingCount, totalSamples)).getApdexScore(); | ||
|
||
return (long) (score * 100.0); | ||
} | ||
|
||
@Override | ||
protected boolean decideResult(Long value) { | ||
return value <= rule.getThreshold(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/ApdexScoreCheckerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2022 NAVER Corp. | ||
* | ||
* Licensed 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 com.navercorp.pinpoint.batch.alarm.checker; | ||
|
||
import com.navercorp.pinpoint.batch.alarm.collector.ResponseTimeDataCollector; | ||
import com.navercorp.pinpoint.common.trace.ServiceType; | ||
import com.navercorp.pinpoint.web.alarm.CheckerCategory; | ||
import com.navercorp.pinpoint.web.alarm.DataCollectorCategory; | ||
import com.navercorp.pinpoint.web.alarm.vo.Rule; | ||
import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogram; | ||
import com.navercorp.pinpoint.web.dao.MapResponseDao; | ||
import com.navercorp.pinpoint.web.vo.Application; | ||
import com.navercorp.pinpoint.web.vo.ResponseTime; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author youngjin.kim2 | ||
*/ | ||
public class ApdexScoreCheckerTest { | ||
|
||
private static final String SERVICE_NAME = "local_service"; | ||
private static final String SERVICE_TYPE = "tomcat"; | ||
|
||
private static MapResponseDao mockMapResponseDAO; | ||
|
||
@BeforeClass | ||
public static void before() { | ||
mockMapResponseDAO = (application, range) -> { | ||
List<ResponseTime> list = new LinkedList<>(); | ||
long timeStamp = 1409814914298L; | ||
ResponseTime responseTime = new ResponseTime(SERVICE_NAME, ServiceType.STAND_ALONE, timeStamp); | ||
list.add(responseTime); | ||
|
||
for (int i=0 ; i < 5; i++) { | ||
for (int j=0 ; j < 5; j++) { | ||
TimeHistogram histogram = new TimeHistogram(ServiceType.STAND_ALONE, timeStamp); | ||
histogram.addCallCountByElapsedTime(1000, false); | ||
histogram.addCallCountByElapsedTime(1000, false); | ||
histogram.addCallCountByElapsedTime(1000, false); | ||
histogram.addCallCountByElapsedTime(1000, false); | ||
histogram.addCallCountByElapsedTime(6000, false); | ||
responseTime.addResponseTime("agent_" + i + "_" + j, histogram); | ||
} | ||
timeStamp += 1; | ||
} | ||
|
||
return list; | ||
}; | ||
} | ||
|
||
/* | ||
* alert conditions not satisfied | ||
*/ | ||
@Test | ||
public void checkTest1() { | ||
Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); | ||
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); | ||
Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SLOW_COUNT.getName(), 90, "testGroup", false, false, false, ""); | ||
ApdexScoreChecker checker = new ApdexScoreChecker(collector, rule); | ||
|
||
checker.check(); | ||
assertTrue(checker.isDetected()); | ||
} | ||
|
||
/* | ||
* alert conditions not satisfied | ||
*/ | ||
@Test | ||
public void checkTest2() { | ||
Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); | ||
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); | ||
Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SLOW_COUNT.getName(), 75, "testGroup", false, false, false, ""); | ||
ApdexScoreChecker checker = new ApdexScoreChecker(collector, rule); | ||
|
||
checker.check(); | ||
assertFalse(checker.isDetected()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters