Skip to content

Commit

Permalink
[pinpoint-apm#8757] Remove duplicate agent metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Apr 8, 2022
1 parent 31ae700 commit 9a3e190
Show file tree
Hide file tree
Showing 106 changed files with 750 additions and 3,216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.navercorp.pinpoint.batch.alarm.collector.ResponseTimeDataCollector;
import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo;
import com.navercorp.pinpoint.common.server.bo.stat.DataSourceListBo;
import com.navercorp.pinpoint.common.server.bo.stat.FileDescriptorBo;
import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo;
import com.navercorp.pinpoint.web.alarm.CheckerCategory;
import com.navercorp.pinpoint.web.alarm.DataCollectorCategory;
Expand All @@ -33,9 +34,7 @@
import com.navercorp.pinpoint.web.dao.hbase.HbaseMapResponseTimeDao;
import com.navercorp.pinpoint.web.dao.hbase.HbaseMapStatisticsCallerDao;
import com.navercorp.pinpoint.web.dao.stat.AgentStatDao;
import com.navercorp.pinpoint.web.dao.stat.FileDescriptorDao;
import com.navercorp.pinpoint.web.vo.Application;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.Objects;
Expand All @@ -58,7 +57,7 @@ public class DataCollectorFactory {

private final AgentStatDao<DataSourceListBo> dataSourceDao;

private final FileDescriptorDao fileDescriptorDao;
private final AgentStatDao<FileDescriptorBo> fileDescriptorDao;

private final AgentEventDao agentEventDao;

Expand All @@ -67,10 +66,10 @@ public class DataCollectorFactory {
private final HbaseMapStatisticsCallerDao mapStatisticsCallerDao;

public DataCollectorFactory(HbaseMapResponseTimeDao hbaseMapResponseTimeDao,
@Qualifier("jvmGcDaoFactory") AgentStatDao<JvmGcBo> jvmGcDao,
@Qualifier("cpuLoadDaoFactory") AgentStatDao<CpuLoadBo> cpuLoadDao,
@Qualifier("dataSourceDaoFactory") AgentStatDao<DataSourceListBo> dataSourceDao,
@Qualifier("fileDescriptorDaoFactory") FileDescriptorDao fileDescriptorDao,
AgentStatDao<JvmGcBo> jvmGcDao,
AgentStatDao<CpuLoadBo> cpuLoadDao,
AgentStatDao<DataSourceListBo> dataSourceDao,
AgentStatDao<FileDescriptorBo> fileDescriptorDao,
AgentEventDao agentEventDao,
HbaseApplicationIndexDao hbaseApplicationIndexDao,
HbaseMapStatisticsCallerDao mapStatisticsCallerDao) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package com.navercorp.pinpoint.batch.alarm.checker;

import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType;
import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo;
import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo;
import com.navercorp.pinpoint.common.server.bo.stat.join.StatType;
import com.navercorp.pinpoint.web.dao.ApplicationIndexDao;
import com.navercorp.pinpoint.web.dao.stat.AgentStatDao;
import com.navercorp.pinpoint.web.vo.Application;
Expand All @@ -43,7 +45,12 @@ public class GcCountCheckerTest {

@BeforeClass
public static void before() {
jvmGcDao = new AgentStatDao<JvmGcBo>() {
jvmGcDao = new AgentStatDao<>() {

@Override
public String getChartType() {
return AgentStatType.JVM_GC.getChartType();
}

@Override
public List<JvmGcBo> getAgentStatList(String agentId, Range range) {
Expand All @@ -64,7 +71,12 @@ public boolean agentStatExists(String agentId, Range range) {
}
};

cpuLoadDao = new AgentStatDao<CpuLoadBo>() {
cpuLoadDao = new AgentStatDao<>() {

@Override
public String getChartType() {
return AgentStatType.CPU_LOAD.getChartType();
}

@Override
public List<CpuLoadBo> getAgentStatList(String agentId, Range range) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.navercorp.pinpoint.batch.alarm.checker;

import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType;
import com.navercorp.pinpoint.web.alarm.CheckerCategory;
import com.navercorp.pinpoint.web.alarm.DataCollectorCategory;
import com.navercorp.pinpoint.batch.alarm.DataCollectorFactory;
Expand Down Expand Up @@ -45,26 +46,32 @@ public class HeapUsageRateCheckerTest {
private static final String SERVICE_TYPE = "tomcat";

private static ApplicationIndexDao applicationIndexDao;

private static AgentStatDao<JvmGcBo> jvmGcDao;

private static AgentStatDao<CpuLoadBo> cpuLoadDao;

@BeforeClass
public static void before() {jvmGcDao = new AgentStatDao<JvmGcBo>() {
public static void before() {
jvmGcDao = new AgentStatDao<>() {

@Override
public String getChartType() {
return AgentStatType.JVM_GC.getChartType();
}

@Override
public List<JvmGcBo> getAgentStatList(String agentId, Range range) {
List<JvmGcBo> jvmGcs = new LinkedList<>();

for (int i = 0; i < 36; i++) {
JvmGcBo jvmGcBo = new JvmGcBo();
jvmGcBo.setHeapUsed(70L);
jvmGcBo.setHeapMax(100L);

jvmGcs.add(jvmGcBo);
}

return jvmGcs;
}

Expand All @@ -74,7 +81,12 @@ public boolean agentStatExists(String agentId, Range range) {
}
};

cpuLoadDao = new AgentStatDao<CpuLoadBo>() {
cpuLoadDao = new AgentStatDao<>() {

@Override
public String getChartType() {
return AgentStatType.CPU_LOAD.getChartType();
}

@Override
public List<CpuLoadBo> getAgentStatList(String agentId, Range range) {
Expand Down Expand Up @@ -106,7 +118,7 @@ public List<String> selectAgentIds(String applicationName) {
agentIds.add("local_tomcat");
return agentIds;
}

throw new IllegalArgumentException();
}

Expand All @@ -124,40 +136,40 @@ public void deleteAgentIds(Map<String, List<String>> applicationAgentIdMap) {
public void deleteAgentId(String applicationName, String agentId) {
throw new UnsupportedOperationException();
}

};
}


@Test
public void checkTest1() {
Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.HEAP_USAGE_RATE.getName(), 70, "testGroup", false, false, false, "");
Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE);
AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, jvmGcDao, cpuLoadDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN);
AgentChecker checker = new HeapUsageRateChecker(collector, rule);

checker.check();
assertTrue(checker.isDetected());
}

@Test
public void checkTest2() {
Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.HEAP_USAGE_RATE.getName(), 71, "testGroup", false, false, false, "");
Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE);
AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, jvmGcDao, cpuLoadDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN);
AgentChecker checker = new HeapUsageRateChecker(collector, rule);

checker.check();
assertFalse(checker.isDetected());
}


// @Autowired
// private HbaseAgentStatDao hbaseAgentStatDao ;

// @Autowired
// private HbaseApplicationIndexDao applicationIndexDao;

// @Test
// public void checkTest1() {
// Rule rule = new Rule(SERVICE_NAME, CheckerCategory.HEAP_USAGE_RATE.getName(), 60, "testGroup", false, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.navercorp.pinpoint.batch.alarm.checker;

import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType;
import com.navercorp.pinpoint.web.alarm.CheckerCategory;
import com.navercorp.pinpoint.web.alarm.DataCollectorCategory;
import com.navercorp.pinpoint.batch.alarm.DataCollectorFactory;
Expand Down Expand Up @@ -52,7 +53,12 @@ public class JvmCpuUsageRateCheckerTest {

@BeforeClass
public static void before() {
jvmGcDao = new AgentStatDao<JvmGcBo>() {
jvmGcDao = new AgentStatDao<>() {

@Override
public String getChartType() {
return AgentStatType.JVM_GC.getChartType();
}

@Override
public List<JvmGcBo> getAgentStatList(String agentId, Range range) {
Expand All @@ -65,7 +71,11 @@ public boolean agentStatExists(String agentId, Range range) {
}
};

cpuLoadDao = new AgentStatDao<CpuLoadBo>() {
cpuLoadDao = new AgentStatDao<>() {
@Override
public String getChartType() {
return AgentStatType.CPU_LOAD.getChartType();
}

public List<CpuLoadBo> getAgentStatList(String agentId, Range range) {
List<CpuLoadBo> cpuLoads = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.batch.alarm.DataCollectorFactory;
import com.navercorp.pinpoint.web.dao.ApplicationIndexDao;
import com.navercorp.pinpoint.web.dao.stat.FileDescriptorDao;
import com.navercorp.pinpoint.web.dao.stat.AgentStatDao;
import com.navercorp.pinpoint.web.vo.Application;
import com.navercorp.pinpoint.common.server.util.time.Range;
import org.junit.Test;
Expand Down Expand Up @@ -51,7 +51,7 @@ public void collect() {
ApplicationIndexDao applicationIndexDao = mock(ApplicationIndexDao.class);
when(applicationIndexDao.selectAgentIds(applicationId)).thenReturn(agentList);

FileDescriptorDao fileDescriptorDao = mock(FileDescriptorDao.class);
AgentStatDao<FileDescriptorBo> fileDescriptorDao = mock(AgentStatDao.class);
long timeStamp = 1558936971494L;
Range range = Range.newUncheckedRange(timeStamp - DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN, timeStamp);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,37 @@
* @author HyunGil Jeong
*/
public enum AgentStatType {
UNKNOWN(0, "Unknown"),
JVM_GC(1, "JVM GC"),
JVM_GC_DETAILED(2, "JVM GC Detailed"),
CPU_LOAD(3, "Cpu Usage"),
TRANSACTION((byte) 4, "Transaction"),
ACTIVE_TRACE((byte) 5, "Active Trace"),
DATASOURCE((byte) 6, "DataSource"),
RESPONSE_TIME((byte) 7, "Response Time"),
DEADLOCK((byte) 8, "Deadlock"),
FILE_DESCRIPTOR((byte) 9, "FileDescriptor"),
DIRECT_BUFFER((byte) 10, "DirectBuffer"),
TOTAL_THREAD((byte) 11, "Total Thread Count"),
LOADED_CLASS((byte) 12, "Loaded Class"),
UNKNOWN(0, "Unknown", null),
JVM_GC(1, "JVM GC", "jvmGc"),
JVM_GC_DETAILED(2, "JVM GC Detailed", "jvmGcDetailed"),
CPU_LOAD(3, "Cpu Usage", "cpuLoad"),
TRANSACTION((byte) 4, "Transaction", "transaction"),
ACTIVE_TRACE((byte) 5, "Active Trace", "activeTrace"),
DATASOURCE((byte) 6, "DataSource", "dataSource"),
RESPONSE_TIME((byte) 7, "Response Time", "responseTime"),
DEADLOCK((byte) 8, "Deadlock", "deadlock"),
FILE_DESCRIPTOR((byte) 9, "FileDescriptor", "fileDescriptor"),
DIRECT_BUFFER((byte) 10, "DirectBuffer", "directBuffer"),
TOTAL_THREAD((byte) 11, "Total Thread Count", "totalThreadCount"),
LOADED_CLASS((byte) 12, "Loaded Class", "loadedClass"),

URI((byte) 100, "Agent URI Stat");
URI((byte) 100, "Agent URI Stat", "uriStat");

public static final int TYPE_CODE_BYTE_LENGTH = 1;

private final byte typeCode;
private final String name;
private final String chartType;

private static final Set<AgentStatType> AGENT_STAT_TYPES = EnumSet.allOf(AgentStatType.class);

AgentStatType(int typeCode, String name) {
AgentStatType(int typeCode, String name, String chartType) {
if (typeCode < 0 || typeCode > 255) {
throw new IllegalArgumentException("type code out of range (0~255)");
}
this.typeCode = (byte) (typeCode & 0xFF);
this.name = name;
this.chartType = chartType;
}

public int getTypeCode() {
Expand All @@ -66,6 +68,10 @@ public String getName() {
return name;
}

public String getChartType() {
return chartType;
}

@Override
public String toString() {
return this.name;
Expand Down
Loading

0 comments on commit 9a3e190

Please sign in to comment.