diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/DataCollectorFactory.java b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/DataCollectorFactory.java index 0cb0a207170d..a93735dcab84 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/DataCollectorFactory.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/DataCollectorFactory.java @@ -17,27 +17,20 @@ package com.navercorp.pinpoint.batch.alarm; import com.navercorp.pinpoint.batch.alarm.collector.AgentEventDataCollector; -import com.navercorp.pinpoint.batch.alarm.collector.AgentStatDataCollector; import com.navercorp.pinpoint.batch.alarm.collector.DataCollector; import com.navercorp.pinpoint.batch.alarm.collector.MapStatisticsCallerDataCollector; import com.navercorp.pinpoint.batch.alarm.collector.ResponseTimeDataCollector; import com.navercorp.pinpoint.batch.alarm.collector.pinot.DataSourceDataCollector; +import com.navercorp.pinpoint.batch.alarm.collector.pinot.FileDescriptorDataCollector; import com.navercorp.pinpoint.batch.alarm.collector.pinot.HeapDataCollector; import com.navercorp.pinpoint.batch.alarm.collector.pinot.JvmCpuDataCollector; import com.navercorp.pinpoint.batch.alarm.collector.pinot.SystemCpuDataCollector; -import com.navercorp.pinpoint.batch.alarm.collector.pinot.FileDescriptorDataCollector; import com.navercorp.pinpoint.batch.alarm.dao.AlarmDao; -import com.navercorp.pinpoint.batch.common.BatchProperties; -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; import com.navercorp.pinpoint.web.applicationmap.dao.MapResponseDao; import com.navercorp.pinpoint.web.applicationmap.dao.MapStatisticsCallerDao; import com.navercorp.pinpoint.web.dao.AgentEventDao; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; import com.navercorp.pinpoint.web.vo.Application; import org.springframework.stereotype.Component; @@ -53,78 +46,28 @@ public class DataCollectorFactory { public final static long SLOT_INTERVAL_FIVE_MIN = 300000; - public final static long SLOT_INTERVAL_THREE_MIN = 180000; - private final MapResponseDao mapResponseDao; - private final AgentStatDao jvmGcDao; - - private final AgentStatDao cpuLoadDao; - - private final AgentStatDao dataSourceDao; - - private final AgentStatDao fileDescriptorDao; - private final AgentEventDao agentEventDao; private final MapStatisticsCallerDao callerDao; private final AlarmDao alarmDao; - - private final int collectorVersion; - + public DataCollectorFactory(MapResponseDao mapResponseDao, - AgentStatDao jvmGcDao, - AgentStatDao cpuLoadDao, - AgentStatDao dataSourceDao, - AgentStatDao fileDescriptorDao, AgentEventDao agentEventDao, MapStatisticsCallerDao callerDao, - AlarmDao alarmDao, - BatchProperties batchProperties) { + AlarmDao alarmDao) { this.mapResponseDao = Objects.requireNonNull(mapResponseDao, "mapResponseDao"); - this.jvmGcDao = Objects.requireNonNull(jvmGcDao, "jvmGcDao"); - this.cpuLoadDao = Objects.requireNonNull(cpuLoadDao, "cpuLoadDao"); - this.dataSourceDao = Objects.requireNonNull(dataSourceDao, "dataSourceDao"); - this.fileDescriptorDao = Objects.requireNonNull(fileDescriptorDao, "fileDescriptorDao"); this.agentEventDao = Objects.requireNonNull(agentEventDao, "agentEventDao"); this.callerDao = Objects.requireNonNull(callerDao, "callerDao"); this.alarmDao = Objects.requireNonNull(alarmDao, "alarmDao"); - this.collectorVersion = batchProperties.getCollectorVersion(); } public DataCollector createDataCollector(CheckerCategory checker, Application application, Supplier> agentIds, long timeSlotEndTime) { - if (collectorVersion == 1) { - return createDataCollectorV1(checker, application, agentIds, timeSlotEndTime); - } else { - return createDataCollectorV2(checker, application, agentIds, timeSlotEndTime); - } - - } - - private DataCollector createDataCollectorV1(CheckerCategory checker, Application application, Supplier> agentIds, long timeSlotEndTime) { - return switch (checker.getDataCollectorCategory()) { - case RESPONSE_TIME -> - new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mapResponseDao, timeSlotEndTime, SLOT_INTERVAL_FIVE_MIN); - case AGENT_STAT, HEAP_USAGE_RATE, JVM_CPU_USAGE_RATE, SYSTEM_CPU_USAGE_RATE -> - new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, jvmGcDao, cpuLoadDao, agentIds.get(), timeSlotEndTime, SLOT_INTERVAL_FIVE_MIN); - case AGENT_EVENT -> - new AgentEventDataCollector(DataCollectorCategory.AGENT_EVENT, agentEventDao, agentIds.get(), timeSlotEndTime, SLOT_INTERVAL_FIVE_MIN); - case CALLER_STAT -> - new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, callerDao, timeSlotEndTime, SLOT_INTERVAL_FIVE_MIN); - case DATA_SOURCE_STAT -> - new com.navercorp.pinpoint.batch.alarm.collector.DataSourceDataCollector(DataCollectorCategory.DATA_SOURCE_STAT, dataSourceDao, agentIds.get(), timeSlotEndTime, SLOT_INTERVAL_FIVE_MIN); - case FILE_DESCRIPTOR -> - new com.navercorp.pinpoint.batch.alarm.collector.FileDescriptorDataCollector(DataCollectorCategory.FILE_DESCRIPTOR, fileDescriptorDao, agentIds.get(), timeSlotEndTime, SLOT_INTERVAL_FIVE_MIN); - }; - } - - private DataCollector createDataCollectorV2(CheckerCategory checker, Application application, Supplier> agentIds, long timeSlotEndTime) { return switch (checker.getDataCollectorCategory()) { case RESPONSE_TIME -> new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mapResponseDao, timeSlotEndTime, SLOT_INTERVAL_FIVE_MIN); - case AGENT_STAT -> - new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, jvmGcDao, cpuLoadDao, agentIds.get(), timeSlotEndTime, SLOT_INTERVAL_FIVE_MIN); case AGENT_EVENT -> new AgentEventDataCollector(DataCollectorCategory.AGENT_EVENT, agentEventDao, agentIds.get(), timeSlotEndTime, SLOT_INTERVAL_FIVE_MIN); case CALLER_STAT -> diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/checker/DataSourceConnectionUsageRateChecker.java b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/checker/DataSourceConnectionUsageRateChecker.java index 47f1a5565843..748f453b98e2 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/checker/DataSourceConnectionUsageRateChecker.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/checker/DataSourceConnectionUsageRateChecker.java @@ -17,9 +17,7 @@ package com.navercorp.pinpoint.batch.alarm.checker; import com.navercorp.pinpoint.batch.alarm.collector.DataCollector; -import com.navercorp.pinpoint.batch.alarm.collector.DataSourceDataCollector; import com.navercorp.pinpoint.batch.alarm.collector.DataSourceDataGetter; -import com.navercorp.pinpoint.batch.alarm.collector.FileDescriptorDataGetter; import com.navercorp.pinpoint.batch.alarm.vo.DataSourceAlarmVO; import com.navercorp.pinpoint.common.util.Assert; import com.navercorp.pinpoint.web.alarm.vo.Rule; diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/checker/GcCountChecker.java b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/checker/GcCountChecker.java deleted file mode 100644 index eee2094e5447..000000000000 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/checker/GcCountChecker.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2014 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.AgentStatDataCollector; -import com.navercorp.pinpoint.web.alarm.vo.Rule; - -import java.util.Map; - -/** - * @author minwoo.jung - * @author Jongjin.Bae - */ -public class GcCountChecker extends LongValueAgentChecker { - - public GcCountChecker(AgentStatDataCollector dataCollector, Rule rule) { - super(rule, "", dataCollector); - } - - @Override - protected Map getAgentValues() { - return ((AgentStatDataCollector)dataCollector).getGCCount(); - } -} diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/AgentStatDataCollector.java b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/AgentStatDataCollector.java deleted file mode 100644 index b3da56cd6c3f..000000000000 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/AgentStatDataCollector.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2014 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.collector; - -import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.web.alarm.DataCollectorCategory; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * @author minwoo.jung - */ -public class AgentStatDataCollector extends DataCollector implements HeapDataGetter, JvmCpuDataGetter, SystemCpuDataGetter { - private final AgentStatDao jvmGcDao; - private final AgentStatDao cpuLoadDao; - private final List agentIds; - private final long timeSlotEndTime; - private final long slotInterval; - private final AtomicBoolean init = new AtomicBoolean(false); // need to consider a race condition when checkers start simultaneously. - - private final Map agentHeapUsageRate = new HashMap<>(); - private final Map agentGcCount = new HashMap<>(); - private final Map agentJvmCpuUsageRate = new HashMap<>(); - private final Map agentSystemCpuUsageRate = new HashMap<>(); - - public AgentStatDataCollector( - DataCollectorCategory category, - AgentStatDao jvmGcDao, - AgentStatDao cpuLoadDao, - List agentIds, - long timeSlotEndTime, - long slotInterval - ) { - super(category); - - this.jvmGcDao = jvmGcDao; - this.cpuLoadDao = cpuLoadDao; - this.agentIds = agentIds; - this.timeSlotEndTime = timeSlotEndTime; - this.slotInterval = slotInterval; - } - - @Override - public void collect() { - if (init.get()) { - return; - } - - Range range = Range.between(timeSlotEndTime - slotInterval, timeSlotEndTime); - - for(String agentId : agentIds) { - List jvmGcBos = jvmGcDao.getAgentStatList(agentId, range); - List cpuLoadBos = cpuLoadDao.getAgentStatList(agentId, range); - long totalHeapSize = 0; - long usedHeapSize = 0; - long jvmCpuUsaged = 0; - long systemCpuUsaged = 0; - - for (JvmGcBo jvmGcBo : jvmGcBos) { - totalHeapSize += jvmGcBo.getHeapMax(); - usedHeapSize += jvmGcBo.getHeapUsed(); - } - - for (CpuLoadBo cpuLoadBo : cpuLoadBos) { - jvmCpuUsaged += cpuLoadBo.getJvmCpuLoad() * 100; - systemCpuUsaged += cpuLoadBo.getSystemCpuLoad() * 100; - } - - if (!jvmGcBos.isEmpty()) { - long percent = calculatePercent(usedHeapSize, totalHeapSize); - agentHeapUsageRate.put(agentId, percent); - - long accruedLastGcCount = jvmGcBos.get(0).getGcOldCount(); - long accruedFirstGcCount = jvmGcBos.get(jvmGcBos.size() - 1).getGcOldCount(); - agentGcCount.put(agentId, accruedLastGcCount - accruedFirstGcCount); - } - if (!cpuLoadBos.isEmpty()) { - long jvmCpuUsagedPercent = calculatePercent(jvmCpuUsaged, 100L * cpuLoadBos.size()); - agentJvmCpuUsageRate.put(agentId, jvmCpuUsagedPercent); - long systemCpuUsagedPercent = calculatePercent(systemCpuUsaged, 100L * cpuLoadBos.size()); - agentSystemCpuUsageRate.put(agentId, systemCpuUsagedPercent); - } - } - - init.set(true); - - } - - @Override - public Map getHeapUsageRate() { - return agentHeapUsageRate; - } - - public Map getGCCount() { - return agentGcCount; - } - - @Override - public Map getJvmCpuUsageRate() { - return agentJvmCpuUsageRate; - } - - @Override - public Map getSystemCpuUsageRate() { return agentSystemCpuUsageRate; } -} diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/DataSourceDataCollector.java b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/DataSourceDataCollector.java deleted file mode 100644 index 614dbf087b38..000000000000 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/DataSourceDataCollector.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2017 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.collector; - -import com.navercorp.pinpoint.batch.alarm.vo.DataSourceAlarmVO; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceBo; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceListBo; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.common.util.CollectionUtils; -import com.navercorp.pinpoint.web.alarm.DataCollectorCategory; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * @author Taejin Koo - */ -public class DataSourceDataCollector extends DataCollector implements DataSourceDataGetter { - private final AgentStatDao dataSourceDao; - private final List agentIds; - private final long timeSlotEndTime; - private final long slotInterval; - - private final MultiValueMap agentDataSourceConnectionUsageRateMap = new LinkedMultiValueMap<>(); - - private final AtomicBoolean init = new AtomicBoolean(false); // need to consider a race condition when checkers start simultaneously. - - public DataSourceDataCollector( - DataCollectorCategory dataCollectorCategory, - AgentStatDao dataSourceDao, - List agentIds, - long timeSlotEndTime, - long slotInterval - ) { - super(dataCollectorCategory); - - this.dataSourceDao = dataSourceDao; - this.agentIds = agentIds; - this.timeSlotEndTime = timeSlotEndTime; - this.slotInterval = slotInterval; - } - - @Override - public void collect() { - if (init.get()) { - return; - } - - Range range = Range.between(timeSlotEndTime - slotInterval, timeSlotEndTime); - - for (String agentId : agentIds) { - List dataSourceListBos = dataSourceDao.getAgentStatList(agentId, range); - MultiValueMap partitions = partitionDataSourceId(dataSourceListBos); - - for (Map.Entry> entry : partitions.entrySet()) { - List dataSourceBoList = entry.getValue(); - - if (CollectionUtils.hasLength(dataSourceBoList)) { - double activeConnectionAvg = dataSourceBoList.stream() - .mapToInt(DataSourceBo::getActiveConnectionSize) - .average() - .orElse(-1); - double maxConnectionAvg = dataSourceBoList.stream() - .mapToInt(DataSourceBo::getMaxConnectionSize) - .average() - .orElse(-1); - DataSourceBo dataSourceBo = org.springframework.util.CollectionUtils.firstElement(dataSourceBoList); - if (dataSourceBo == null) { - continue; - } - - DataSourceAlarmVO dataSourceAlarmVO = new DataSourceAlarmVO(dataSourceBo.getId(), dataSourceBo.getDatabaseName(), - (int) Math.floor(activeConnectionAvg), (int) Math.floor(maxConnectionAvg)); - - agentDataSourceConnectionUsageRateMap.add(agentId, dataSourceAlarmVO); - } - } - } - - init.set(true); - } - - private MultiValueMap partitionDataSourceId(List dataSourceListBos) { - MultiValueMap result = new LinkedMultiValueMap<>(); - - for (DataSourceListBo dataSourceListBo : dataSourceListBos) { - List dataSourceBos = dataSourceListBo.getList(); - if (CollectionUtils.isEmpty(dataSourceBos)) { - continue; - } - - for (DataSourceBo dataSourceBo : dataSourceBos) { - int id = dataSourceBo.getId(); - - if (dataSourceBo.getMaxConnectionSize() <= 0 || dataSourceBo.getActiveConnectionSize() < 0) { - continue; - } - - result.add(id, dataSourceBo); - } - } - - return result; - } - - - @Override - public Map> getDataSourceConnectionUsageRate() { - return agentDataSourceConnectionUsageRateMap; - } - -} diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/FileDescriptorDataCollector.java b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/FileDescriptorDataCollector.java deleted file mode 100644 index 176af98372c6..000000000000 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/FileDescriptorDataCollector.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2019 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.collector; - -import com.navercorp.pinpoint.common.server.bo.stat.FileDescriptorBo; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.web.alarm.DataCollectorCategory; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * @author minwoo.jung - */ -public class FileDescriptorDataCollector extends DataCollector implements FileDescriptorDataGetter { - private final AgentStatDao fileDescriptorDao; - private final List agentIds; - private final long timeSlotEndTime; - private final long slotInterval; - private final AtomicBoolean init = new AtomicBoolean(false); - - private final Map fileDescriptorCount = new HashMap<>(); - - public FileDescriptorDataCollector( - DataCollectorCategory dataCollectorCategory, - AgentStatDao fileDescriptorDao, - List agentIds, - long timeSlotEndTime, - long slotInterval - ) { - super(dataCollectorCategory); - - this.fileDescriptorDao = fileDescriptorDao; - this.agentIds = agentIds; - this.timeSlotEndTime = timeSlotEndTime; - this.slotInterval = slotInterval; - } - - @Override - public void collect() { - if (init.get()) { - return; - } - - Range range = Range.between(timeSlotEndTime - slotInterval, timeSlotEndTime); - - for(String agentId : agentIds) { - List fileDescriptorBoList = fileDescriptorDao.getAgentStatList(agentId, range); - - if (fileDescriptorBoList.isEmpty()) { - continue; - } - - long fileDescriptorTotalCount = 0; - int size = fileDescriptorBoList.size(); - for (FileDescriptorBo fileDescriptorBo : fileDescriptorBoList) { - fileDescriptorTotalCount += fileDescriptorBo.getOpenFileDescriptorCount(); - } - - final long fileDescriptorAvgCount = fileDescriptorTotalCount / size; - - fileDescriptorCount.put(agentId, fileDescriptorAvgCount); - } - - init.set(true); - } - - @Override - public Map getFileDescriptorCount() { - return fileDescriptorCount; - } -} diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/pinot/FileDescriptorDataCollector.java b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/pinot/FileDescriptorDataCollector.java index 98e988e90d9d..5260c73d9cd9 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/pinot/FileDescriptorDataCollector.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/alarm/collector/pinot/FileDescriptorDataCollector.java @@ -33,8 +33,8 @@ * @author minwoo-jung */ public class FileDescriptorDataCollector extends DataCollector implements FileDescriptorDataGetter { - private final static String METRIC_NAME = "fileDescriptor"; - private final static String FIELD_NAME = "openFileDescriptorCount"; + protected final static String METRIC_NAME = "fileDescriptor"; + protected final static String FIELD_NAME = "openFileDescriptorCount"; private final AlarmDao alarmDao; private final Application application; diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/common/BatchProperties.java b/batch/src/main/java/com/navercorp/pinpoint/batch/common/BatchProperties.java index f167288964e0..184d925a5f99 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/common/BatchProperties.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/common/BatchProperties.java @@ -79,9 +79,6 @@ public class BatchProperties { @Value("${job.cleanup.inactive.applications.cron}") private String cleanupInactiveApplicationsJobCron; - @Value("${alarm.collector.version:1}") - private int collectorVersion; - private static final int MINIMUM_CLEANUP_INACTIVE_AGENTS_DURATION_DAYS = 7; @PostConstruct @@ -155,10 +152,6 @@ public String getCleanupInactiveApplicationsJobCron() { return cleanupInactiveApplicationsJobCron; } - public int getCollectorVersion() { - return collectorVersion; - } - public int getAgentInspectorStatTableCount() { return alarmAgentInspectorStatTableCount; } @@ -189,7 +182,6 @@ public String toString() { ", cleanupInactiveAgentsDurationDays=" + cleanupInactiveAgentsDurationDays + ", cleanupInactiveApplicationsJobEnable=" + cleanupInactiveApplicationsJobEnable + ", cleanupInactiveApplicationsJobCron='" + cleanupInactiveApplicationsJobCron + '\'' + - ", collectorVersion=" + collectorVersion + '}'; } } diff --git a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/AlarmProcessorTest.java b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/AlarmProcessorTest.java index bfa3f9b1357f..2fad5129c940 100644 --- a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/AlarmProcessorTest.java +++ b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/AlarmProcessorTest.java @@ -1,6 +1,6 @@ package com.navercorp.pinpoint.batch.alarm; -import com.navercorp.pinpoint.batch.alarm.collector.AgentStatDataCollector; +import com.navercorp.pinpoint.batch.alarm.collector.pinot.HeapDataCollector; import com.navercorp.pinpoint.batch.alarm.vo.AppAlarmChecker; import com.navercorp.pinpoint.batch.config.AlarmCheckerConfiguration; import com.navercorp.pinpoint.common.trace.ServiceType; @@ -48,7 +48,7 @@ public class AlarmProcessorTest { private ActiveAgentValidator activeAgentValidator; @Mock - private AgentStatDataCollector agentStatDataCollector; + private HeapDataCollector heapDataCollector; @Autowired CheckerRegistry checkerRegistry; @@ -78,8 +78,8 @@ public void test() { Map heapUsageRate = Map.of(agentIds.get(1), 80L, agentIds.get(2), 85L); when(alarmService.selectRuleByApplicationId(SERVICE_NAME)).thenReturn(List.of(rule1, rule2)); - when(dataCollectorFactory.createDataCollector(any(), any(), any(), anyLong())).thenReturn(agentStatDataCollector); - when(agentStatDataCollector.getHeapUsageRate()).thenReturn(heapUsageRate); + when(dataCollectorFactory.createDataCollector(any(), any(), any(), anyLong())).thenReturn(heapDataCollector); + when(heapDataCollector.getHeapUsageRate()).thenReturn(heapUsageRate); // Executions AlarmProcessor processor = new AlarmProcessor(dataCollectorFactory, alarmService, applicationIndexDao, activeAgentValidator, checkerRegistry); diff --git a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/DataSourceConnectionUsageRateCheckerTest.java b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/DataSourceConnectionUsageRateCheckerTest.java index 2e93012c446f..6e9d11384097 100644 --- a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/DataSourceConnectionUsageRateCheckerTest.java +++ b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/DataSourceConnectionUsageRateCheckerTest.java @@ -16,25 +16,19 @@ package com.navercorp.pinpoint.batch.alarm.checker; -import com.navercorp.pinpoint.batch.alarm.collector.DataSourceDataCollector; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceBo; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceListBo; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.batch.alarm.collector.pinot.DataSourceDataCollector; +import com.navercorp.pinpoint.batch.alarm.vo.DataSourceAlarmVO; import com.navercorp.pinpoint.common.util.StringUtils; 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.dao.stat.AgentStatDao; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Random; import static org.assertj.core.api.Assertions.assertThat; @@ -61,27 +55,22 @@ public class DataSourceConnectionUsageRateCheckerTest { private static final long TIMESTAMP_INTERVAL = 5000L; @Mock - private AgentStatDao mockDataSourceDao; - - @BeforeEach - public void before() { - Range range = Range.between(START_TIME_MILLIS, CURRENT_TIME_MILLIS); - - List dataSourceListBoList = List.of( - createDataSourceListBo(1, 30, 40, 3), - createDataSourceListBo(2, 25, 40, 3), - createDataSourceListBo(3, 10, 40, 3) - ); - - when(mockDataSourceDao.getAgentStatList(AGENT_ID, range)).thenReturn(dataSourceListBoList); - } + private DataSourceDataCollector dataSourceDataCollector; @Test public void checkTest1() { Rule rule = new Rule(APPLICATION_NAME, SERVICE_TYPE, CheckerCategory.ERROR_COUNT.getName(), 50, "testGroup", false, false, false, ""); + Map> dataSourceAlarmVOMap = Map.ofEntries( + Map.entry("local_tomcat", List.of( + new DataSourceAlarmVO(1, "database1", 11, 20), + new DataSourceAlarmVO(2, "database2", 20, 30), + new DataSourceAlarmVO(3, "database3", 13, 40) + )) + ); + + when(dataSourceDataCollector.getDataSourceConnectionUsageRate()).thenReturn(dataSourceAlarmVOMap); + DataSourceConnectionUsageRateChecker checker = new DataSourceConnectionUsageRateChecker(dataSourceDataCollector, rule); - DataSourceDataCollector collector = new DataSourceDataCollector(DataCollectorCategory.DATA_SOURCE_STAT, mockDataSourceDao, mockAgentIds, CURRENT_TIME_MILLIS, INTERVAL_MILLIS); - DataSourceConnectionUsageRateChecker checker = new DataSourceConnectionUsageRateChecker(collector, rule); checker.check(); Assertions.assertTrue(checker.isDetected()); @@ -94,10 +83,18 @@ public void checkTest1() { @Test public void checkTest2() { - Rule rule = new Rule(APPLICATION_NAME, SERVICE_TYPE, CheckerCategory.ERROR_COUNT.getName(), 80, "testGroup", false, false, false, ""); + Rule rule = new Rule(APPLICATION_NAME, SERVICE_TYPE, CheckerCategory.ERROR_COUNT.getName(), 50, "testGroup", false, false, false, ""); + Map> dataSourceAlarmVOMap = Map.ofEntries( + Map.entry("local_tomcat", List.of( + new DataSourceAlarmVO(1, "database1", 40, 100), + new DataSourceAlarmVO(2, "database2", 10, 100), + new DataSourceAlarmVO(3, "database3", 20, 100) + )) + ); + + when(dataSourceDataCollector.getDataSourceConnectionUsageRate()).thenReturn(dataSourceAlarmVOMap); + DataSourceConnectionUsageRateChecker checker = new DataSourceConnectionUsageRateChecker(dataSourceDataCollector, rule); - DataSourceDataCollector collector = new DataSourceDataCollector(DataCollectorCategory.DATA_SOURCE_STAT, mockDataSourceDao, mockAgentIds, CURRENT_TIME_MILLIS, INTERVAL_MILLIS); - DataSourceConnectionUsageRateChecker checker = new DataSourceConnectionUsageRateChecker(collector, rule); checker.check(); Assertions.assertFalse(checker.isDetected()); @@ -108,49 +105,4 @@ public void checkTest2() { assertThat(smsMessage).isEmpty(); } - private DataSourceListBo createDataSourceListBo(int id, int activeConnectionSize, int maxConnectionSize, int numValues) { - DataSourceListBo dataSourceListBo = new DataSourceListBo(); - dataSourceListBo.setAgentId(AGENT_ID); - dataSourceListBo.setStartTimestamp(START_TIME_MILLIS); - dataSourceListBo.setTimestamp(CURRENT_TIME_MILLIS); - - List timestamps = createTimestamps(CURRENT_TIME_MILLIS, numValues); - - for (int i = 0; i < numValues; i++) { - DataSourceBo dataSourceBo = new DataSourceBo(); - dataSourceBo.setAgentId(AGENT_ID); - dataSourceBo.setStartTimestamp(START_TIME_MILLIS); - dataSourceBo.setTimestamp(timestamps.get(i)); - - dataSourceBo.setId(id); - dataSourceBo.setServiceTypeCode(ServiceType.UNKNOWN.getCode()); - dataSourceBo.setDatabaseName("name-" + id); - dataSourceBo.setJdbcUrl("jdbcurl-" + id); - dataSourceBo.setActiveConnectionSize(activeConnectionSize); - dataSourceBo.setMaxConnectionSize(maxConnectionSize); - - dataSourceListBo.add(dataSourceBo); - } - - return dataSourceListBo; - } - - private List createTimestamps(long initialTimestamp, int numValues) { - long minTimestampInterval = TIMESTAMP_INTERVAL - 5L; - long maxTimestampInterval = TIMESTAMP_INTERVAL + 5L; - return createIncreasingValues(initialTimestamp, initialTimestamp + 1, minTimestampInterval, maxTimestampInterval, numValues); - } - - private List createIncreasingValues(long minValue, long maxValue, long minIncrement, long maxIncrement, int numValues) { - List values = new ArrayList<>(numValues); - long value = random.nextLong(minValue, maxValue); - values.add(value); - for (int i = 0; i < numValues - 1; i++) { - long increment = random.nextLong(minIncrement, maxIncrement); - value = value + increment; - values.add(value); - } - return values; - } - } diff --git a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/FileDescriptorCheckerTest.java b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/FileDescriptorCheckerTest.java index 2c59bcc9e142..4d74fefe51bf 100644 --- a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/FileDescriptorCheckerTest.java +++ b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/FileDescriptorCheckerTest.java @@ -16,9 +16,11 @@ package com.navercorp.pinpoint.batch.alarm.checker; -import com.navercorp.pinpoint.batch.alarm.collector.FileDescriptorDataCollector; +import com.navercorp.pinpoint.batch.alarm.collector.pinot.FileDescriptorDataCollector; import com.navercorp.pinpoint.web.alarm.vo.Rule; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.Map; @@ -30,6 +32,7 @@ /** * @author minwoo.jung */ +@ExtendWith({MockitoExtension.class}) public class FileDescriptorCheckerTest { @Test diff --git a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/GcCountCheckerTest.java b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/GcCountCheckerTest.java deleted file mode 100644 index 7fabbf226bc0..000000000000 --- a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/GcCountCheckerTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2014 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.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.util.time.Range; -import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; -import com.navercorp.pinpoint.web.vo.Application; -import org.junit.jupiter.api.BeforeAll; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -public class GcCountCheckerTest { - - - private static final String SERVICE_NAME = "local_service"; - private static final String SERVICE_TYPE = "tomcat"; - - private static ApplicationIndexDao applicationIndexDao; - - private static AgentStatDao jvmGcDao; - - private static AgentStatDao cpuLoadDao; - - @BeforeAll - public static void before() { - jvmGcDao = new AgentStatDao<>() { - - @Override - public String getChartType() { - return AgentStatType.JVM_GC.getChartType(); - } - - @Override - public List getAgentStatList(String agentId, Range range) { - List jvmGcs = new ArrayList<>(); - - for (int i = 36; i > 0; i--) { - JvmGcBo jvmGc = new JvmGcBo(); - jvmGc.setGcOldCount(i); - jvmGcs.add(jvmGc); - } - - return jvmGcs; - } - - @Override - public boolean agentStatExists(String agentId, Range range) { - return true; - } - }; - - cpuLoadDao = new AgentStatDao<>() { - - @Override - public String getChartType() { - return AgentStatType.CPU_LOAD.getChartType(); - } - - @Override - public List getAgentStatList(String agentId, Range range) { - return Collections.emptyList(); - } - - @Override - public boolean agentStatExists(String agentId, Range range) { - return false; - } - }; - - applicationIndexDao = new ApplicationIndexDao() { - - @Override - public List selectAllApplicationNames() { - throw new UnsupportedOperationException(); - } - - @Override - public List selectApplicationName(String applicationName) { - throw new UnsupportedOperationException(); - } - - @Override - public List selectAgentIds(String applicationName) { - if (SERVICE_NAME.equals(applicationName)) { - return List.of("local_tomcat"); - } - - throw new IllegalArgumentException(); - } - - @Override - public void deleteApplicationName(String applicationName) { - throw new UnsupportedOperationException(); - } - - @Override - public void deleteAgentIds(Map> applicationAgentIdMap) { - throw new UnsupportedOperationException(); - } - - @Override - public void deleteAgentId(String applicationName, String agentId) { - throw new UnsupportedOperationException(); - } - - }; - } - - -// @Test -// public void checkTest1() { -// Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.GC_COUNT.getName(), 35, "testGroup", 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 GcCountChecker(collector, rule); -// -// checker.check(); -// assertTrue(checker.isDetected()); -// } -// -// @Test -// public void checkTest2() { -// Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.GC_COUNT.getName(), 36, "testGroup", 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 GcCountChecker(collector, rule); -// -// checker.check(); -// assertFalse(checker.isDetected()); -// } - -} diff --git a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/HeapUsageRateCheckerTest.java b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/HeapUsageRateCheckerTest.java index dd549b9a6b26..136b6325e47d 100644 --- a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/HeapUsageRateCheckerTest.java +++ b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/HeapUsageRateCheckerTest.java @@ -16,100 +16,59 @@ package com.navercorp.pinpoint.batch.alarm.checker; -import com.navercorp.pinpoint.batch.alarm.DataCollectorFactory; -import com.navercorp.pinpoint.batch.alarm.collector.AgentStatDataCollector; -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.util.time.Range; +import com.navercorp.pinpoint.batch.alarm.collector.pinot.HeapDataCollector; 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.dao.stat.AgentStatDao; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; -import java.util.ArrayList; -import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; +@ExtendWith({MockitoExtension.class}) public class HeapUsageRateCheckerTest { private static final String SERVICE_NAME = "local_service"; private static final String SERVICE_TYPE = "tomcat"; - private static final List mockAgentIds = List.of("local_tomcat"); - - private static AgentStatDao jvmGcDao; - - private static AgentStatDao cpuLoadDao; - - @BeforeAll - public static void before() { - jvmGcDao = new AgentStatDao<>() { - - @Override - public String getChartType() { - return AgentStatType.JVM_GC.getChartType(); - } - - @Override - public List getAgentStatList(String agentId, Range range) { - List jvmGcs = new ArrayList<>(); - - for (int i = 0; i < 36; i++) { - JvmGcBo jvmGcBo = new JvmGcBo(); - jvmGcBo.setHeapUsed(70L); - jvmGcBo.setHeapMax(100L); - - jvmGcs.add(jvmGcBo); - } - - return jvmGcs; - } - - @Override - public boolean agentStatExists(String agentId, Range range) { - return true; - } - }; - - cpuLoadDao = new AgentStatDao<>() { - @Override - public String getChartType() { - return AgentStatType.CPU_LOAD.getChartType(); - } - - @Override - public List getAgentStatList(String agentId, Range range) { - return Collections.emptyList(); - } - - @Override - public boolean agentStatExists(String agentId, Range range) { - return false; - } - }; - } + @Mock + HeapDataCollector heapDataCollector; @Test public void checkTest1() { Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.HEAP_USAGE_RATE.getName(), 70, "testGroup", false, false, false, ""); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, jvmGcDao, cpuLoadDao, mockAgentIds, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); - AgentChecker checker = new HeapUsageRateChecker(collector, rule); + AgentChecker checker = new HeapUsageRateChecker(heapDataCollector, rule); + Map heapUsageRateMap = Map.ofEntries( + Map.entry("local_tomcat01", 71L), + Map.entry("local_tomcat02", 70L), + Map.entry("local_tomcat03", 60L) + ); + + when(heapDataCollector.getHeapUsageRate()).thenReturn(heapUsageRateMap); 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, ""); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, jvmGcDao, cpuLoadDao, mockAgentIds, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); - AgentChecker checker = new HeapUsageRateChecker(collector, rule); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.HEAP_USAGE_RATE.getName(), 70, "testGroup", false, false, false, ""); + AgentChecker checker = new HeapUsageRateChecker(heapDataCollector, rule); + + Map heapUsageRateMap = Map.ofEntries( + Map.entry("local_tomcat01", 50L), + Map.entry("local_tomcat02", 40L), + Map.entry("local_tomcat03", 60L) + ); + + when(heapDataCollector.getHeapUsageRate()).thenReturn(heapUsageRateMap); checker.check(); assertFalse(checker.isDetected()); diff --git a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/JvmCpuUsageRateCheckerTest.java b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/JvmCpuUsageRateCheckerTest.java index e3ce77b03aa1..5ef23e04bc98 100644 --- a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/JvmCpuUsageRateCheckerTest.java +++ b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/JvmCpuUsageRateCheckerTest.java @@ -16,88 +16,43 @@ package com.navercorp.pinpoint.batch.alarm.checker; -import com.navercorp.pinpoint.batch.alarm.DataCollectorFactory; -import com.navercorp.pinpoint.batch.alarm.collector.AgentStatDataCollector; -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.util.time.Range; +import com.navercorp.pinpoint.batch.alarm.collector.pinot.JvmCpuDataCollector; 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.dao.stat.AgentStatDao; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; -import java.util.ArrayList; -import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; +@ExtendWith({MockitoExtension.class}) public class JvmCpuUsageRateCheckerTest { private static final String SERVICE_NAME = "local_service"; private static final String SERVICE_TYPE = "tomcat"; - private static final List mockAgentIds = List.of("local_tomcat"); - - - private static AgentStatDao jvmGcDao; - - private static AgentStatDao cpuLoadDao; - - @BeforeAll - public static void before() { - jvmGcDao = new AgentStatDao<>() { - - @Override - public String getChartType() { - return AgentStatType.JVM_GC.getChartType(); - } - - @Override - public List getAgentStatList(String agentId, Range range) { - return Collections.emptyList(); - } - - @Override - public boolean agentStatExists(String agentId, Range range) { - return false; - } - }; - - cpuLoadDao = new AgentStatDao<>() { - @Override - public String getChartType() { - return AgentStatType.CPU_LOAD.getChartType(); - } - - public List getAgentStatList(String agentId, Range range) { - List cpuLoads = new ArrayList<>(); - - for (int i = 0; i < 36; i++) { - CpuLoadBo cpuLoad = new CpuLoadBo(); - cpuLoad.setJvmCpuLoad(0.6); - cpuLoads.add(cpuLoad); - } - - return cpuLoads; - } - - @Override - public boolean agentStatExists(String agentId, Range range) { - return true; - } - }; - } + @Mock + JvmCpuDataCollector jvmCpuDataCollector; @Test public void checkTest1() { Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.JVM_CPU_USAGE_RATE.getName(), 60, "testGroup", false, false, false, ""); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, jvmGcDao, cpuLoadDao, mockAgentIds, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); - AgentChecker checker = new JvmCpuUsageRateChecker(collector, rule); + + JvmCpuUsageRateChecker checker = new JvmCpuUsageRateChecker(jvmCpuDataCollector, rule); + Map jvmCpuUsageRate = Map.ofEntries( + Map.entry("local_tomcat01", 71L), + Map.entry("local_tomcat02", 72L), + Map.entry("local_tomcat03", 73L) + ); + + when(jvmCpuDataCollector.getJvmCpuUsageRate()).thenReturn(jvmCpuUsageRate); checker.check(); assertTrue(checker.isDetected()); @@ -105,9 +60,16 @@ public void checkTest1() { @Test public void checkTest2() { - Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.JVM_CPU_USAGE_RATE.getName(), 61, "testGroup", false, false, false, ""); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, jvmGcDao, cpuLoadDao, mockAgentIds, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); - AgentChecker checker = new JvmCpuUsageRateChecker(collector, rule); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.JVM_CPU_USAGE_RATE.getName(), 60, "testGroup", false, false, false, ""); + + JvmCpuUsageRateChecker checker = new JvmCpuUsageRateChecker(jvmCpuDataCollector, rule); + Map jvmCpuUsageRate = Map.ofEntries( + Map.entry("local_tomcat01", 51L), + Map.entry("local_tomcat02", 52L), + Map.entry("local_tomcat03", 53L) + ); + + when(jvmCpuDataCollector.getJvmCpuUsageRate()).thenReturn(jvmCpuUsageRate); checker.check(); assertFalse(checker.isDetected()); diff --git a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/SystemCpuUsageRateCheckerTest.java b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/SystemCpuUsageRateCheckerTest.java index c8bd06785f12..07f813f1a7c2 100644 --- a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/SystemCpuUsageRateCheckerTest.java +++ b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/checker/SystemCpuUsageRateCheckerTest.java @@ -16,51 +16,62 @@ package com.navercorp.pinpoint.batch.alarm.checker; -import com.navercorp.pinpoint.batch.alarm.collector.AgentStatDataCollector; +import com.navercorp.pinpoint.batch.alarm.collector.pinot.SystemCpuDataCollector; +import com.navercorp.pinpoint.web.alarm.CheckerCategory; import com.navercorp.pinpoint.web.alarm.vo.Rule; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import java.util.HashMap; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /** * @author minwoo.jung */ +@ExtendWith({MockitoExtension.class}) public class SystemCpuUsageRateCheckerTest { + private static final String SERVICE_NAME = "local_service"; + private static final String SERVICE_TYPE = "tomcat"; + + @Mock + SystemCpuDataCollector systemCpuDataCollector; + @Test public void checkTest() { - Rule rule = new Rule(); - rule.setThreshold(10); - AgentStatDataCollector agentStatDataCollector = mock(AgentStatDataCollector.class); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SYSTEM_CPU_USAGE_RATE.getName(), 10, "testGroup", false, false, false, ""); - Map result = Map.ofEntries( - Map.entry("testAgent1", 30L), - Map.entry("testAgent2", 50L)); + Map systemCpuUsageRate = Map.ofEntries( + Map.entry("local_tomcat01", 21L), + Map.entry("local_tomcat02", 22L), + Map.entry("local_tomcat03", 23L) + ); + when(systemCpuDataCollector.getSystemCpuUsageRate()).thenReturn(systemCpuUsageRate); - when(agentStatDataCollector.getSystemCpuUsageRate()).thenReturn(result); - SystemCpuUsageRateChecker systemCpuUsageRateChecker = new SystemCpuUsageRateChecker(agentStatDataCollector, rule); + SystemCpuUsageRateChecker systemCpuUsageRateChecker = new SystemCpuUsageRateChecker(systemCpuDataCollector, rule); systemCpuUsageRateChecker.check(); assertTrue(systemCpuUsageRateChecker.isDetected()); } @Test public void check2Test() { - Rule rule = new Rule(); - rule.setThreshold(70); - AgentStatDataCollector agentStatDataCollector = mock(AgentStatDataCollector.class); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SYSTEM_CPU_USAGE_RATE.getName(), 70, "testGroup", false, false, false, ""); - Map result = Map.ofEntries( - Map.entry("testAgent1", 30L), - Map.entry("testAgent2", 50L)); + Map systemCpuUsageRate = Map.ofEntries( + Map.entry("local_tomcat01", 30L), + Map.entry("local_tomcat02", 50L), + Map.entry("local_tomcat03", 40L) + ); + when(systemCpuDataCollector.getSystemCpuUsageRate()).thenReturn(systemCpuUsageRate); - when(agentStatDataCollector.getSystemCpuUsageRate()).thenReturn(result); - SystemCpuUsageRateChecker systemCpuUsageRateChecker = new SystemCpuUsageRateChecker(agentStatDataCollector, rule); + SystemCpuUsageRateChecker systemCpuUsageRateChecker = new SystemCpuUsageRateChecker(systemCpuDataCollector, rule); systemCpuUsageRateChecker.check(); assertFalse(systemCpuUsageRateChecker.isDetected()); } diff --git a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/collector/FileDescriptorDataCollectorTest.java b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/collector/FileDescriptorDataCollectorTest.java deleted file mode 100644 index 090066feaf0b..000000000000 --- a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/collector/FileDescriptorDataCollectorTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2019 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.collector; - -import com.navercorp.pinpoint.batch.alarm.DataCollectorFactory; -import com.navercorp.pinpoint.common.server.bo.stat.FileDescriptorBo; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.web.alarm.DataCollectorCategory; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.Map; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * @author minwoo.jung - */ -public class FileDescriptorDataCollectorTest { - - @Test - public void collect() { - String agentId1 = "testAgent1"; - String agentId2 = "testAgent2"; - - List agentList = List.of(agentId1, agentId2); - - @SuppressWarnings("unchecked") - AgentStatDao fileDescriptorDao = (AgentStatDao) mock(AgentStatDao.class); - long timeStamp = 1558936971494L; - Range range = Range.between(timeStamp - DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN, timeStamp); - - FileDescriptorBo fileDescriptorBo1_1 = new FileDescriptorBo(); - fileDescriptorBo1_1.setOpenFileDescriptorCount(200); - FileDescriptorBo fileDescriptorBo1_2 = new FileDescriptorBo(); - fileDescriptorBo1_2.setOpenFileDescriptorCount(300); - FileDescriptorBo fileDescriptorBo1_3 = new FileDescriptorBo(); - fileDescriptorBo1_3.setOpenFileDescriptorCount(400); - - List fileDescriptorBoList1 = List.of( - fileDescriptorBo1_1, - fileDescriptorBo1_2, - fileDescriptorBo1_3 - ); - when(fileDescriptorDao.getAgentStatList(agentId1, range)).thenReturn(fileDescriptorBoList1); - - FileDescriptorBo fileDescriptorBo2_1 = new FileDescriptorBo(); - fileDescriptorBo2_1.setOpenFileDescriptorCount(250); - FileDescriptorBo fileDescriptorBo2_2 = new FileDescriptorBo(); - fileDescriptorBo2_2.setOpenFileDescriptorCount(350); - FileDescriptorBo fileDescriptorBo2_3 = new FileDescriptorBo(); - fileDescriptorBo2_3.setOpenFileDescriptorCount(450); - List fileDescriptorBoList2 = List.of( - fileDescriptorBo2_1, - fileDescriptorBo2_2, - fileDescriptorBo2_3 - ); - when(fileDescriptorDao.getAgentStatList(agentId2, range)).thenReturn(fileDescriptorBoList2); - - FileDescriptorDataCollector fileDescriptorDataCollector = new FileDescriptorDataCollector( - DataCollectorCategory.FILE_DESCRIPTOR, - fileDescriptorDao, - agentList, - timeStamp, - DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN - ); - - fileDescriptorDataCollector.collect(); - Map fileDescriptorCount = fileDescriptorDataCollector.getFileDescriptorCount(); - Assertions.assertThat(fileDescriptorCount) - .hasSize(2) - .containsEntry(agentId1, 300L) - .containsEntry(agentId2, 350L); - } -} \ No newline at end of file diff --git a/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/collector/pinot/FileDescriptorDataCollectorTest.java b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/collector/pinot/FileDescriptorDataCollectorTest.java new file mode 100644 index 000000000000..99f8ada0a3bb --- /dev/null +++ b/batch/src/test/java/com/navercorp/pinpoint/batch/alarm/collector/pinot/FileDescriptorDataCollectorTest.java @@ -0,0 +1,70 @@ +/* + * Copyright 2025 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.collector.pinot; + +import com.navercorp.pinpoint.batch.alarm.DataCollectorFactory; +import com.navercorp.pinpoint.batch.alarm.dao.AlarmDao; +import com.navercorp.pinpoint.batch.alarm.vo.AgentUsage; +import com.navercorp.pinpoint.common.server.util.time.Range; +import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.web.alarm.DataCollectorCategory; +import com.navercorp.pinpoint.web.vo.Application; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; +import java.util.Map; + +import static org.mockito.Mockito.when; + +/** + * @author minwoo-jung + */ +@ExtendWith({MockitoExtension.class}) +class FileDescriptorDataCollectorTest { + + @Mock + AlarmDao alarmDao; + + @Test + public void collect() { + Application application = new Application("test", ServiceType.STAND_ALONE); + long now = System.currentTimeMillis(); + Range range = Range.unchecked(now - DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN, now); + FileDescriptorDataCollector fileDescriptorDataCollector = new FileDescriptorDataCollector(DataCollectorCategory.FILE_DESCRIPTOR, alarmDao, application, now, DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); + + List agentUsageList = List.of( + new AgentUsage("testAgent1", 100D), + new AgentUsage("testAgent2", 200D), + new AgentUsage("testAgent3", 150D), + new AgentUsage("testAgent4", 200D), + new AgentUsage("testAgent5", 300D), + new AgentUsage("testAgent6", 400D) + ); + when(alarmDao.selectAvg(application.getName(), FileDescriptorDataCollector.METRIC_NAME, FileDescriptorDataCollector.FIELD_NAME, range)).thenReturn(agentUsageList); + fileDescriptorDataCollector.collect(); + + Map fileDescriptorCount = fileDescriptorDataCollector.getFileDescriptorCount(); + Assertions.assertThat(fileDescriptorCount) + .hasSize(6) + .containsEntry("testAgent1", 100L) + .containsEntry("testAgent2", 200L); + } +} \ No newline at end of file diff --git a/collector-starter/src/main/resources/application.yml b/collector-starter/src/main/resources/application.yml index 099d979eaceb..0084ce9c6e82 100644 --- a/collector-starter/src/main/resources/application.yml +++ b/collector-starter/src/main/resources/application.yml @@ -17,5 +17,7 @@ pinpoint: enabled: true hbase: enabled: true + otlpmetric: + enabled: true realtime: enabled: true \ No newline at end of file diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/AgentStatDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/AgentStatDao.java deleted file mode 100644 index 87a5aab4766d..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/AgentStatDao.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2016 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.collector.dao; - -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -@Repository -public interface AgentStatDao { - void insert(String agentId, List agentStatDataPoints); - - void dispatch(AgentStatBo agentStatBo); -} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/stat/DefaultAgentStatDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/stat/DefaultAgentStatDao.java deleted file mode 100644 index f352aa124776..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/stat/DefaultAgentStatDao.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.navercorp.pinpoint.collector.dao.hbase.stat; - -import com.navercorp.pinpoint.collector.dao.AgentStatDao; -import com.navercorp.pinpoint.collector.util.CollectorUtils; -import com.navercorp.pinpoint.common.hbase.HbaseTable; -import com.navercorp.pinpoint.common.hbase.TableNameProvider; -import com.navercorp.pinpoint.common.hbase.async.HbasePutWriter; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatHbaseOperationFactory; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatSerializer; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.client.Put; - -import java.util.List; -import java.util.Objects; -import java.util.function.Function; - -public class DefaultAgentStatDao implements AgentStatDao { - - private final AgentStatType agentStatType; - private final HbaseTable tableName; - private final Function> dataPointFunction; - private final HbasePutWriter putWriter; - private final TableNameProvider tableNameProvider; - private final AgentStatHbaseOperationFactory operations; - private final AgentStatSerializer serializer; - - protected Function, List> preprocessor = Function.identity(); - - public DefaultAgentStatDao(AgentStatType agentStatType, - HbaseTable tableName, - Function> dataPointFunction, - HbasePutWriter putWriter, - TableNameProvider tableNameProvider, - AgentStatHbaseOperationFactory operations, - AgentStatSerializer serializer) { - this.agentStatType = Objects.requireNonNull(agentStatType, "agentStatType"); - this.tableName = Objects.requireNonNull(tableName, "tableName"); - this.dataPointFunction = Objects.requireNonNull(dataPointFunction, "dataPointFunction"); - - this.putWriter = Objects.requireNonNull(putWriter, "putWriter"); - - this.tableNameProvider = Objects.requireNonNull(tableNameProvider, "tableNameProvider"); - this.operations = Objects.requireNonNull(operations, "operations"); - this.serializer = Objects.requireNonNull(serializer, "serializer"); - } - - - - @Override - public void insert(String agentId, List dataPoints) { - Objects.requireNonNull(agentId, "agentId"); - Objects.requireNonNull(dataPoints, "dataPoints"); - - // Assert agentId - CollectorUtils.checkAgentId(agentId); - - if (CollectionUtils.isEmpty(dataPoints)) { - return; - } - - dataPoints = preprocessor.apply(dataPoints); - List puts = this.operations.createPuts(agentId, agentStatType, dataPoints, this.serializer); - if (puts.isEmpty()) { - return; - } - TableName tableName = tableNameProvider.getTableName(this.tableName); - this.putWriter.put(tableName, puts); - } - - @Override - public void dispatch(AgentStatBo agentStatBo) { - Objects.requireNonNull(agentStatBo, "agentStatBo"); - - List dataPoints = this.dataPointFunction.apply(agentStatBo); - insert(agentStatBo.getAgentId(), dataPoints); - } -} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/stat/HBaseDaoConfiguration.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/stat/HBaseDaoConfiguration.java deleted file mode 100644 index 4eec34c2e8a1..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/stat/HBaseDaoConfiguration.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.navercorp.pinpoint.collector.dao.hbase.stat; - -import com.navercorp.pinpoint.collector.dao.AgentStatDao; -import com.navercorp.pinpoint.common.hbase.HbaseTable; -import com.navercorp.pinpoint.common.hbase.TableNameProvider; -import com.navercorp.pinpoint.common.hbase.async.HbasePutWriter; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatHbaseOperationFactory; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatSerializer; -import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -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.DataSourceListBo; -import com.navercorp.pinpoint.common.server.bo.stat.DeadlockThreadCountBo; -import com.navercorp.pinpoint.common.server.bo.stat.DirectBufferBo; -import com.navercorp.pinpoint.common.server.bo.stat.FileDescriptorBo; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; -import com.navercorp.pinpoint.common.server.bo.stat.LoadedClassBo; -import com.navercorp.pinpoint.common.server.bo.stat.ResponseTimeBo; -import com.navercorp.pinpoint.common.server.bo.stat.TotalThreadCountBo; -import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.List; -import java.util.Objects; -import java.util.function.Function; - -@Configuration -public class HBaseDaoConfiguration { - - private final HbasePutWriter putWriter; - private final HbaseTable hbaseTable = HbaseTable.AGENT_STAT_VER2; - private final TableNameProvider tableNameProvider; - private final AgentStatHbaseOperationFactory operations; - - public HBaseDaoConfiguration(HbasePutWriter putWriter, TableNameProvider tableNameProvider, AgentStatHbaseOperationFactory operations) { - this.putWriter = Objects.requireNonNull(putWriter, "putWriter"); - this.tableNameProvider = Objects.requireNonNull(tableNameProvider, "tableNameProvider"); - this.operations = Objects.requireNonNull(operations, "operations"); - } - - private AgentStatDao newAgentStatDao(AgentStatType agentStatType, Function> dataPointFunction, AgentStatSerializer serializer) { - return new DefaultAgentStatDao<>(agentStatType, hbaseTable, dataPointFunction, - putWriter, tableNameProvider, operations, serializer); - } - - @Bean - public AgentStatDao getActiveTraceDao(AgentStatSerializer serializer) { - return newAgentStatDao(AgentStatType.ACTIVE_TRACE, AgentStatBo::getActiveTraceBos, serializer); - } - - @Bean - public AgentStatDao getCpuLoadDao(AgentStatSerializer serializer) { - return newAgentStatDao(AgentStatType.CPU_LOAD, AgentStatBo::getCpuLoadBos, serializer); - } - - @Bean - public AgentStatDao getDataSourceListDao(AgentStatSerializer serializer) { - return new HbaseDataSourceListDao(putWriter, tableNameProvider, operations, serializer); - } - - @Bean - public AgentStatDao getDeadlockThreadCountDao(AgentStatSerializer serializer) { - return newAgentStatDao(AgentStatType.DEADLOCK, AgentStatBo::getDeadlockThreadCountBos, serializer); - } - - @Bean - public AgentStatDao getDirectBufferDao(AgentStatSerializer serializer) { - return newAgentStatDao(AgentStatType.DIRECT_BUFFER, AgentStatBo::getDirectBufferBos, serializer); - } - - @Bean - public AgentStatDao getFileDescriptorDao(AgentStatSerializer serializer) { - return newAgentStatDao(AgentStatType.FILE_DESCRIPTOR, AgentStatBo::getFileDescriptorBos, serializer); - } - - @Bean - public AgentStatDao getJvmGcDao(AgentStatSerializer serializer) { - return newAgentStatDao(AgentStatType.JVM_GC, AgentStatBo::getJvmGcBos, serializer); - } - - @Bean - public AgentStatDao getJvmGcDetailedDao(AgentStatSerializer serializer) { - return newAgentStatDao(AgentStatType.JVM_GC_DETAILED, AgentStatBo::getJvmGcDetailedBos, serializer); - } - - @Bean - public AgentStatDao getLoadedClassDao(AgentStatSerializer serializer) { - return newAgentStatDao(AgentStatType.LOADED_CLASS, AgentStatBo::getLoadedClassBos, serializer); - } - - @Bean - public AgentStatDao getResponseTimeDao(AgentStatSerializer serializer) { - return newAgentStatDao(AgentStatType.RESPONSE_TIME, AgentStatBo::getResponseTimeBos, serializer); - } - - @Bean - public AgentStatDao getTotalThreadCountDao(AgentStatSerializer serializer) { - return newAgentStatDao(AgentStatType.TOTAL_THREAD, AgentStatBo::getTotalThreadCountBos, serializer); - } - - @Bean - public AgentStatDao getTransactionDao(AgentStatSerializer serializer) { - return newAgentStatDao(AgentStatType.TRANSACTION, AgentStatBo::getTransactionBos, serializer); - } -} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/stat/HbaseDataSourceListDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/stat/HbaseDataSourceListDao.java deleted file mode 100644 index 135d8f74a217..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/stat/HbaseDataSourceListDao.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2017 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.collector.dao.hbase.stat; - -import com.navercorp.pinpoint.common.hbase.HbaseTable; -import com.navercorp.pinpoint.common.hbase.TableNameProvider; -import com.navercorp.pinpoint.common.hbase.async.HbasePutWriter; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatHbaseOperationFactory; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatSerializer; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatUtils; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceBo; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceListBo; -import org.apache.commons.collections4.map.MultiKeyMap; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * @author Taejin Koo - */ -public class HbaseDataSourceListDao extends DefaultAgentStatDao { - - public HbaseDataSourceListDao(HbasePutWriter putWriter, - TableNameProvider tableNameProvider, - AgentStatHbaseOperationFactory operationFactory, - AgentStatSerializer serializer) { - super(AgentStatType.DATASOURCE, HbaseTable.AGENT_STAT_VER2, AgentStatBo::getDataSourceListBos, - putWriter, tableNameProvider, operationFactory, serializer); - this.preprocessor = this::reorderDataSourceListBos; - } - - private List reorderDataSourceListBos(List dataSourceListBos) { - // reorder dataSourceBo using id and timeSlot - MultiKeyMap dataSourceListBoMap = new MultiKeyMap<>(); - - for (DataSourceListBo dataSourceListBo : dataSourceListBos) { - for (DataSourceBo dataSourceBo : dataSourceListBo.getList()) { - int id = dataSourceBo.getId(); - long timestamp = dataSourceBo.getTimestamp(); - long timeSlot = AgentStatUtils.getBaseTimestamp(timestamp); - - DataSourceListBo mappedDataSourceListBo = dataSourceListBoMap.get(id, timeSlot); - if (mappedDataSourceListBo == null) { - mappedDataSourceListBo = new DataSourceListBo(); - mappedDataSourceListBo.setAgentId(dataSourceBo.getAgentId()); - mappedDataSourceListBo.setStartTimestamp(dataSourceBo.getStartTimestamp()); - mappedDataSourceListBo.setTimestamp(dataSourceBo.getTimestamp()); - - dataSourceListBoMap.put((long) id, timeSlot, mappedDataSourceListBo); - } - - // set fastest timestamp - if (mappedDataSourceListBo.getTimestamp() > dataSourceBo.getTimestamp()) { - mappedDataSourceListBo.setTimestamp(dataSourceBo.getTimestamp()); - } - - mappedDataSourceListBo.add(dataSourceBo); - } - } - - Collection values = dataSourceListBoMap.values(); - return new ArrayList<>(values); - } - -} \ No newline at end of file diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/HBaseAgentStatService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/HBaseAgentStatService.java deleted file mode 100644 index 53ceb54b5d37..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/HBaseAgentStatService.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2017 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.collector.service; - -import com.navercorp.pinpoint.collector.dao.AgentStatDao; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo; -import jakarta.validation.Valid; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.util.Objects; - -/** - * @author minwoo.jung - */ -@Service("hBaseAgentStatService") -@Validated -@ConditionalOnProperty(value = "pinpoint.modules.collector.inspector.hbase.enabled", havingValue = "true") -public class HBaseAgentStatService implements AgentStatService { - - private final Logger logger = LogManager.getLogger(HBaseAgentStatService.class); - - private final AgentStatDao[] agentStatDaoList; - - public HBaseAgentStatService(AgentStatDao[] agentStatDaoList) { - this.agentStatDaoList = Objects.requireNonNull(agentStatDaoList, "agentStatDaoList"); - - for (AgentStatDao agentStatDao : agentStatDaoList) { - logger.info("AgentStatDaoV2:{}", agentStatDao.getClass().getSimpleName()); - } - } - - @Override - public void save(@Valid AgentStatBo agentStatBo) { - for (AgentStatDao agentStatDao : agentStatDaoList) { - try { - agentStatDao.dispatch(agentStatBo); - } catch (Exception e) { - logger.warn("Error inserting AgentStatBo. Caused:{}", e.getMessage(), e); - } - } - } - -} diff --git a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseColumnFamily.java b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseColumnFamily.java index 1198996d531d..6857f68c74db 100644 --- a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseColumnFamily.java +++ b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseColumnFamily.java @@ -54,15 +54,6 @@ private AgentLifeCycleStatus(HbaseTable hBaseTable, byte[] columnFamilyName) { } } - public static final AgentStatStatistics AGENT_STAT_STATISTICS = new AgentStatStatistics(HbaseTable.AGENT_STAT_VER2, Bytes.toBytes("S")); - public static class AgentStatStatistics extends HbaseColumnFamily { - public static final int TIMESPAN_MS = 5 * 60 * 1000; - - private AgentStatStatistics(HbaseTable hBaseTable, byte[] columnFamilyName) { - super(hBaseTable, columnFamilyName); - } - } - public static final AgentUriStatStatistics AGENT_URI_STAT_STATISTICS = new AgentUriStatStatistics(HbaseTable.AGENT_URI_STAT, Bytes.toBytes("Uri")); public static class AgentUriStatStatistics extends HbaseColumnFamily { public static final int TIMESPAN_MS = 5 * 60 * 1000; @@ -88,15 +79,6 @@ private ApplicationIndex(HbaseTable hBaseTable, byte[] columnFamilyName) { } } - public static final ApplicationStatStatistics APPLICATION_STAT_STATISTICS = new ApplicationStatStatistics(HbaseTable.APPLICATION_STAT_AGGRE, Bytes.toBytes("S")); - public static class ApplicationStatStatistics extends HbaseColumnFamily { - public int TIMESPAN_MS = 5 * 60 * 1000; - - private ApplicationStatStatistics(HbaseTable hBaseTable, byte[] columnFamilyName) { - super(hBaseTable, columnFamilyName); - } - } - public static final ApplicationTraceIndexTrace APPLICATION_TRACE_INDEX_TRACE = new ApplicationTraceIndexTrace(HbaseTable.APPLICATION_TRACE_INDEX, Bytes.toBytes("I")); public static final ApplicationTraceIndexTrace APPLICATION_TRACE_INDEX_META = new ApplicationTraceIndexTrace(HbaseTable.APPLICATION_TRACE_INDEX, Bytes.toBytes("M")); public static class ApplicationTraceIndexTrace extends HbaseColumnFamily { diff --git a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseTable.java b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseTable.java index 07990ce8494f..eb84e83a12f1 100644 --- a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseTable.java +++ b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseTable.java @@ -25,11 +25,9 @@ public enum HbaseTable { AGENTINFO("AgentInfo"), AGENT_EVENT("AgentEvent"), AGENT_LIFECYCLE("AgentLifeCycle"), - AGENT_STAT_VER2("AgentStatV2"), AGENT_URI_STAT("AgentUriStat"), API_METADATA("ApiMetaData"), APPLICATION_INDEX("ApplicationIndex"), - APPLICATION_STAT_AGGRE("ApplicationStatAggre"), APPLICATION_TRACE_INDEX("ApplicationTraceIndex"), HOST_APPLICATION_MAP_VER2("HostApplicationMap_Ver2"), MAP_STATISTICS_CALLEE_VER2("ApplicationMapStatisticsCallee_Ver2"), diff --git a/commons-hbase/src/test/java/com/navercorp/pinpoint/common/hbase/HbaseTableTest.java b/commons-hbase/src/test/java/com/navercorp/pinpoint/common/hbase/HbaseTableTest.java index ca2987508c45..7a1115808f43 100644 --- a/commons-hbase/src/test/java/com/navercorp/pinpoint/common/hbase/HbaseTableTest.java +++ b/commons-hbase/src/test/java/com/navercorp/pinpoint/common/hbase/HbaseTableTest.java @@ -50,14 +50,6 @@ public void agentLifecycleStatusTest() { Assertions.assertArrayEquals(Bytes.toBytes("states"), agentLifecycleStatus.QUALIFIER_STATES); } - @Test - public void agentStatStatisticsTest() { - HbaseColumnFamily.AgentStatStatistics agentStatStatistics = HbaseColumnFamily.AGENT_STAT_STATISTICS; - Assertions.assertArrayEquals(Bytes.toBytes("S"), agentStatStatistics.getName()); - Assertions.assertEquals("AgentStatV2", agentStatStatistics.getTable().getName()); - Assertions.assertEquals(5 * 60 * 1000, agentStatStatistics.TIMESPAN_MS); - } - @Test public void apiMetadataApiTest() { HbaseColumnFamily.ApiMetadata apiMetadataApi = HbaseColumnFamily.API_METADATA_API; @@ -73,14 +65,6 @@ public void applicationIndexAgentsTest() { Assertions.assertEquals("ApplicationIndex", applicationIndexAgents.getTable().getName()); } - @Test - public void applicationStatStatisticsTest() { - HbaseColumnFamily.ApplicationStatStatistics applicationStatStatistics = HbaseColumnFamily.APPLICATION_STAT_STATISTICS; - Assertions.assertArrayEquals(Bytes.toBytes("S"), applicationStatStatistics.getName()); - Assertions.assertEquals("ApplicationStatAggre", applicationStatStatistics.getTable().getName()); - Assertions.assertEquals(5 * 60 * 1000, applicationStatStatistics.TIMESPAN_MS); - } - @Test public void applicationTraceIndexTraceTest() { HbaseColumnFamily.ApplicationTraceIndexTrace applicationTraceIndexTrace = HbaseColumnFamily.APPLICATION_TRACE_INDEX_TRACE; diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/CommonsHbaseConfiguration.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/CommonsHbaseConfiguration.java index 3b875a85d306..cc5ac0ad5387 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/CommonsHbaseConfiguration.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/CommonsHbaseConfiguration.java @@ -1,6 +1,5 @@ package com.navercorp.pinpoint.common.server; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.config.AgentStatSerializeConfiguration; import com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.config.SpanSerializeConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -9,7 +8,6 @@ @Configuration @Import({ SpanSerializeConfiguration.class, - AgentStatSerializeConfiguration.class, }) @ComponentScan(basePackages = { "com.navercorp.pinpoint.common.server.bo.codec", diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatCodec.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatCodec.java deleted file mode 100644 index 16ee8ea807b5..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatCodec.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -public interface AgentStatCodec { - - byte getVersion(); - - - void encodeValues(Buffer valueBuffer, List agentStatDataPoints); - - List decodeValues(Buffer valueBuffer, AgentStatDecodingContext decodingContext); - - - interface CodecEncoder { - - void addValue(T agentStatDataPoint); - - void encode(Buffer valueBuffer); - - } - - interface CodecDecoder { - - void decode(Buffer valueBuffer, AgentStatHeaderDecoder headerDecoder, int valueSize); - - T getValue(int index); - - } - -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatCoderConfiguration.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatCoderConfiguration.java deleted file mode 100644 index a433a83a635b..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatCoderConfiguration.java +++ /dev/null @@ -1,164 +0,0 @@ -package com.navercorp.pinpoint.common.server.bo.codec.stat; - -import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; -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.DeadlockThreadCountBo; -import com.navercorp.pinpoint.common.server.bo.stat.DirectBufferBo; -import com.navercorp.pinpoint.common.server.bo.stat.FileDescriptorBo; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; -import com.navercorp.pinpoint.common.server.bo.stat.LoadedClassBo; -import com.navercorp.pinpoint.common.server.bo.stat.ResponseTimeBo; -import com.navercorp.pinpoint.common.server.bo.stat.TotalThreadCountBo; -import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.List; - -@Configuration -public class AgentStatCoderConfiguration { - - @Bean - public AgentStatDecoder getAgentActiveTraceDecoder(List> codecs) { - return new AgentStatDecoder<>(codecs); - } - - @Bean - public AgentStatEncoder getAgentActiveTraceEncoder(AgentStatCodec codec) { - return new AgentStatEncoder<>(codec); - } - - // ---------------- - - @Bean - public AgentStatDecoder getAgentCpuLoadDecoder(List> codecs) { - return new AgentStatDecoder<>(codecs); - } - - @Bean - public AgentStatEncoder getAgentCpuLoadEncoder(AgentStatCodec codec) { - return new AgentStatEncoder<>(codec); - } - - // ---------------- - - @Bean - public AgentStatDecoder getAgentDataSourceDecoder(List> codecs) { - return new AgentStatDecoder<>(codecs); - } - - @Bean - public AgentStatEncoder getAgentDataSourceEncoder(AgentStatCodec codec) { - return new AgentStatEncoder<>(codec); - } - - // ---------------- - - @Bean - public AgentStatDecoder getAgentDeadlockDecoder(List> codecs) { - return new AgentStatDecoder<>(codecs); - } - - @Bean - public AgentStatEncoder getAgentDeadlockEncoder(AgentStatCodec codec) { - return new AgentStatEncoder<>(codec); - } - - // ---------------- - - @Bean - public AgentStatDecoder getAgentDirectBufferDecoder(List> codecs) { - return new AgentStatDecoder<>(codecs); - } - - @Bean - public AgentStatEncoder getAgentDirectBufferEncoder(AgentStatCodec codec) { - return new AgentStatEncoder<>(codec); - } - - // ---------------- - - @Bean - public AgentStatDecoder getAgentFileDescriptorDecoder(List> codecs) { - return new AgentStatDecoder<>(codecs); - } - - @Bean - public AgentStatEncoder getAgentFileDescriptorEncoder(AgentStatCodec codec) { - return new AgentStatEncoder<>(codec); - } - - // ---------------- - - @Bean - public AgentStatDecoder getAgentJvmGcDecoder(List> codecs) { - return new AgentStatDecoder<>(codecs); - } - - @Bean - public AgentStatEncoder getAgentJvmGcEncoder(AgentStatCodec codec) { - return new AgentStatEncoder<>(codec); - } - - // ---------------- - - @Bean - public AgentStatDecoder getAgentJvmGcDetailedDecoder(List> codecs) { - return new AgentStatDecoder<>(codecs); - } - - @Bean - public AgentStatEncoder getAgentJvmGcDetailedEncoder(AgentStatCodec codec) { - return new AgentStatEncoder<>(codec); - } - - // ---------------- - - @Bean - public AgentStatDecoder getAgentLoadedClassCountDecoder(List> codecs) { - return new AgentStatDecoder<>(codecs); - } - - @Bean - public AgentStatEncoder getAgentLoadedClassCountEncoder(AgentStatCodec codec) { - return new AgentStatEncoder<>(codec); - } - - // ---------------- - - @Bean - public AgentStatDecoder getAgentResponseTimeDecoder(List> codecs) { - return new AgentStatDecoder<>(codecs); - } - - @Bean - public AgentStatEncoder getAgentResponseTimeEncoder(AgentStatCodec codec) { - return new AgentStatEncoder<>(codec); - } - - // ---------------- - - @Bean - public AgentStatDecoder getAgentTotalThreadCountDecoder(List> codecs) { - return new AgentStatDecoder<>(codecs); - } - - @Bean - public AgentStatEncoder getAgentTotalThreadCountEncoder(AgentStatCodec codec) { - return new AgentStatEncoder<>(codec); - } - - // ---------------- - - @Bean - public AgentStatDecoder getAgentTransactionDecoder(List> codecs) { - return new AgentStatDecoder<>(codecs); - } - - @Bean - public AgentStatEncoder getAgentTransactionEncoder(AgentStatCodec codec) { - return new AgentStatEncoder<>(codec); - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatDataPointCodec.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatDataPointCodec.java deleted file mode 100644 index c51f64d9620d..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatDataPointCodec.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author HyunGil Jeong - */ -@Component -public class AgentStatDataPointCodec { - - public void encodeTimestamps(Buffer buffer, List timestamps) { - long prevTimestamp = timestamps.get(0); - long prevDelta = 0; - // skip first timestamp as this value is encoded as the qualifier and delta is meaningless - for (int i = 1; i < timestamps.size(); i++) { - long timestamp = timestamps.get(i); - long timestampDelta = timestamp - prevTimestamp; - buffer.putVLong(timestampDelta - prevDelta); - prevTimestamp = timestamp; - prevDelta = timestampDelta; - } - } - - public List decodeTimestamps(long initialTimestamp, Buffer buffer, int numValues) { - List timestamps = new ArrayList<>(numValues); - timestamps.add(initialTimestamp); - long prevTimestamp = initialTimestamp; - long prevDelta = 0; - // loop through numValues - 1 as the first timestamp is gotten from the qualifier - for (int i = 0; i < numValues - 1; i++) { - long timestampDelta = prevDelta + buffer.readVLong(); - long timestamp = prevTimestamp + timestampDelta; - timestamps.add(timestamp); - prevTimestamp = timestamp; - prevDelta = timestampDelta; - } - return timestamps; - } - - public void encodeValues(Buffer buffer, EncodingStrategy encodingStrategy, List values) { - encodingStrategy.encodeValues(buffer, values); - } - - public List decodeValues(Buffer buffer, EncodingStrategy encodingStrategy, int numValues) { - return encodingStrategy.decodeValues(buffer, numValues); - } -} - - diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatDecoder.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatDecoder.java deleted file mode 100644 index 4f2a0909fb94..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatDecoder.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; - -import java.util.List; -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -public class AgentStatDecoder { - - private final AgentStatCodec[] codecs; - - @SuppressWarnings("unchecked") - public AgentStatDecoder(List> codecs) { - Objects.requireNonNull(codecs, "codecs"); - this.codecs = codecs.toArray(new AgentStatCodec[0]); - } - - public long decodeQualifier(Buffer qualifierBuffer) { - return qualifierBuffer.readVLong(); - } - - public List decodeValue(Buffer valueBuffer, AgentStatDecodingContext decodingContext) { - byte version = valueBuffer.readByte(); - for (AgentStatCodec codec : this.codecs) { - if (version == codec.getVersion()) { - return codec.decodeValues(valueBuffer, decodingContext); - } - } - throw new IllegalArgumentException("Unknown version : " + version); - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatEncoder.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatEncoder.java deleted file mode 100644 index 469460022e2b..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatEncoder.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat; - -import com.navercorp.pinpoint.common.buffer.AutomaticBuffer; -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; - -import java.nio.ByteBuffer; -import java.util.List; -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -public class AgentStatEncoder { - - private final AgentStatCodec codec; - - public AgentStatEncoder(AgentStatCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - public ByteBuffer encodeQualifier(long timestampDelta) { - // Variable-length encoding of 5 minutes (300000 ms) takes up max 3 bytes - Buffer qualifierBuffer = new AutomaticBuffer(3); - qualifierBuffer.putVLong(timestampDelta); - return qualifierBuffer.wrapByteBuffer(); - } - - public ByteBuffer encodeValue(List agentStatDataPoints) { - Buffer valueBuffer = new AutomaticBuffer(); - valueBuffer.putByte(this.codec.getVersion()); - codec.encodeValues(valueBuffer, agentStatDataPoints); - return valueBuffer.wrapByteBuffer(); - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/CodecFactory.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/CodecFactory.java deleted file mode 100644 index b8dd76696ebd..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/CodecFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2017 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.common.server.bo.codec.stat; - - -/** - * @author Woonduk Kang(emeroad) - */ -public interface CodecFactory { - - - AgentStatDataPointCodec getCodec(); - - AgentStatCodec.CodecEncoder createCodecEncoder(); - - AgentStatCodec.CodecDecoder createCodecDecoder(); - -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/AgentStatHeaderDecoder.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/AgentStatHeaderDecoder.java deleted file mode 100644 index 52dc556c4ff9..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/AgentStatHeaderDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.header; - -/** - * @author HyunGil Jeong - */ -public interface AgentStatHeaderDecoder { - int getCode(); -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/AgentStatHeaderEncoder.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/AgentStatHeaderEncoder.java deleted file mode 100644 index 3260a4a740d1..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/AgentStatHeaderEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.header; - -/** - * @author HyunGil Jeong - */ -public interface AgentStatHeaderEncoder { - void addCode(int code); - byte[] getHeader(); -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/BitCountingHeaderDecoder.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/BitCountingHeaderDecoder.java deleted file mode 100644 index ee7b2bbb7a4d..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/BitCountingHeaderDecoder.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.header; - -import java.util.BitSet; - -/** - * Bit-counting implementation of {@link AgentStatHeaderDecoder} that decodes - * each code by counting the number of set bits until the next unset bit. - * If all bits are used up, the subsequent {@link #getCode()} invocations will - * simply return 0. - * - *

For example, given a header of 100110, {@link #getCode()} will return 1, - * 0, 2, and 0s afterwards.

- * - * @author HyunGil Jeong - * @see BitCountingHeaderDecoder - */ -public class BitCountingHeaderDecoder implements AgentStatHeaderDecoder { - - private final BitSet headerBitSet; - private int position = 0; - - public BitCountingHeaderDecoder(byte[] header) { - this.headerBitSet = BitSet.valueOf(header); - } - - @Override - public int getCode() { - int fromIndex = this.position; - int toIndex = this.headerBitSet.nextClearBit(this.position); - int numBitsSet = this.headerBitSet.get(fromIndex, toIndex).cardinality(); - this.position = toIndex + 1; - return numBitsSet; - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/BitCountingHeaderEncoder.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/BitCountingHeaderEncoder.java deleted file mode 100644 index 1c7b74547f80..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/BitCountingHeaderEncoder.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.header; - -import java.util.BitSet; - -/** - * Bit-counting implementation of {@link AgentStatHeaderEncoder} that encodes - * each code by setting the number of bits equal to it followed by a 0. - * - *

For example, codes {1, 0, 2} will be encoded as 100110. - * - *

This implementation is best suited for very small code values (ideally - * those that take less than a few bits to encode). It is very inefficient for - * values larger than this, and other implementations should be used in place - * of this. - * - * @author HyunGil Jeong - * @see BitCountingHeaderDecoder - */ -public class BitCountingHeaderEncoder implements AgentStatHeaderEncoder { - - private final BitSet headerBitSet = new BitSet(); - private int position = 0; - - @Override - public void addCode(int code) { - if (code < 0) { - throw new IllegalArgumentException("code must be positive"); - } - int fromIndex = this.position; - int toIndex = this.position + code; - this.headerBitSet.set(fromIndex, toIndex); - this.position = toIndex + 1; - } - - @Override - public byte[] getHeader() { - return headerBitSet.toByteArray(); - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/MathUtils.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/MathUtils.java deleted file mode 100644 index 30c8c14f4b9c..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/MathUtils.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.navercorp.pinpoint.common.server.bo.codec.stat.strategy; - -final class MathUtils { - private MathUtils() { - } - - static int min(int a, int b, int c, int d) { - int min1 = Math.min(a, b); - int min2 = Math.min(c, d); - return Math.min(min1, min2); - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/StrategyAnalyzer.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/StrategyAnalyzer.java deleted file mode 100644 index 60762f5094fe..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/StrategyAnalyzer.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.strategy; - -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -public interface StrategyAnalyzer { - - EncodingStrategy getBestStrategy(); - - List getValues(); - - interface StrategyAnalyzerBuilder { - - StrategyAnalyzerBuilder addValue(T value); - - StrategyAnalyzer build(); - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/StringEncodingStrategy.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/StringEncodingStrategy.java deleted file mode 100644 index d27bc5cb7f35..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/StringEncodingStrategy.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2017 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.common.server.bo.codec.stat.strategy; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.StringTypedBufferHandler; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.StringAlwaysSameValueEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.StringRepeatCountEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.StringValueEncodingStrategy; -import com.navercorp.pinpoint.common.util.BytesUtils; - -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; - -/** - * @author Taejin Koo - */ -public enum StringEncodingStrategy implements EncodingStrategy { - NONE(new StringValueEncodingStrategy(StringTypedBufferHandler.VARIABLE_HANDLER)), - REPEAT_COUNT(new StringRepeatCountEncodingStrategy(StringTypedBufferHandler.VARIABLE_HANDLER)), - ALWAYS_SAME_VALUE(new StringAlwaysSameValueEncodingStrategy(StringTypedBufferHandler.VARIABLE_HANDLER)); - - private final EncodingStrategy delegate; - - private static final Set STRING_ENCODING_STRATEGY = EnumSet.allOf(StringEncodingStrategy.class); - - StringEncodingStrategy(EncodingStrategy delegate) { - this.delegate = delegate; - } - - @Override - public byte getCode() { - return this.delegate.getCode(); - } - - @Override - public void encodeValues(Buffer buffer, List values) { - this.delegate.encodeValues(buffer, values); - } - - @Override - public List decodeValues(Buffer buffer, int numValues) { - return this.delegate.decodeValues(buffer, numValues); - } - - public static StringEncodingStrategy getFromCode(int code) { - for (StringEncodingStrategy encodingStrategy : STRING_ENCODING_STRATEGY) { - if (encodingStrategy.getCode() == (code & 0xFF)) { - return encodingStrategy; - } - } - throw new IllegalArgumentException("Unknown code : " + code); - } - - public static class Analyzer implements StrategyAnalyzer { - - private final EncodingStrategy bestStrategy; - private final List values; - - private Analyzer(EncodingStrategy bestStrategy, List values) { - this.bestStrategy = bestStrategy; - this.values = values; - } - - @Override - public EncodingStrategy getBestStrategy() { - return this.bestStrategy; - } - - @Override - public List getValues() { - return this.values; - } - - public static class Builder implements StrategyAnalyzerBuilder { - - private static final int MAX_BYTES_PER_CHAR_UTF8 = (int) StandardCharsets.UTF_8.newEncoder().maxBytesPerChar(); - - private final List values = new ArrayList<>(); - - private String previousValue = null; - - private int byteSizeValue = 0; - - private int repeatedValueCount = 0; - private int byteSizeRepeatCount = 0; - - - @Override - public StrategyAnalyzerBuilder addValue(String value) { - if (this.values.isEmpty()) { - initializeByteSizes(value); - } else { - updateByteSizes(value); - } - this.previousValue = value; - - this.values.add(value); - return this; - } - - @Override - public StrategyAnalyzer build() { - if (this.repeatedValueCount > 0) { - this.byteSizeRepeatCount += BytesUtils.computeVar32Size(this.repeatedValueCount); - } - EncodingStrategy bestStrategy; - if (repeatedValueCount != 0 && repeatedValueCount == values.size()) { - bestStrategy = ALWAYS_SAME_VALUE; - } else { - int minimumNumBytesUsed = Math.min( - this.byteSizeValue, - this.byteSizeRepeatCount); - if (this.byteSizeValue == minimumNumBytesUsed) { - bestStrategy = NONE; - } else { - bestStrategy = REPEAT_COUNT; - } - } - - List values = new ArrayList<>(this.values); - this.values.clear(); - - return new Analyzer(bestStrategy, values); - } - - private void initializeByteSizes(String value) { - int maxBytesUsedByValue = getMaxBytes(value); - this.byteSizeValue = maxBytesUsedByValue; - this.repeatedValueCount = 1; - this.byteSizeRepeatCount = maxBytesUsedByValue; - } - - private void updateByteSizes(String value) { - int maxBytesUsedByValue = getMaxBytes(value); - this.byteSizeValue += maxBytesUsedByValue; - - // for null - if (this.previousValue == null) { - if (value == null) { - this.repeatedValueCount++; - } else { - this.byteSizeRepeatCount += expectedBytesVLength(this.repeatedValueCount); - this.byteSizeRepeatCount += maxBytesUsedByValue; - this.repeatedValueCount = 1; - } - } else if (this.previousValue.equals(value)) { - this.repeatedValueCount++; - } else { - this.byteSizeRepeatCount += expectedBytesVLength(this.repeatedValueCount); - this.byteSizeRepeatCount += maxBytesUsedByValue; - this.repeatedValueCount = 1; - } - } - - private int getMaxBytes(String value) { - if (value == null) { - return 0; - } - return value.length() * MAX_BYTES_PER_CHAR_UTF8; - } - - private int expectedBytesVLength(int value) { - if (value < 0) { - return BytesUtils.computeVar64Size(value); - } else { - return BytesUtils.computeVar32Size(value); - } - } - - } - - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedIntegerEncodingStrategy.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedIntegerEncodingStrategy.java deleted file mode 100644 index 71ff7c59d200..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedIntegerEncodingStrategy.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.strategy; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.ArithmeticOperation; -import com.navercorp.pinpoint.common.server.bo.codec.TypedBufferHandler; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.DeltaEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.DeltaOfDeltaEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.RepeatCountEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.ValueEncodingStrategy; -import com.navercorp.pinpoint.common.util.BytesUtils; - -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; - -/** - * @author HyunGil Jeong - */ -public enum UnsignedIntegerEncodingStrategy implements EncodingStrategy { - NONE(new ValueEncodingStrategy.Unsigned<>(TypedBufferHandler.INTEGER_BUFFER_HANDLER)), - REPEAT_COUNT(new RepeatCountEncodingStrategy.Unsigned<>(TypedBufferHandler.INTEGER_BUFFER_HANDLER)), - DELTA(new DeltaEncodingStrategy.Unsigned<>(TypedBufferHandler.INTEGER_BUFFER_HANDLER, ArithmeticOperation.INTEGER_OPERATIONS)), - DELTA_OF_DELTA(new DeltaOfDeltaEncodingStrategy.Unsigned<>(TypedBufferHandler.INTEGER_BUFFER_HANDLER, ArithmeticOperation.INTEGER_OPERATIONS)), ; - - private final EncodingStrategy delegate; - private static final Set UNSIGNED_INTEGER_ENCODING_STRATEGY = EnumSet.allOf(UnsignedIntegerEncodingStrategy.class); - - UnsignedIntegerEncodingStrategy(EncodingStrategy delegate) { - this.delegate = delegate; - } - - @Override - public byte getCode() { - return this.delegate.getCode(); - } - - @Override - public void encodeValues(Buffer buffer, List values) { - this.delegate.encodeValues(buffer, values); - } - - @Override - public List decodeValues(Buffer buffer, int numValues) { - return this.delegate.decodeValues(buffer, numValues); - } - - public static UnsignedIntegerEncodingStrategy getFromCode(int code) { - - for (UnsignedIntegerEncodingStrategy encodingStrategy : UNSIGNED_INTEGER_ENCODING_STRATEGY) { - if (encodingStrategy.getCode() == (code & 0xFF)) { - return encodingStrategy; - } - } - throw new IllegalArgumentException("Unknown code : " + code); - } - - public static class Analyzer implements StrategyAnalyzer { - - private final EncodingStrategy bestStrategy; - private final List values; - - private Analyzer(EncodingStrategy bestStrategy, List values) { - this.bestStrategy = bestStrategy; - this.values = values; - } - - @Override - public EncodingStrategy getBestStrategy() { - return this.bestStrategy; - } - - @Override - public List getValues() { - return this.values; - } - - public static class Builder implements StrategyAnalyzerBuilder { - - private final List values = new ArrayList<>(); - private int previousValue = 0; - private int previousDelta = 0; - - private int byteSizeValue = 0; - private int byteSizeDelta = 0; - private int byteSizeDeltaOfDelta = 0; - private int byteSizeRepeatCount = 0; - - private int repeatedValueCount = 0; - - @Override - public StrategyAnalyzerBuilder addValue(Integer value) { - int delta = value - this.previousValue; - if (this.values.isEmpty()) { - initializeByteSizes(value); - } else { - updateByteSizes(value, delta); - this.previousDelta = delta; - } - this.previousValue = value; - - this.values.add(value); - return this; - } - - @Override - public StrategyAnalyzer build() { - if (this.repeatedValueCount > 0) { - this.byteSizeRepeatCount += BytesUtils.computeVar32Size(this.repeatedValueCount); - } - EncodingStrategy bestStrategy; - int minimumNumBytesUsed = MathUtils.min( - this.byteSizeValue, - this.byteSizeDelta, - this.byteSizeDeltaOfDelta, - this.byteSizeRepeatCount); - if (this.byteSizeValue == minimumNumBytesUsed) { - bestStrategy = NONE; - } else if (this.byteSizeDelta == minimumNumBytesUsed) { - bestStrategy = DELTA; - } else if (this.byteSizeDeltaOfDelta == minimumNumBytesUsed) { - bestStrategy = DELTA_OF_DELTA; - } else { - bestStrategy = REPEAT_COUNT; - } - List values = new ArrayList<>(this.values); - this.values.clear(); - return new Analyzer(bestStrategy, values); - } - - int getByteSizeValue() { - return byteSizeValue; - } - - int getByteSizeDelta() { - return byteSizeDelta; - } - - int getByteSizeDeltaOfDelta() { - return byteSizeDeltaOfDelta; - } - - int getByteSizeRepeatCount() { - return byteSizeRepeatCount; - } - - private void initializeByteSizes(int value) { - int expectedNumBytesUsedByValue = expectedBytesVLength(value); - this.byteSizeValue = expectedNumBytesUsedByValue; - this.byteSizeDelta = expectedNumBytesUsedByValue; - this.byteSizeDeltaOfDelta = expectedNumBytesUsedByValue; - this.repeatedValueCount = 1; - this.byteSizeRepeatCount = expectedNumBytesUsedByValue; - } - - private void updateByteSizes(int value, int delta) { - int expectedNumBytesUsedByValue = expectedBytesVLength(value); - this.byteSizeValue += expectedNumBytesUsedByValue; - this.byteSizeDelta += expectedBytesVLength(value ^ this.previousValue); - this.byteSizeDeltaOfDelta += expectedBytesSVLength(delta - this.previousDelta); - if (this.previousValue != value) { - this.byteSizeRepeatCount += expectedBytesVLength(this.repeatedValueCount); - this.byteSizeRepeatCount += expectedNumBytesUsedByValue; - this.repeatedValueCount = 1; - } else { - this.repeatedValueCount++; - } - } - - private int expectedBytesVLength(int value) { - if (value < 0) { - return BytesUtils.computeVar64Size(value); - } else { - return BytesUtils.computeVar32Size(value); - } - } - - private int expectedBytesSVLength(int value) { - return BytesUtils.computeVar32Size(BytesUtils.intToZigZag(value)); - } - } - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedLongEncodingStrategy.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedLongEncodingStrategy.java deleted file mode 100644 index 099b99885cd4..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedLongEncodingStrategy.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.strategy; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.ArithmeticOperation; -import com.navercorp.pinpoint.common.server.bo.codec.TypedBufferHandler; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.DeltaEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.DeltaOfDeltaEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.RepeatCountEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.ValueEncodingStrategy; -import com.navercorp.pinpoint.common.util.BytesUtils; - -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; - -/** - * @author HyunGil Jeong - */ -public enum UnsignedLongEncodingStrategy implements EncodingStrategy { - NONE(new ValueEncodingStrategy.Unsigned<>(TypedBufferHandler.LONG_BUFFER_HANDLER)), - REPEAT_COUNT(new RepeatCountEncodingStrategy.Unsigned<>(TypedBufferHandler.LONG_BUFFER_HANDLER)), - DELTA(new DeltaEncodingStrategy.Unsigned<>(TypedBufferHandler.LONG_BUFFER_HANDLER, ArithmeticOperation.LONG_OPERATIONS)), - DELTA_OF_DELTA(new DeltaOfDeltaEncodingStrategy.Unsigned<>(TypedBufferHandler.LONG_BUFFER_HANDLER, ArithmeticOperation.LONG_OPERATIONS)); - - private final EncodingStrategy delegate; - - private static final Set UNSIGNED_LONG_ENCODING_STRATEGY = EnumSet.allOf(UnsignedLongEncodingStrategy.class); - - UnsignedLongEncodingStrategy(EncodingStrategy delegate) { - this.delegate = delegate; - } - - @Override - public byte getCode() { - return this.delegate.getCode(); - } - - @Override - public void encodeValues(Buffer buffer, List values) { - this.delegate.encodeValues(buffer, values); - } - - @Override - public List decodeValues(Buffer buffer, int numValues) { - return this.delegate.decodeValues(buffer, numValues); - } - - public static UnsignedLongEncodingStrategy getFromCode(int code) { - - for (UnsignedLongEncodingStrategy encodingStrategy : UNSIGNED_LONG_ENCODING_STRATEGY) { - if (encodingStrategy.getCode() == (code & 0xFF)) { - return encodingStrategy; - } - } - throw new IllegalArgumentException("Unknown code : " + code); - } - - public static class Analyzer implements StrategyAnalyzer { - - private final EncodingStrategy bestStrategy; - private final List values; - - private Analyzer(EncodingStrategy bestStrategy, List values) { - this.bestStrategy = bestStrategy; - this.values = values; - } - - @Override - public EncodingStrategy getBestStrategy() { - return this.bestStrategy; - } - - @Override - public List getValues() { - return this.values; - } - - public static class Builder implements StrategyAnalyzerBuilder { - - private final List values = new ArrayList<>(); - private long previousValue = 0L; - private long previousDelta = 0L; - - private int byteSizeValue = 0; - private int byteSizeDelta = 0; - private int byteSizeDeltaOfDelta = 0; - private int byteSizeRepeatCount = 0; - - private int repeatedValueCount = 0; - - @Override - public StrategyAnalyzerBuilder addValue(Long value) { - long delta = value - this.previousValue; - if (this.values.isEmpty()) { - initializeByteSizes(value); - } else { - updateByteSizes(value, delta); - this.previousDelta = delta; - } - this.previousValue = value; - - this.values.add(value); - return this; - } - - @Override - public StrategyAnalyzer build() { - if (this.repeatedValueCount > 0) { - this.byteSizeRepeatCount += BytesUtils.computeVar32Size(this.repeatedValueCount); - } - EncodingStrategy bestStrategy; - int minimumNumBytesUsed = MathUtils.min( - this.byteSizeValue, - this.byteSizeDelta, - this.byteSizeDeltaOfDelta, - this.byteSizeRepeatCount); - if (this.byteSizeValue == minimumNumBytesUsed) { - bestStrategy = NONE; - } else if (this.byteSizeDelta == minimumNumBytesUsed) { - bestStrategy = DELTA; - } else if (this.byteSizeDeltaOfDelta == minimumNumBytesUsed) { - bestStrategy = DELTA_OF_DELTA; - } else { - bestStrategy = REPEAT_COUNT; - } - List values = new ArrayList<>(this.values); - this.values.clear(); - return new Analyzer(bestStrategy, values); - } - - int getByteSizeValue() { - return byteSizeValue; - } - - int getByteSizeDelta() { - return byteSizeDelta; - } - - int getByteSizeDeltaOfDelta() { - return byteSizeDeltaOfDelta; - } - - int getByteSizeRepeatCount() { - return byteSizeRepeatCount; - } - - private void initializeByteSizes(long value) { - int expectedNumBytesUsedByValue = expectedBytesVLength(value); - this.byteSizeValue = expectedNumBytesUsedByValue; - this.byteSizeDelta = expectedNumBytesUsedByValue; - this.byteSizeDeltaOfDelta = expectedNumBytesUsedByValue; - this.repeatedValueCount = 1; - this.byteSizeRepeatCount = expectedNumBytesUsedByValue; - } - - private void updateByteSizes(long value, long delta) { - int expectedNumBytesUsedByValue = expectedBytesVLength(value); - this.byteSizeValue += expectedNumBytesUsedByValue; - this.byteSizeDelta += expectedBytesVLength(value ^ this.previousValue); - this.byteSizeDeltaOfDelta += expectedBytesSVLength(delta - this.previousDelta); - if (this.previousValue != value) { - this.byteSizeRepeatCount += BytesUtils.computeVar32Size(this.repeatedValueCount); - this.byteSizeRepeatCount += expectedNumBytesUsedByValue; - this.repeatedValueCount = 1; - } else { - this.repeatedValueCount++; - } - } - - private int expectedBytesVLength(long value) { - return BytesUtils.computeVar64Size(value); - } - - private int expectedBytesSVLength(long value) { - return expectedBytesVLength(BytesUtils.longToZigZag(value)); - } - } - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedShortEncodingStrategy.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedShortEncodingStrategy.java deleted file mode 100644 index 6c9926c6cf52..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedShortEncodingStrategy.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.strategy; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.TypedBufferHandler; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.RepeatCountEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.ValueEncodingStrategy; -import com.navercorp.pinpoint.common.util.BytesUtils; - -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; - -/** - * @author HyunGil Jeong - */ -public enum UnsignedShortEncodingStrategy implements EncodingStrategy { - NONE(new ValueEncodingStrategy.Unsigned<>(TypedBufferHandler.SHORT_BUFFER_HANDLER)), - REPEAT_COUNT(new RepeatCountEncodingStrategy.Unsigned<>(TypedBufferHandler.SHORT_BUFFER_HANDLER)); - - private final EncodingStrategy delegate; - private static final Set UNSIGNED_SHORT_ENCODING_STRATEGY = EnumSet.allOf(UnsignedShortEncodingStrategy.class); - - UnsignedShortEncodingStrategy(EncodingStrategy delegate) { - this.delegate = delegate; - } - - @Override - public byte getCode() { - return this.delegate.getCode(); - } - - @Override - public void encodeValues(Buffer buffer, List values) { - this.delegate.encodeValues(buffer, values); - } - - @Override - public List decodeValues(Buffer buffer, int numValues) { - return this.delegate.decodeValues(buffer, numValues); - } - - public static UnsignedShortEncodingStrategy getFromCode(int code) { - - for (UnsignedShortEncodingStrategy encodingStrategy : UNSIGNED_SHORT_ENCODING_STRATEGY) { - if (encodingStrategy.getCode() == (code & 0xFF)) { - return encodingStrategy; - } - } - throw new IllegalArgumentException("Unknown code : " + code); - } - - public static class Analyzer implements StrategyAnalyzer { - - private final EncodingStrategy bestStrategy; - private final List values; - - private Analyzer(EncodingStrategy bestStrategy, List values) { - this.bestStrategy = bestStrategy; - this.values = values; - } - - @Override - public EncodingStrategy getBestStrategy() { - return this.bestStrategy; - } - - @Override - public List getValues() { - return this.values; - } - - public static class Builder implements StrategyAnalyzerBuilder { - - private static final int SHORT_BYTE_SIZE = 2; - - private final List values = new ArrayList<>(); - private short previousValue = 0; - - private int byteSizeValue = 0; - private int byteSizeRepeatCount = 0; - - private int repeatedValueCount = 0; - - @Override - public StrategyAnalyzerBuilder addValue(Short value) { - if (this.values.isEmpty()) { - initializeByteSizes(); - } else { - updateByteSizes(value); - } - this.previousValue = value; - - this.values.add(value); - return this; - } - - @Override - public StrategyAnalyzer build() { - if (this.repeatedValueCount > 0) { - this.byteSizeRepeatCount += BytesUtils.computeVar32Size(this.repeatedValueCount); - } - EncodingStrategy bestStrategy; - int minimumNumBytesUsed = Math.min( - this.byteSizeValue, - this.byteSizeRepeatCount); - if (this.byteSizeValue == minimumNumBytesUsed) { - bestStrategy = NONE; - } else { - bestStrategy = REPEAT_COUNT; - } - List values = new ArrayList<>(this.values); - this.values.clear(); - return new Analyzer(bestStrategy, values); - } - - int getByteSizeValue() { - return byteSizeValue; - } - - int getByteSizeRepeatCount() { - return byteSizeRepeatCount; - } - - private void initializeByteSizes() { - this.byteSizeValue = SHORT_BYTE_SIZE; - this.repeatedValueCount = 1; - this.byteSizeRepeatCount = SHORT_BYTE_SIZE; - } - - private void updateByteSizes(int value) { - this.byteSizeValue += SHORT_BYTE_SIZE; - if (this.previousValue != value) { - this.byteSizeRepeatCount += BytesUtils.computeVar32Size(this.repeatedValueCount); - this.byteSizeRepeatCount += 2; - this.repeatedValueCount = 1; - } else { - this.repeatedValueCount++; - } - } - } - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/ActiveTraceCodecV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/ActiveTraceCodecV2.java deleted file mode 100644 index e61f6e2ec26c..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/ActiveTraceCodecV2.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecFactory; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.StrategyAnalyzer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedIntegerEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedShortEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; -import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceHistogram; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -@Component -public class ActiveTraceCodecV2 extends AgentStatCodecV2 { - - public ActiveTraceCodecV2(AgentStatDataPointCodec codec) { - super(new ActiveTraceCodecFactory(codec)); - } - - - private static class ActiveTraceCodecFactory implements CodecFactory { - - private final AgentStatDataPointCodec codec; - - private ActiveTraceCodecFactory(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public AgentStatDataPointCodec getCodec() { - return codec; - } - - @Override - public CodecEncoder createCodecEncoder() { - return new ActiveTraceCodecEncoder(codec); - } - - @Override - public CodecDecoder createCodecDecoder() { - return new ActiveTraceCodecDecoder(codec); - } - } - - public static class ActiveTraceCodecEncoder implements AgentStatCodec.CodecEncoder { - - private final AgentStatDataPointCodec codec; - private final UnsignedShortEncodingStrategy.Analyzer.Builder versionAnalyzerBuilder = new UnsignedShortEncodingStrategy.Analyzer.Builder(); - private final UnsignedIntegerEncodingStrategy.Analyzer.Builder schemaTypeAnalyzerBuilder = new UnsignedIntegerEncodingStrategy.Analyzer.Builder(); - private final UnsignedIntegerEncodingStrategy.Analyzer.Builder fastTraceCountsAnalyzerBuilder = new UnsignedIntegerEncodingStrategy.Analyzer.Builder(); - private final UnsignedIntegerEncodingStrategy.Analyzer.Builder normalTraceCountsAnalyzerBuilder = new UnsignedIntegerEncodingStrategy.Analyzer.Builder(); - private final UnsignedIntegerEncodingStrategy.Analyzer.Builder slowTraceCountsAnalyzerBuilder = new UnsignedIntegerEncodingStrategy.Analyzer.Builder(); - private final UnsignedIntegerEncodingStrategy.Analyzer.Builder verySlowTraceCountsAnalyzerBuilder = new UnsignedIntegerEncodingStrategy.Analyzer.Builder(); - - public ActiveTraceCodecEncoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void addValue(ActiveTraceBo activeTraceBo) { - versionAnalyzerBuilder.addValue(activeTraceBo.getVersion()); - schemaTypeAnalyzerBuilder.addValue(activeTraceBo.getHistogramSchemaType()); - final ActiveTraceHistogram activeTraceHistogram = activeTraceBo.getActiveTraceHistogram(); - fastTraceCountsAnalyzerBuilder.addValue(activeTraceHistogram.getFastCount()); - normalTraceCountsAnalyzerBuilder.addValue(activeTraceHistogram.getNormalCount()); - slowTraceCountsAnalyzerBuilder.addValue(activeTraceHistogram.getSlowCount()); - verySlowTraceCountsAnalyzerBuilder.addValue(activeTraceHistogram.getVerySlowCount()); - } - - @Override - public void encode(Buffer valueBuffer) { - StrategyAnalyzer versionStrategyAnalyzer = versionAnalyzerBuilder.build(); - StrategyAnalyzer schemaTypeStrategyAnalyzer = schemaTypeAnalyzerBuilder.build(); - StrategyAnalyzer fastTraceCountsStrategyAnalyzer = fastTraceCountsAnalyzerBuilder.build(); - StrategyAnalyzer normalTraceCountsStrategyAnalyzer = normalTraceCountsAnalyzerBuilder.build(); - StrategyAnalyzer slowTraceCountsStrategyAnalyzer = slowTraceCountsAnalyzerBuilder.build(); - StrategyAnalyzer verySlowTraceCountsStrategyAnalyzer = verySlowTraceCountsAnalyzerBuilder.build(); - - // encode header - AgentStatHeaderEncoder headerEncoder = new BitCountingHeaderEncoder(); - headerEncoder.addCode(versionStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(schemaTypeStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(fastTraceCountsStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(normalTraceCountsStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(slowTraceCountsStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(verySlowTraceCountsStrategyAnalyzer.getBestStrategy().getCode()); - final byte[] header = headerEncoder.getHeader(); - valueBuffer.putPrefixedBytes(header); - // encode values - this.codec.encodeValues(valueBuffer, versionStrategyAnalyzer.getBestStrategy(), versionStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, schemaTypeStrategyAnalyzer.getBestStrategy(), schemaTypeStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, fastTraceCountsStrategyAnalyzer.getBestStrategy(), fastTraceCountsStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, normalTraceCountsStrategyAnalyzer.getBestStrategy(), normalTraceCountsStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, slowTraceCountsStrategyAnalyzer.getBestStrategy(), slowTraceCountsStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, verySlowTraceCountsStrategyAnalyzer.getBestStrategy(), verySlowTraceCountsStrategyAnalyzer.getValues()); - } - - } - - public static class ActiveTraceCodecDecoder implements AgentStatCodec.CodecDecoder { - - private final AgentStatDataPointCodec codec; - private List versions; - private List schemaTypes; - private List fastTraceCounts; - private List normalTraceCounts; - private List slowTraceCounts; - private List verySlowTraceCounts; - - public ActiveTraceCodecDecoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void decode(Buffer valueBuffer, AgentStatHeaderDecoder headerDecoder, int valueSize) { - EncodingStrategy versionEncodingStrategy = UnsignedShortEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy schemaTypeEncodingStrategy = UnsignedIntegerEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy fastTraceCountsEncodingStrategy = UnsignedIntegerEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy normalTraceCountsEncodingStrategy = UnsignedIntegerEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy slowTraceCountsEncodingStrategy = UnsignedIntegerEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy verySlowTraceCountsEncodingStrategy = UnsignedIntegerEncodingStrategy.getFromCode(headerDecoder.getCode()); - // decode values - this.versions = this.codec.decodeValues(valueBuffer, versionEncodingStrategy, valueSize); - this.schemaTypes = this.codec.decodeValues(valueBuffer, schemaTypeEncodingStrategy, valueSize); - this.fastTraceCounts = this.codec.decodeValues(valueBuffer, fastTraceCountsEncodingStrategy, valueSize); - this.normalTraceCounts = this.codec.decodeValues(valueBuffer, normalTraceCountsEncodingStrategy, valueSize); - this.slowTraceCounts = this.codec.decodeValues(valueBuffer, slowTraceCountsEncodingStrategy, valueSize); - this.verySlowTraceCounts = this.codec.decodeValues(valueBuffer, verySlowTraceCountsEncodingStrategy, valueSize); - } - - @Override - public ActiveTraceBo getValue(int index) { - ActiveTraceBo activeTraceBo = new ActiveTraceBo(); - activeTraceBo.setVersion(versions.get(index)); - activeTraceBo.setHistogramSchemaType(schemaTypes.get(index)); - - ActiveTraceHistogram activeTraceHistogram = newActiveTraceHistogram(index); - activeTraceBo.setActiveTraceHistogram(activeTraceHistogram); - return activeTraceBo; - } - - private ActiveTraceHistogram newActiveTraceHistogram(int index) { - final int fast = fastTraceCounts.get(index); - final int normal = normalTraceCounts.get(index); - final int slow = slowTraceCounts.get(index); - final int verySlow = verySlowTraceCounts.get(index); - return new ActiveTraceHistogram(fast, normal, slow, verySlow); - } - - } - -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/AgentStatCodecV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/AgentStatCodecV2.java deleted file mode 100644 index e67dd1e61d27..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/AgentStatCodecV2.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2017 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecFactory; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedLongEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import org.springframework.util.Assert; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * @author Taejin Koo - */ -public class AgentStatCodecV2 implements AgentStatCodec { - - private static final byte VERSION = 2; - - private final CodecFactory codecFactory; - - public AgentStatCodecV2(final CodecFactory codecFactory) { - this.codecFactory = Objects.requireNonNull(codecFactory, "codecFactory"); - } - - @Override - public byte getVersion() { - return VERSION; - } - - @Override - public void encodeValues(Buffer valueBuffer, List statDataPointList) { - Assert.notEmpty(statDataPointList, "statDataPointList"); - - final int numValues = statDataPointList.size(); - valueBuffer.putVInt(numValues); - - List startTimestamps = new ArrayList<>(numValues); - List timestamps = new ArrayList<>(numValues); - - CodecEncoder encoder = codecFactory.createCodecEncoder(); - for (T statDataPoint : statDataPointList) { - startTimestamps.add(statDataPoint.getStartTimestamp()); - timestamps.add(statDataPoint.getTimestamp()); - encoder.addValue(statDataPoint); - } - - final AgentStatDataPointCodec codec = codecFactory.getCodec(); - codec.encodeValues(valueBuffer, UnsignedLongEncodingStrategy.REPEAT_COUNT, startTimestamps); - codec.encodeTimestamps(valueBuffer, timestamps); - encoder.encode(valueBuffer); - } - - @Override - public List decodeValues(Buffer valueBuffer, AgentStatDecodingContext decodingContext) { - final String agentId = decodingContext.getAgentId(); - final long baseTimestamp = decodingContext.getBaseTimestamp(); - final long timestampDelta = decodingContext.getTimestampDelta(); - final long initialTimestamp = baseTimestamp + timestampDelta; - - int numValues = valueBuffer.readVInt(); - final AgentStatDataPointCodec codec = codecFactory.getCodec(); - List startTimestamps = codec.decodeValues(valueBuffer, UnsignedLongEncodingStrategy.REPEAT_COUNT, numValues); - List timestamps = codec.decodeTimestamps(initialTimestamp, valueBuffer, numValues); - - CodecDecoder codecDecoder = codecFactory.createCodecDecoder(); - - // decode headers - final byte[] header = valueBuffer.readPrefixedBytes(); - AgentStatHeaderDecoder headerDecoder = new BitCountingHeaderDecoder(header); - - codecDecoder.decode(valueBuffer, headerDecoder, numValues); - - List result = new ArrayList(numValues); - for (int i = 0; i < numValues; i++) { - T newObject = codecDecoder.getValue(i); - newObject.setAgentId(agentId); - newObject.setStartTimestamp(startTimestamps.get(i)); - newObject.setTimestamp(timestamps.get(i)); - result.add(newObject); - } - - return result; - } - - -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/CpuLoadCodecV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/CpuLoadCodecV2.java deleted file mode 100644 index 8145aa83889f..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/CpuLoadCodecV2.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecFactory; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.StrategyAnalyzer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedLongEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatUtils; -import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -@Component -public class CpuLoadCodecV2 extends AgentStatCodecV2 { - - public CpuLoadCodecV2(AgentStatDataPointCodec codec) { - super(new CpuLoadCodecFactory(codec)); - } - - - private static class CpuLoadCodecFactory implements CodecFactory { - - private final AgentStatDataPointCodec codec; - - private CpuLoadCodecFactory(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public AgentStatDataPointCodec getCodec() { - return codec; - } - - @Override - public CodecEncoder createCodecEncoder() { - return new CpuLoadCodecEncoder(codec); - } - - @Override - public CodecDecoder createCodecDecoder() { - return new CpuLoadCodecDecoder(codec); - } - } - - public static class CpuLoadCodecEncoder implements AgentStatCodec.CodecEncoder { - - private final AgentStatDataPointCodec codec; - private final UnsignedLongEncodingStrategy.Analyzer.Builder jvmCpuLoadAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder systemCpuLoadAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - - public CpuLoadCodecEncoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void addValue(CpuLoadBo cpuLoadBo) { - jvmCpuLoadAnalyzerBuilder.addValue(AgentStatUtils.convertDoubleToLong(cpuLoadBo.getJvmCpuLoad())); - systemCpuLoadAnalyzerBuilder.addValue(AgentStatUtils.convertDoubleToLong(cpuLoadBo.getSystemCpuLoad())); - } - - @Override - public void encode(Buffer valueBuffer) { - StrategyAnalyzer jvmCpuLoadStrategyAnalyzer = jvmCpuLoadAnalyzerBuilder.build(); - StrategyAnalyzer systemCpuLoadStrategyAnalyzer = systemCpuLoadAnalyzerBuilder.build(); - - // encode header - AgentStatHeaderEncoder headerEncoder = new BitCountingHeaderEncoder(); - headerEncoder.addCode(jvmCpuLoadStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(systemCpuLoadStrategyAnalyzer.getBestStrategy().getCode()); - final byte[] header = headerEncoder.getHeader(); - valueBuffer.putPrefixedBytes(header); - // encode values - this.codec.encodeValues(valueBuffer, jvmCpuLoadStrategyAnalyzer.getBestStrategy(), jvmCpuLoadStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, systemCpuLoadStrategyAnalyzer.getBestStrategy(), systemCpuLoadStrategyAnalyzer.getValues()); - } - - } - - public static class CpuLoadCodecDecoder implements AgentStatCodec.CodecDecoder { - - private final AgentStatDataPointCodec codec; - - private List jvmCpuLoads; - private List systemCpuLoads; - - public CpuLoadCodecDecoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void decode(Buffer valueBuffer, AgentStatHeaderDecoder headerDecoder, int valueSize) { - EncodingStrategy jvmCpuLoadEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy systemCpuLoadEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - // decode values - this.jvmCpuLoads = this.codec.decodeValues(valueBuffer, jvmCpuLoadEncodingStrategy, valueSize); - this.systemCpuLoads = this.codec.decodeValues(valueBuffer, systemCpuLoadEncodingStrategy, valueSize); - } - - @Override - public CpuLoadBo getValue(int index) { - CpuLoadBo cpuLoadBo = new CpuLoadBo(); - cpuLoadBo.setJvmCpuLoad(AgentStatUtils.convertLongToDouble(jvmCpuLoads.get(index))); - cpuLoadBo.setSystemCpuLoad(AgentStatUtils.convertLongToDouble(systemCpuLoads.get(index))); - return cpuLoadBo; - } - - } - -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DataSourceCodecV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DataSourceCodecV2.java deleted file mode 100644 index 22436b195c2d..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DataSourceCodecV2.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2017 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.StrategyAnalyzer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.StringEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedIntegerEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedLongEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedShortEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceBo; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceListBo; -import org.springframework.stereotype.Component; -import org.springframework.util.Assert; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * @author Taejin Koo - */ -@Component -public class DataSourceCodecV2 implements AgentStatCodec { - - private static final byte VERSION = 2; - - private final AgentStatDataPointCodec codec; - - public DataSourceCodecV2(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "agentStatDataPointCodec"); - } - - @Override - public byte getVersion() { - return VERSION; - } - - @Override - public void encodeValues(Buffer valueBuffer, List dataSourceListBos) { - Assert.notEmpty(dataSourceListBos, "dataSourceListBos"); - - final int numValues = dataSourceListBos.size(); - valueBuffer.putVInt(numValues); - - for (DataSourceListBo dataSourceListBo : dataSourceListBos) { - encodeDataSourceListBo(valueBuffer, dataSourceListBo); - } - } - - private void encodeDataSourceListBo(Buffer valueBuffer, DataSourceListBo dataSourceListBo) { - final int numValues = dataSourceListBo.size(); - valueBuffer.putVInt(numValues); - - if (numValues == 0) { - return; - } - - // id // int - // serviceTypeCode // short - // name // string - // jdbcUrl // string - // activeConnectionSize //int - // maxConnectionSize // int - List startTimestamps = new ArrayList<>(numValues); - List timestamps = new ArrayList<>(numValues); - - UnsignedIntegerEncodingStrategy.Analyzer.Builder idAnalyzerBuilder = new UnsignedIntegerEncodingStrategy.Analyzer.Builder(); - UnsignedShortEncodingStrategy.Analyzer.Builder serviceTypeAnalyzerBuilder = new UnsignedShortEncodingStrategy.Analyzer.Builder(); - StringEncodingStrategy.Analyzer.Builder databaseNameAnalyzerBuilder = new StringEncodingStrategy.Analyzer.Builder(); - StringEncodingStrategy.Analyzer.Builder jdbcUrlAnalyzerBuilder = new StringEncodingStrategy.Analyzer.Builder(); - UnsignedIntegerEncodingStrategy.Analyzer.Builder activeConnectionSizeAnalyzerBuilder = new UnsignedIntegerEncodingStrategy.Analyzer.Builder(); - UnsignedIntegerEncodingStrategy.Analyzer.Builder maxConnectionSizeAnalyzerBuilder = new UnsignedIntegerEncodingStrategy.Analyzer.Builder(); - - for (DataSourceBo dataSourceBo : dataSourceListBo.getList()) { - startTimestamps.add(dataSourceBo.getStartTimestamp()); - timestamps.add(dataSourceBo.getTimestamp()); - - idAnalyzerBuilder.addValue(dataSourceBo.getId()); - serviceTypeAnalyzerBuilder.addValue(dataSourceBo.getServiceTypeCode()); - databaseNameAnalyzerBuilder.addValue(dataSourceBo.getDatabaseName()); - jdbcUrlAnalyzerBuilder.addValue(dataSourceBo.getJdbcUrl()); - activeConnectionSizeAnalyzerBuilder.addValue(dataSourceBo.getActiveConnectionSize()); - maxConnectionSizeAnalyzerBuilder.addValue(dataSourceBo.getMaxConnectionSize()); - } - this.codec.encodeValues(valueBuffer, UnsignedLongEncodingStrategy.REPEAT_COUNT, startTimestamps); - this.codec.encodeTimestamps(valueBuffer, timestamps); - this.encodeDataPoints(valueBuffer, idAnalyzerBuilder.build(), serviceTypeAnalyzerBuilder.build(), - databaseNameAnalyzerBuilder.build(), jdbcUrlAnalyzerBuilder.build(), - activeConnectionSizeAnalyzerBuilder.build(), maxConnectionSizeAnalyzerBuilder.build()); - - } - - private void encodeDataPoints(Buffer valueBuffer, StrategyAnalyzer idAnalyzerBuilder, StrategyAnalyzer serviceTypeAnalyzerBuilder, - StrategyAnalyzer databaseNameAnalyzerBuilder, StrategyAnalyzer jdbcUrlAnalyzerBuilder, - StrategyAnalyzer activeConnectionSizeAnalyzerBuilder, StrategyAnalyzer maxConnectionSizeAnalyzerBuilder) { - // encode header - AgentStatHeaderEncoder headerEncoder = new BitCountingHeaderEncoder(); - headerEncoder.addCode(idAnalyzerBuilder.getBestStrategy().getCode()); - headerEncoder.addCode(serviceTypeAnalyzerBuilder.getBestStrategy().getCode()); - headerEncoder.addCode(databaseNameAnalyzerBuilder.getBestStrategy().getCode()); - headerEncoder.addCode(jdbcUrlAnalyzerBuilder.getBestStrategy().getCode()); - headerEncoder.addCode(activeConnectionSizeAnalyzerBuilder.getBestStrategy().getCode()); - headerEncoder.addCode(maxConnectionSizeAnalyzerBuilder.getBestStrategy().getCode()); - - final byte[] header = headerEncoder.getHeader(); - valueBuffer.putPrefixedBytes(header); - - // encode values - this.codec.encodeValues(valueBuffer, idAnalyzerBuilder.getBestStrategy(), idAnalyzerBuilder.getValues()); - this.codec.encodeValues(valueBuffer, serviceTypeAnalyzerBuilder.getBestStrategy(), serviceTypeAnalyzerBuilder.getValues()); - this.codec.encodeValues(valueBuffer, databaseNameAnalyzerBuilder.getBestStrategy(), databaseNameAnalyzerBuilder.getValues()); - this.codec.encodeValues(valueBuffer, jdbcUrlAnalyzerBuilder.getBestStrategy(), jdbcUrlAnalyzerBuilder.getValues()); - this.codec.encodeValues(valueBuffer, activeConnectionSizeAnalyzerBuilder.getBestStrategy(), activeConnectionSizeAnalyzerBuilder.getValues()); - this.codec.encodeValues(valueBuffer, maxConnectionSizeAnalyzerBuilder.getBestStrategy(), maxConnectionSizeAnalyzerBuilder.getValues()); - } - - @Override - public List decodeValues(Buffer valueBuffer, AgentStatDecodingContext decodingContext) { - int numValues = valueBuffer.readVInt(); - - List dataSourceListBos = new ArrayList<>(numValues); - for (int i = 0; i < numValues; i++) { - DataSourceListBo dataSourceListBo = decodeValue(valueBuffer, decodingContext); - dataSourceListBos.add(dataSourceListBo); - } - return dataSourceListBos; - } - - private DataSourceListBo decodeValue(Buffer valueBuffer, AgentStatDecodingContext decodingContext) { - final String agentId = decodingContext.getAgentId(); - final long baseTimestamp = decodingContext.getBaseTimestamp(); - final long timestampDelta = decodingContext.getTimestampDelta(); - final long initialTimestamp = baseTimestamp + timestampDelta; - - int numValues = valueBuffer.readVInt(); - - List startTimestamps = this.codec.decodeValues(valueBuffer, UnsignedLongEncodingStrategy.REPEAT_COUNT, numValues); - List timestamps = this.codec.decodeTimestamps(initialTimestamp, valueBuffer, numValues); - - // decode headers - final byte[] header = valueBuffer.readPrefixedBytes(); - AgentStatHeaderDecoder headerDecoder = new BitCountingHeaderDecoder(header); - - EncodingStrategy idEncodingStrategy = UnsignedIntegerEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy serviceTypeEncodingStrategy = UnsignedShortEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy databaseNameEncodingStrategy = StringEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy urlEncodingStrategy = StringEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy activeConnectionSizeStrategy = UnsignedIntegerEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy maxConnectionSizeStrategy = UnsignedIntegerEncodingStrategy.getFromCode(headerDecoder.getCode()); - - List ids = this.codec.decodeValues(valueBuffer, idEncodingStrategy, numValues); - List serviceTypeCodes = this.codec.decodeValues(valueBuffer, serviceTypeEncodingStrategy, numValues); - List databaseNames = this.codec.decodeValues(valueBuffer, databaseNameEncodingStrategy, numValues); - List jdbcUrls = this.codec.decodeValues(valueBuffer, urlEncodingStrategy, numValues); - List activeConnectionSizes = this.codec.decodeValues(valueBuffer, activeConnectionSizeStrategy, numValues); - List maxConnectionSizes = this.codec.decodeValues(valueBuffer, maxConnectionSizeStrategy, numValues); - - DataSourceListBo dataSourceListBo = new DataSourceListBo(); - for (int i = 0; i < numValues; i++) { - if (i == 0) { - dataSourceListBo.setAgentId(agentId); - dataSourceListBo.setTimestamp(timestamps.get(i)); - dataSourceListBo.setStartTimestamp(startTimestamps.get(i)); - } - - DataSourceBo dataSourceBo = new DataSourceBo(); - dataSourceBo.setAgentId(agentId); - dataSourceBo.setStartTimestamp(startTimestamps.get(i)); - dataSourceBo.setTimestamp(timestamps.get(i)); - - dataSourceBo.setId(ids.get(i)); - dataSourceBo.setServiceTypeCode(serviceTypeCodes.get(i)); - dataSourceBo.setDatabaseName(databaseNames.get(i)); - dataSourceBo.setJdbcUrl(jdbcUrls.get(i)); - dataSourceBo.setActiveConnectionSize(activeConnectionSizes.get(i)); - dataSourceBo.setMaxConnectionSize(maxConnectionSizes.get(i)); - dataSourceListBo.add(dataSourceBo); - } - return dataSourceListBo; - } - -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DeadlockCodecV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DeadlockCodecV2.java deleted file mode 100644 index fb81d616c719..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DeadlockCodecV2.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2017 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecFactory; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.StrategyAnalyzer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedIntegerEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.stat.DeadlockThreadCountBo; -import org.springframework.stereotype.Component; - - -import java.util.List; -import java.util.Objects; - -/** - * @author Taejin Koo - */ -@Component -public class DeadlockCodecV2 extends AgentStatCodecV2 { - - public DeadlockCodecV2(AgentStatDataPointCodec codec) { - super(new DeadlockCodecFactory(codec)); - } - - - private static class DeadlockCodecFactory implements CodecFactory { - - private final AgentStatDataPointCodec codec; - - private DeadlockCodecFactory(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public AgentStatDataPointCodec getCodec() { - return codec; - } - - @Override - public CodecEncoder createCodecEncoder() { - return new DeadlockCodecEncoder(codec); - } - - @Override - public CodecDecoder createCodecDecoder() { - return new DeadlockCodecDecoder(codec); - } - } - - private static class DeadlockCodecEncoder implements AgentStatCodec.CodecEncoder { - - private final AgentStatDataPointCodec codec; - private final UnsignedIntegerEncodingStrategy.Analyzer.Builder deadlockedThreadCountAnalyzerBuilder = new UnsignedIntegerEncodingStrategy.Analyzer.Builder(); - - private DeadlockCodecEncoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void addValue(DeadlockThreadCountBo deadlockThreadCountBo) { - deadlockedThreadCountAnalyzerBuilder.addValue(deadlockThreadCountBo.getDeadlockedThreadCount()); - } - - @Override - public void encode(Buffer valueBuffer) { - StrategyAnalyzer deadlockedThreadIdAnalyzer = deadlockedThreadCountAnalyzerBuilder.build(); - - // encode header - AgentStatHeaderEncoder headerEncoder = new BitCountingHeaderEncoder(); - headerEncoder.addCode(deadlockedThreadIdAnalyzer.getBestStrategy().getCode()); - - final byte[] header = headerEncoder.getHeader(); - valueBuffer.putPrefixedBytes(header); - - // encode values - this.codec.encodeValues(valueBuffer, deadlockedThreadIdAnalyzer.getBestStrategy(), deadlockedThreadIdAnalyzer.getValues()); - } - - } - - private static class DeadlockCodecDecoder implements AgentStatCodec.CodecDecoder { - - private final AgentStatDataPointCodec codec; - - private List deadlockedThreadCountList; - - public DeadlockCodecDecoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void decode(Buffer valueBuffer, AgentStatHeaderDecoder headerDecoder, int valueSize) { - EncodingStrategy deadlockedThreadCountEncodingStrategy = UnsignedIntegerEncodingStrategy.getFromCode(headerDecoder.getCode()); - - // decode values - this.deadlockedThreadCountList = codec.decodeValues(valueBuffer, deadlockedThreadCountEncodingStrategy, valueSize); - } - - @Override - public DeadlockThreadCountBo getValue(int index) { - DeadlockThreadCountBo deadlockThreadCountBo = new DeadlockThreadCountBo(); - deadlockThreadCountBo.setDeadlockedThreadCount(deadlockedThreadCountList.get(index)); - return deadlockThreadCountBo; - } - - } - -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DirectBufferCodecV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DirectBufferCodecV2.java deleted file mode 100644 index 86c0bc63427b..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DirectBufferCodecV2.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2018 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecFactory; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.StrategyAnalyzer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedLongEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.stat.DirectBufferBo; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Objects; - -/** - * @author Roy Kim - */ -@Component -public class DirectBufferCodecV2 extends AgentStatCodecV2 { - - public DirectBufferCodecV2(AgentStatDataPointCodec codec) { - super(new DirectBufferCodecFactory(codec)); - } - - - private static class DirectBufferCodecFactory implements CodecFactory { - - private final AgentStatDataPointCodec codec; - - private DirectBufferCodecFactory(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public AgentStatDataPointCodec getCodec() { - return codec; - } - - @Override - public CodecEncoder createCodecEncoder() { - return new DirectBufferCodecEncoder(codec); - } - - @Override - public CodecDecoder createCodecDecoder() { - return new DirectBufferCodecDecoder(codec); - } - } - - public static class DirectBufferCodecEncoder implements CodecEncoder { - - private final AgentStatDataPointCodec codec; - private final UnsignedLongEncodingStrategy.Analyzer.Builder directCountAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder directMemoryUsedAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder mappedCountAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder mappedMemoryUsedAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - - - public DirectBufferCodecEncoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void addValue(DirectBufferBo directBufferBo) { - directCountAnalyzerBuilder.addValue(directBufferBo.getDirectCount()); - directMemoryUsedAnalyzerBuilder.addValue(directBufferBo.getDirectMemoryUsed()); - mappedCountAnalyzerBuilder.addValue(directBufferBo.getMappedCount()); - mappedMemoryUsedAnalyzerBuilder.addValue(directBufferBo.getMappedMemoryUsed()); - } - - @Override - public void encode(Buffer valueBuffer) { - StrategyAnalyzer directCountStrategyAnalyzer = directCountAnalyzerBuilder.build(); - StrategyAnalyzer directMemoryUsedStrategyAnalyzer = directMemoryUsedAnalyzerBuilder.build(); - StrategyAnalyzer mappedCountStrategyAnalyzer = mappedCountAnalyzerBuilder.build(); - StrategyAnalyzer mappedMemoryUsedStrategyAnalyzer = mappedMemoryUsedAnalyzerBuilder.build(); - - - // encode header - AgentStatHeaderEncoder headerEncoder = new BitCountingHeaderEncoder(); - headerEncoder.addCode(directCountStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(directMemoryUsedStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(mappedCountStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(mappedMemoryUsedStrategyAnalyzer.getBestStrategy().getCode()); - - final byte[] header = headerEncoder.getHeader(); - valueBuffer.putPrefixedBytes(header); - // encode values - this.codec.encodeValues(valueBuffer, directCountStrategyAnalyzer.getBestStrategy(), directCountStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, directMemoryUsedStrategyAnalyzer.getBestStrategy(), directMemoryUsedStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, mappedCountStrategyAnalyzer.getBestStrategy(), mappedCountStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, mappedMemoryUsedStrategyAnalyzer.getBestStrategy(), mappedMemoryUsedStrategyAnalyzer.getValues()); - } - - } - - public static class DirectBufferCodecDecoder implements CodecDecoder { - - private final AgentStatDataPointCodec codec; - - private List directCount; - private List directMemoryUsed; - private List mappedCount; - private List mappedMemoryUsed; - - public DirectBufferCodecDecoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void decode(Buffer valueBuffer, AgentStatHeaderDecoder headerDecoder, int valueSize) { - EncodingStrategy directCountEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy directMemoryUsedEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy mappedCountEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy mappedMemoryUsedCountEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - // decode values - this.directCount = this.codec.decodeValues(valueBuffer, directCountEncodingStrategy, valueSize); - this.directMemoryUsed = this.codec.decodeValues(valueBuffer, directMemoryUsedEncodingStrategy, valueSize); - this.mappedCount = this.codec.decodeValues(valueBuffer, mappedCountEncodingStrategy, valueSize); - this.mappedMemoryUsed = this.codec.decodeValues(valueBuffer, mappedMemoryUsedCountEncodingStrategy, valueSize); - } - - @Override - public DirectBufferBo getValue(int index) { - DirectBufferBo directBufferBo = new DirectBufferBo(); - directBufferBo.setDirectCount(directCount.get(index)); - directBufferBo.setDirectMemoryUsed(directMemoryUsed.get(index)); - directBufferBo.setMappedCount(mappedCount.get(index)); - directBufferBo.setMappedMemoryUsed(mappedMemoryUsed.get(index)); - return directBufferBo; - } - - } - -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/FileDescriptorCodecV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/FileDescriptorCodecV2.java deleted file mode 100644 index 2e016c40d1d4..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/FileDescriptorCodecV2.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2018 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecFactory; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.StrategyAnalyzer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedLongEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.stat.FileDescriptorBo; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Objects; - -/** - * @author Roy Kim - */ -@Component -public class FileDescriptorCodecV2 extends AgentStatCodecV2 { - - public FileDescriptorCodecV2(AgentStatDataPointCodec codec) { - super(new FileDescriptorCodecFactory(codec)); - } - - - private static class FileDescriptorCodecFactory implements CodecFactory { - - private final AgentStatDataPointCodec codec; - - private FileDescriptorCodecFactory(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public AgentStatDataPointCodec getCodec() { - return codec; - } - - @Override - public CodecEncoder createCodecEncoder() { - return new FileDescriptorCodecEncoder(codec); - } - - @Override - public CodecDecoder createCodecDecoder() { - return new FileDescriptorCodecDecoder(codec); - } - } - - public static class FileDescriptorCodecEncoder implements CodecEncoder { - - private final AgentStatDataPointCodec codec; - private final UnsignedLongEncodingStrategy.Analyzer.Builder openFileDescriptorCountAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - - public FileDescriptorCodecEncoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void addValue(FileDescriptorBo fileDescriptorBo) { - openFileDescriptorCountAnalyzerBuilder.addValue(fileDescriptorBo.getOpenFileDescriptorCount()); - } - - @Override - public void encode(Buffer valueBuffer) { - StrategyAnalyzer openFileDescriptorCountStrategyAnalyzer = openFileDescriptorCountAnalyzerBuilder.build(); - - // encode header - AgentStatHeaderEncoder headerEncoder = new BitCountingHeaderEncoder(); - headerEncoder.addCode(openFileDescriptorCountStrategyAnalyzer.getBestStrategy().getCode()); - final byte[] header = headerEncoder.getHeader(); - valueBuffer.putPrefixedBytes(header); - // encode values - this.codec.encodeValues(valueBuffer, openFileDescriptorCountStrategyAnalyzer.getBestStrategy(), openFileDescriptorCountStrategyAnalyzer.getValues()); - - } - - } - - public static class FileDescriptorCodecDecoder implements CodecDecoder { - - private final AgentStatDataPointCodec codec; - - private List openFileDescriptorCounts; - - public FileDescriptorCodecDecoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void decode(Buffer valueBuffer, AgentStatHeaderDecoder headerDecoder, int valueSize) { - EncodingStrategy openFileDescriptorCountEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - // decode values - this.openFileDescriptorCounts = this.codec.decodeValues(valueBuffer, openFileDescriptorCountEncodingStrategy, valueSize); - } - - @Override - public FileDescriptorBo getValue(int index) { - FileDescriptorBo fileDescriptorBo = new FileDescriptorBo(); - fileDescriptorBo.setOpenFileDescriptorCount(openFileDescriptorCounts.get(index)); - return fileDescriptorBo; - } - - } - -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/JvmGcCodecV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/JvmGcCodecV2.java deleted file mode 100644 index d028ebce929b..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/JvmGcCodecV2.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.JvmGcType; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.StrategyAnalyzer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedLongEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; -import org.springframework.stereotype.Component; -import org.springframework.util.Assert; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -@Component -public class JvmGcCodecV2 implements AgentStatCodec { - - private static final byte VERSION = 2; - - private final AgentStatDataPointCodec codec; - - public JvmGcCodecV2(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "agentStatDataPointCodec"); - } - - @Override - public byte getVersion() { - return VERSION; - } - - @Override - public void encodeValues(Buffer valueBuffer, List jvmGcBos) { - Assert.notEmpty(jvmGcBos, "jvmGcBos"); - - final int gcTypeCode = jvmGcBos.get(0).getGcType().getTypeCode(); - valueBuffer.putVInt(gcTypeCode); - final int numValues = jvmGcBos.size(); - valueBuffer.putVInt(numValues); - - List startTimestamps = new ArrayList<>(numValues); - List timestamps = new ArrayList<>(numValues); - JvmGcCodecEncoder jvmGcCodecEncoder = new JvmGcCodecEncoder(codec); - for (JvmGcBo jvmGcBo : jvmGcBos) { - startTimestamps.add(jvmGcBo.getStartTimestamp()); - timestamps.add(jvmGcBo.getTimestamp()); - jvmGcCodecEncoder.addValue(jvmGcBo); - } - - this.codec.encodeValues(valueBuffer, UnsignedLongEncodingStrategy.REPEAT_COUNT, startTimestamps); - this.codec.encodeTimestamps(valueBuffer, timestamps); - jvmGcCodecEncoder.encode(valueBuffer); - } - - @Override - public List decodeValues(Buffer valueBuffer, AgentStatDecodingContext decodingContext) { - final String agentId = decodingContext.getAgentId(); - final long baseTimestamp = decodingContext.getBaseTimestamp(); - final long timestampDelta = decodingContext.getTimestampDelta(); - final long initialTimestamp = baseTimestamp + timestampDelta; - - final JvmGcType gcType = JvmGcType.getTypeByCode(valueBuffer.readVInt()); - int numValues = valueBuffer.readVInt(); - List startTimestamps = this.codec.decodeValues(valueBuffer, UnsignedLongEncodingStrategy.REPEAT_COUNT, numValues); - List timestamps = this.codec.decodeTimestamps(initialTimestamp, valueBuffer, numValues); - - // decode headers - final byte[] header = valueBuffer.readPrefixedBytes(); - AgentStatHeaderDecoder headerDecoder = new BitCountingHeaderDecoder(header); - - JvmGcCodecDecoder decoder = new JvmGcCodecDecoder(codec); - decoder.decode(valueBuffer, headerDecoder, numValues); - - List jvmGcBos = new ArrayList<>(numValues); - for (int i = 0; i < numValues; i++) { - JvmGcBo jvmGcBo = decoder.getValue(i); - jvmGcBo.setAgentId(agentId); - jvmGcBo.setStartTimestamp(startTimestamps.get(i)); - jvmGcBo.setTimestamp(timestamps.get(i)); - jvmGcBo.setGcType(gcType); - jvmGcBos.add(jvmGcBo); - } - return jvmGcBos; - } - - public static class JvmGcCodecEncoder implements AgentStatCodec.CodecEncoder { - - private final AgentStatDataPointCodec codec; - UnsignedLongEncodingStrategy.Analyzer.Builder heapUsedAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - UnsignedLongEncodingStrategy.Analyzer.Builder heapMaxAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - UnsignedLongEncodingStrategy.Analyzer.Builder nonHeapUsedAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - UnsignedLongEncodingStrategy.Analyzer.Builder nonHeapMaxAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - UnsignedLongEncodingStrategy.Analyzer.Builder gcOldCountAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - UnsignedLongEncodingStrategy.Analyzer.Builder gcOldTimeAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - - public JvmGcCodecEncoder(AgentStatDataPointCodec codec) { - this.codec = codec; - } - - @Override - public void addValue(JvmGcBo jvmGcBo) { - heapUsedAnalyzerBuilder.addValue(jvmGcBo.getHeapUsed()); - heapMaxAnalyzerBuilder.addValue(jvmGcBo.getHeapMax()); - nonHeapUsedAnalyzerBuilder.addValue(jvmGcBo.getNonHeapUsed()); - nonHeapMaxAnalyzerBuilder.addValue(jvmGcBo.getNonHeapMax()); - gcOldCountAnalyzerBuilder.addValue(jvmGcBo.getGcOldCount()); - gcOldTimeAnalyzerBuilder.addValue(jvmGcBo.getGcOldTime()); - } - - @Override - public void encode(Buffer valueBuffer) { - StrategyAnalyzer heapUsedStrategyAnalyzer = heapUsedAnalyzerBuilder.build(); - StrategyAnalyzer heapMaxStrategyAnalyzer = heapMaxAnalyzerBuilder.build(); - StrategyAnalyzer nonHeapUsedStrategyAnalyzer = nonHeapUsedAnalyzerBuilder.build(); - StrategyAnalyzer nonHeapMaxStrategyAnalyzer = nonHeapMaxAnalyzerBuilder.build(); - StrategyAnalyzer gcOldCountStrategyAnalyzer = gcOldCountAnalyzerBuilder.build(); - StrategyAnalyzer gcOldTimeStrategyAnalyzer = gcOldTimeAnalyzerBuilder.build(); - // encode header - AgentStatHeaderEncoder headerEncoder = new BitCountingHeaderEncoder(); - headerEncoder.addCode(heapUsedStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(heapMaxStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(nonHeapUsedStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(nonHeapMaxStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(gcOldCountStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(gcOldTimeStrategyAnalyzer.getBestStrategy().getCode()); - final byte[] header = headerEncoder.getHeader(); - valueBuffer.putPrefixedBytes(header); - // encode values - this.codec.encodeValues(valueBuffer, heapUsedStrategyAnalyzer.getBestStrategy(), heapUsedStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, heapMaxStrategyAnalyzer.getBestStrategy(), heapMaxStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, nonHeapUsedStrategyAnalyzer.getBestStrategy(), nonHeapUsedStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, nonHeapMaxStrategyAnalyzer.getBestStrategy(), nonHeapMaxStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, gcOldCountStrategyAnalyzer.getBestStrategy(), gcOldCountStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, gcOldTimeStrategyAnalyzer.getBestStrategy(), gcOldTimeStrategyAnalyzer.getValues()); - } - - } - - public static class JvmGcCodecDecoder implements AgentStatCodec.CodecDecoder { - - private final AgentStatDataPointCodec codec; - private List heapUseds; - private List heapMaxes; - private List nonHeapUseds; - private List nonHeapMaxes; - private List gcOldCounts; - private List gcOldTimes; - - public JvmGcCodecDecoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void decode(Buffer valueBuffer, AgentStatHeaderDecoder headerDecoder, int valueSize) { - EncodingStrategy heapUsedEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy heapMaxEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy nonHeapUsedEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy nonHeapMaxEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy gcOldCountEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy gcOldTimeEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - // decode values - this.heapUseds = this.codec.decodeValues(valueBuffer, heapUsedEncodingStrategy, valueSize); - this.heapMaxes = this.codec.decodeValues(valueBuffer, heapMaxEncodingStrategy, valueSize); - this.nonHeapUseds = this.codec.decodeValues(valueBuffer, nonHeapUsedEncodingStrategy, valueSize); - this.nonHeapMaxes = this.codec.decodeValues(valueBuffer, nonHeapMaxEncodingStrategy, valueSize); - this.gcOldCounts = this.codec.decodeValues(valueBuffer, gcOldCountEncodingStrategy, valueSize); - this.gcOldTimes = this.codec.decodeValues(valueBuffer, gcOldTimeEncodingStrategy, valueSize); - } - - @Override - public JvmGcBo getValue(int index) { - JvmGcBo jvmGcBo = new JvmGcBo(); - jvmGcBo.setHeapUsed(heapUseds.get(index)); - jvmGcBo.setHeapMax(heapMaxes.get(index)); - jvmGcBo.setNonHeapUsed(nonHeapUseds.get(index)); - jvmGcBo.setNonHeapMax(nonHeapMaxes.get(index)); - jvmGcBo.setGcOldCount(gcOldCounts.get(index)); - jvmGcBo.setGcOldTime(gcOldTimes.get(index)); - return jvmGcBo; - } - - } - - -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/JvmGcDetailedCodecV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/JvmGcDetailedCodecV2.java deleted file mode 100644 index 9ca2ac5dd9ba..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/JvmGcDetailedCodecV2.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecFactory; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.StrategyAnalyzer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedLongEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatUtils; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -@Component -public class JvmGcDetailedCodecV2 extends AgentStatCodecV2 { - - public JvmGcDetailedCodecV2(AgentStatDataPointCodec codec) { - super(new JvmGcDetailedCodecFactory(codec)); - } - - - private static class JvmGcDetailedCodecFactory implements CodecFactory { - - private final AgentStatDataPointCodec codec; - - private JvmGcDetailedCodecFactory(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public AgentStatDataPointCodec getCodec() { - return codec; - } - - @Override - public CodecEncoder createCodecEncoder() { - return new JvmGcDetailedCodecEncoder(codec); - } - - @Override - public CodecDecoder createCodecDecoder() { - return new JvmGcDetailedCodecDecoder(codec); - } - } - - public static class JvmGcDetailedCodecEncoder implements AgentStatCodec.CodecEncoder { - - private final AgentStatDataPointCodec codec; - private final UnsignedLongEncodingStrategy.Analyzer.Builder gcNewCountAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder gcNewTimeAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder codeCacheUsedStrategyAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder newGenUsedStrategyAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder oldGenUsedStrategyAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder survivorSpaceUsedStrategyAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder permGenUsedStrategyAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder metaspaceUsedStrategyAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - - public JvmGcDetailedCodecEncoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void addValue(JvmGcDetailedBo jvmGcDetailedBo) { - gcNewCountAnalyzerBuilder.addValue(jvmGcDetailedBo.getGcNewCount()); - gcNewTimeAnalyzerBuilder.addValue(jvmGcDetailedBo.getGcNewTime()); - codeCacheUsedStrategyAnalyzerBuilder.addValue(AgentStatUtils.convertDoubleToLong(jvmGcDetailedBo.getCodeCacheUsed())); - newGenUsedStrategyAnalyzerBuilder.addValue(AgentStatUtils.convertDoubleToLong(jvmGcDetailedBo.getNewGenUsed())); - oldGenUsedStrategyAnalyzerBuilder.addValue(AgentStatUtils.convertDoubleToLong(jvmGcDetailedBo.getOldGenUsed())); - survivorSpaceUsedStrategyAnalyzerBuilder.addValue(AgentStatUtils.convertDoubleToLong(jvmGcDetailedBo.getSurvivorSpaceUsed())); - permGenUsedStrategyAnalyzerBuilder.addValue(AgentStatUtils.convertDoubleToLong(jvmGcDetailedBo.getPermGenUsed())); - metaspaceUsedStrategyAnalyzerBuilder.addValue(AgentStatUtils.convertDoubleToLong(jvmGcDetailedBo.getMetaspaceUsed())); - } - - @Override - public void encode(Buffer valueBuffer) { - StrategyAnalyzer gcNewCountStrategyAnalyzer = gcNewCountAnalyzerBuilder.build(); - StrategyAnalyzer gcNewTimeStrategyAnalyzer = gcNewTimeAnalyzerBuilder.build(); - StrategyAnalyzer codeCacheUsedStrategyAnalyzer = codeCacheUsedStrategyAnalyzerBuilder.build(); - StrategyAnalyzer newGenUsedStrategyAnalyzer = newGenUsedStrategyAnalyzerBuilder.build(); - StrategyAnalyzer oldGenUsedStrategyAnalyzer = oldGenUsedStrategyAnalyzerBuilder.build(); - StrategyAnalyzer survivorSpaceUsedStrategyAnalyzer = survivorSpaceUsedStrategyAnalyzerBuilder.build(); - StrategyAnalyzer permGenUsedStrategyAnalyzer = permGenUsedStrategyAnalyzerBuilder.build(); - StrategyAnalyzer metaspaceUsedStrategyAnalyzer = metaspaceUsedStrategyAnalyzerBuilder.build(); - // encode header - AgentStatHeaderEncoder headerEncoder = new BitCountingHeaderEncoder(); - headerEncoder.addCode(gcNewCountStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(gcNewTimeStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(codeCacheUsedStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(newGenUsedStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(oldGenUsedStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(survivorSpaceUsedStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(permGenUsedStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(metaspaceUsedStrategyAnalyzer.getBestStrategy().getCode()); - final byte[] header = headerEncoder.getHeader(); - valueBuffer.putPrefixedBytes(header); - // encode values - this.codec.encodeValues(valueBuffer, gcNewCountStrategyAnalyzer.getBestStrategy(), gcNewCountStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, gcNewTimeStrategyAnalyzer.getBestStrategy(), gcNewTimeStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, codeCacheUsedStrategyAnalyzer.getBestStrategy(), codeCacheUsedStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, newGenUsedStrategyAnalyzer.getBestStrategy(), newGenUsedStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, oldGenUsedStrategyAnalyzer.getBestStrategy(), oldGenUsedStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, survivorSpaceUsedStrategyAnalyzer.getBestStrategy(), survivorSpaceUsedStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, permGenUsedStrategyAnalyzer.getBestStrategy(), permGenUsedStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, metaspaceUsedStrategyAnalyzer.getBestStrategy(), metaspaceUsedStrategyAnalyzer.getValues()); - } - - } - - public static class JvmGcDetailedCodecDecoder implements AgentStatCodec.CodecDecoder { - - private final AgentStatDataPointCodec codec; - private List gcNewCounts; - private List gcNewTimes; - private List codeCacheUseds; - private List newGenUseds; - private List oldGenUseds; - private List survivorSpaceUseds; - private List permGenUseds; - private List metaspaceUseds; - - public JvmGcDetailedCodecDecoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void decode(Buffer valueBuffer, AgentStatHeaderDecoder headerDecoder, int valueSize) { - EncodingStrategy gcNewCountEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy gcNewTimeEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy codeCacheUsedEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy newGenUsedEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy oldGenUsedEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy survivorSpaceUsedEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy permGenUsedEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy metaspaceUsedEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - // decode values - this.gcNewCounts = this.codec.decodeValues(valueBuffer, gcNewCountEncodingStrategy, valueSize); - this.gcNewTimes = this.codec.decodeValues(valueBuffer, gcNewTimeEncodingStrategy, valueSize); - this.codeCacheUseds = this.codec.decodeValues(valueBuffer, codeCacheUsedEncodingStrategy, valueSize); - this.newGenUseds = this.codec.decodeValues(valueBuffer, newGenUsedEncodingStrategy, valueSize); - this.oldGenUseds = this.codec.decodeValues(valueBuffer, oldGenUsedEncodingStrategy, valueSize); - this.survivorSpaceUseds = this.codec.decodeValues(valueBuffer, survivorSpaceUsedEncodingStrategy, valueSize); - this.permGenUseds = this.codec.decodeValues(valueBuffer, permGenUsedEncodingStrategy, valueSize); - this.metaspaceUseds = this.codec.decodeValues(valueBuffer, metaspaceUsedEncodingStrategy, valueSize); - } - - @Override - public JvmGcDetailedBo getValue(int index) { - JvmGcDetailedBo jvmGcDetailedBo = new JvmGcDetailedBo(); - jvmGcDetailedBo.setGcNewCount(gcNewCounts.get(index)); - jvmGcDetailedBo.setGcNewTime(gcNewTimes.get(index)); - jvmGcDetailedBo.setCodeCacheUsed(AgentStatUtils.convertLongToDouble(codeCacheUseds.get(index))); - jvmGcDetailedBo.setNewGenUsed(AgentStatUtils.convertLongToDouble(newGenUseds.get(index))); - jvmGcDetailedBo.setOldGenUsed(AgentStatUtils.convertLongToDouble(oldGenUseds.get(index))); - jvmGcDetailedBo.setSurvivorSpaceUsed(AgentStatUtils.convertLongToDouble(survivorSpaceUseds.get(index))); - jvmGcDetailedBo.setPermGenUsed(AgentStatUtils.convertLongToDouble(permGenUseds.get(index))); - jvmGcDetailedBo.setMetaspaceUsed(AgentStatUtils.convertLongToDouble(metaspaceUseds.get(index))); - return jvmGcDetailedBo; - } - - } - -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/LoadedClassCodecV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/LoadedClassCodecV2.java deleted file mode 100644 index aa6e43d432e7..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/LoadedClassCodecV2.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2020 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecFactory; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.StrategyAnalyzer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedLongEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.stat.LoadedClassBo; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Objects; - -@Component -public class LoadedClassCodecV2 extends AgentStatCodecV2 { - public LoadedClassCodecV2(AgentStatDataPointCodec codec) { - super(new LoadedClassCodecV2.LoadedClassCodecFactory(codec)); - } - - private static class LoadedClassCodecFactory implements CodecFactory { - private final AgentStatDataPointCodec codec; - - public LoadedClassCodecFactory(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public AgentStatDataPointCodec getCodec() { return codec; } - - @Override - public CodecEncoder createCodecEncoder() { - return new LoadedClassEncoder(codec); - } - - @Override - public CodecDecoder createCodecDecoder() { - return new LoadedClassDecoder(codec); - } - } - - private static class LoadedClassEncoder implements CodecEncoder { - private final AgentStatDataPointCodec codec; - private final UnsignedLongEncodingStrategy.Analyzer.Builder loadedClassAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder unloadedClassAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - - public LoadedClassEncoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void addValue(LoadedClassBo agentStatDataPoint) { - loadedClassAnalyzerBuilder.addValue(agentStatDataPoint.getLoadedClassCount()); - unloadedClassAnalyzerBuilder.addValue(agentStatDataPoint.getUnloadedClassCount()); - } - - @Override - public void encode(Buffer valueBuffer) { - StrategyAnalyzer loadedClassStrategyAnalyzer = loadedClassAnalyzerBuilder.build(); - StrategyAnalyzer unloadedClassStrategyAnalyzer = unloadedClassAnalyzerBuilder.build(); - - // encode header - AgentStatHeaderEncoder headerEncoder = new BitCountingHeaderEncoder(); - headerEncoder.addCode(loadedClassStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(unloadedClassStrategyAnalyzer.getBestStrategy().getCode()); - - final byte[] header = headerEncoder.getHeader(); - valueBuffer.putPrefixedBytes(header); - // encode values - this.codec.encodeValues(valueBuffer, loadedClassStrategyAnalyzer.getBestStrategy(), loadedClassStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, unloadedClassStrategyAnalyzer.getBestStrategy(), unloadedClassStrategyAnalyzer.getValues()); - - } - } - - private static class LoadedClassDecoder implements CodecDecoder { - private final AgentStatDataPointCodec codec; - - private List loadedClassCount; - private List unloadedClassCount; - public LoadedClassDecoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void decode(Buffer valueBuffer, AgentStatHeaderDecoder headerDecoder, int valueSize) { - EncodingStrategy loadedClassEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy unloadedClassEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - // decode values - this.loadedClassCount = this.codec.decodeValues(valueBuffer, loadedClassEncodingStrategy, valueSize); - this.unloadedClassCount = this.codec.decodeValues(valueBuffer, unloadedClassEncodingStrategy, valueSize); - } - - @Override - public LoadedClassBo getValue(int index) { - LoadedClassBo loadedClassBo = new LoadedClassBo(); - loadedClassBo.setLoadedClassCount(loadedClassCount.get(index)); - loadedClassBo.setUnloadedClassCount(unloadedClassCount.get(index)); - return loadedClassBo; - } - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/ResponseTimeCodecV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/ResponseTimeCodecV2.java deleted file mode 100644 index 78dee4f4985b..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/ResponseTimeCodecV2.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2017 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecFactory; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.StrategyAnalyzer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedLongEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.stat.ResponseTimeBo; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Objects; - -/** - * @author Taejin Koo - */ -@Component -public class ResponseTimeCodecV2 extends AgentStatCodecV2 { - - public ResponseTimeCodecV2(AgentStatDataPointCodec codec) { - super(new ResponseTimeFactory(codec)); - } - - private static class ResponseTimeFactory implements CodecFactory { - - private final AgentStatDataPointCodec codec; - - private ResponseTimeFactory(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public AgentStatDataPointCodec getCodec() { - return codec; - } - - @Override - public CodecEncoder createCodecEncoder() { - return new ResponseTimeCodecEncoder(codec); - } - - @Override - public CodecDecoder createCodecDecoder() { - return new ResponseTimeCodecDecoder(codec); - } - } - - private static class ResponseTimeCodecEncoder implements AgentStatCodec.CodecEncoder { - - private final AgentStatDataPointCodec codec; - private final UnsignedLongEncodingStrategy.Analyzer.Builder avgAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder maxAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - - public ResponseTimeCodecEncoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void addValue(ResponseTimeBo agentStatDataPoint) { - avgAnalyzerBuilder.addValue(agentStatDataPoint.getAvg()); - maxAnalyzerBuilder.addValue(agentStatDataPoint.getMax()); - } - - @Override - public void encode(Buffer valueBuffer) { - StrategyAnalyzer avgStrategyAnalyzer = avgAnalyzerBuilder.build(); - StrategyAnalyzer maxStrategyAnalyzer = maxAnalyzerBuilder.build(); - - // encode header - AgentStatHeaderEncoder headerEncoder = new BitCountingHeaderEncoder(); - headerEncoder.addCode(avgStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(maxStrategyAnalyzer.getBestStrategy().getCode()); - - final byte[] header = headerEncoder.getHeader(); - valueBuffer.putPrefixedBytes(header); - // encode values - codec.encodeValues(valueBuffer, avgStrategyAnalyzer.getBestStrategy(), avgStrategyAnalyzer.getValues()); - codec.encodeValues(valueBuffer, maxStrategyAnalyzer.getBestStrategy(), maxStrategyAnalyzer.getValues()); - } - - } - - private static class ResponseTimeCodecDecoder implements AgentStatCodec.CodecDecoder { - - private final AgentStatDataPointCodec codec; - private List avgs; - private List maxs; - - public ResponseTimeCodecDecoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void decode(Buffer valueBuffer, AgentStatHeaderDecoder headerDecoder, int valueSize) { - EncodingStrategy avgEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy maxEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - - this.avgs = codec.decodeValues(valueBuffer, avgEncodingStrategy, valueSize); - if (valueBuffer.hasRemaining()) { - this.maxs = codec.decodeValues(valueBuffer, maxEncodingStrategy, valueSize); - } - } - - @Override - public ResponseTimeBo getValue(int index) { - ResponseTimeBo responseTimeBo = new ResponseTimeBo(); - responseTimeBo.setAvg(avgs.get(index)); - if (maxs != null) { - responseTimeBo.setMax(maxs.get(index)); - } - return responseTimeBo; - } - - } - -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/TotalThreadCountCodecV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/TotalThreadCountCodecV2.java deleted file mode 100644 index 6288e68dc219..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/TotalThreadCountCodecV2.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2020 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecFactory; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.StrategyAnalyzer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedLongEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.stat.TotalThreadCountBo; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Objects; - -@Component -public class TotalThreadCountCodecV2 extends AgentStatCodecV2 { - - public TotalThreadCountCodecV2(AgentStatDataPointCodec codec) { - super(new TotalThreadCountCodecV2.TotalThreadCountCodecFactory(codec)); - } - - private static class TotalThreadCountCodecFactory implements CodecFactory { - - private final AgentStatDataPointCodec codec; - - private TotalThreadCountCodecFactory(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec); - } - - @Override - public AgentStatDataPointCodec getCodec() { return codec; } - - @Override - public CodecEncoder createCodecEncoder() { - return new TotalThreadCountEncoder(codec); - } - - @Override - public CodecDecoder createCodecDecoder() { - return new TotalThreadCountDecoder(codec); - } - } - - private static class TotalThreadCountEncoder implements AgentStatCodec.CodecEncoder { - private final AgentStatDataPointCodec codec; - private final UnsignedLongEncodingStrategy.Analyzer.Builder totalThreadCountAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - - public TotalThreadCountEncoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void addValue(TotalThreadCountBo agentStatDataPoint) { - totalThreadCountAnalyzerBuilder.addValue(agentStatDataPoint.getTotalThreadCount()); - } - - @Override - public void encode(Buffer valueBuffer) { - StrategyAnalyzer totalThreadCountStrategyAnalyzer = totalThreadCountAnalyzerBuilder.build(); - - // encode header - AgentStatHeaderEncoder headerEncoder = new BitCountingHeaderEncoder(); - headerEncoder.addCode(totalThreadCountStrategyAnalyzer.getBestStrategy().getCode()); - final byte[] header = headerEncoder.getHeader(); - valueBuffer.putPrefixedBytes(header); - // encode values - this.codec.encodeValues(valueBuffer, totalThreadCountStrategyAnalyzer.getBestStrategy(), totalThreadCountStrategyAnalyzer.getValues()); - - } - } - - private static class TotalThreadCountDecoder implements AgentStatCodec.CodecDecoder { - private final AgentStatDataPointCodec codec; - private List totalThreadCounts; - - public TotalThreadCountDecoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void decode(Buffer valueBuffer, AgentStatHeaderDecoder headerDecoder, int valueSize) { - EncodingStrategy totalThreadCountEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - // decode values - this.totalThreadCounts = this.codec.decodeValues(valueBuffer, totalThreadCountEncodingStrategy, valueSize); - } - - @Override - public TotalThreadCountBo getValue(int index) { - TotalThreadCountBo totalThreadCountBo = new TotalThreadCountBo(); - totalThreadCountBo.setTotalThreadCount(totalThreadCounts.get(index)); - return totalThreadCountBo; - } - } - -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/TransactionCodecV2.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/TransactionCodecV2.java deleted file mode 100644 index 284bbd2ce164..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/TransactionCodecV2.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecFactory; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.AgentStatHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.header.BitCountingHeaderEncoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.StrategyAnalyzer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.strategy.UnsignedLongEncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -@Component -public class TransactionCodecV2 extends AgentStatCodecV2 { - - public TransactionCodecV2(AgentStatDataPointCodec codec) { - super(new TransactionFactory(codec)); - } - - - private static class TransactionFactory implements CodecFactory { - - private final AgentStatDataPointCodec codec; - - private TransactionFactory(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public AgentStatDataPointCodec getCodec() { - return codec; - } - - @Override - public CodecEncoder createCodecEncoder() { - return new TransactionCodecEncoder(codec); - } - - @Override - public CodecDecoder createCodecDecoder() { - return new TransactionCodecDecoder(codec); - } - } - - public static class TransactionCodecEncoder implements AgentStatCodec.CodecEncoder { - - private final AgentStatDataPointCodec codec; - private final UnsignedLongEncodingStrategy.Analyzer.Builder collectIntervalAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder sampledNewCountAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder sampledContinuationCountAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder unsampledNewCountAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder unsampledContinuationCountAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder skippedNewCountAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - private final UnsignedLongEncodingStrategy.Analyzer.Builder skippedContinuationCountAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder(); - - public TransactionCodecEncoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void addValue(TransactionBo transactionBo) { - collectIntervalAnalyzerBuilder.addValue(transactionBo.getCollectInterval()); - sampledNewCountAnalyzerBuilder.addValue(transactionBo.getSampledNewCount()); - sampledContinuationCountAnalyzerBuilder.addValue(transactionBo.getSampledContinuationCount()); - unsampledNewCountAnalyzerBuilder.addValue(transactionBo.getUnsampledNewCount()); - unsampledContinuationCountAnalyzerBuilder.addValue(transactionBo.getUnsampledContinuationCount()); - skippedNewCountAnalyzerBuilder.addValue(transactionBo.getSkippedNewSkipCount()); - skippedContinuationCountAnalyzerBuilder.addValue(transactionBo.getSkippedContinuationCount()); - } - - @Override - public void encode(Buffer valueBuffer) { - StrategyAnalyzer collectIntervalStrategyAnalyzer = collectIntervalAnalyzerBuilder.build(); - StrategyAnalyzer sampledNewCountStrategyAnalyzer = sampledNewCountAnalyzerBuilder.build(); - StrategyAnalyzer sampledContinuationCountStrategyAnalyzer = sampledContinuationCountAnalyzerBuilder.build(); - StrategyAnalyzer unsampledNewCountStrategyAnalyzer = unsampledNewCountAnalyzerBuilder.build(); - StrategyAnalyzer unsampledContinuationCountStrategyAnalyzer = unsampledContinuationCountAnalyzerBuilder.build(); - StrategyAnalyzer skippedNewCountStrategyAnalyzer = skippedNewCountAnalyzerBuilder.build(); - StrategyAnalyzer skippedContinuationCountStrategyAnalyzer = skippedContinuationCountAnalyzerBuilder.build(); - - // encode header - AgentStatHeaderEncoder headerEncoder = new BitCountingHeaderEncoder(); - headerEncoder.addCode(collectIntervalStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(sampledNewCountStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(sampledContinuationCountStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(unsampledNewCountStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(unsampledContinuationCountStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(skippedNewCountStrategyAnalyzer.getBestStrategy().getCode()); - headerEncoder.addCode(skippedContinuationCountStrategyAnalyzer.getBestStrategy().getCode()); - - final byte[] header = headerEncoder.getHeader(); - valueBuffer.putPrefixedBytes(header); - // encode values - this.codec.encodeValues(valueBuffer, collectIntervalStrategyAnalyzer.getBestStrategy(), collectIntervalStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, sampledNewCountStrategyAnalyzer.getBestStrategy(), sampledNewCountStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, sampledContinuationCountStrategyAnalyzer.getBestStrategy(), sampledContinuationCountStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, unsampledNewCountStrategyAnalyzer.getBestStrategy(), unsampledNewCountStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, unsampledContinuationCountStrategyAnalyzer.getBestStrategy(), unsampledContinuationCountStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, skippedNewCountStrategyAnalyzer.getBestStrategy(), skippedNewCountStrategyAnalyzer.getValues()); - this.codec.encodeValues(valueBuffer, skippedContinuationCountStrategyAnalyzer.getBestStrategy(), skippedContinuationCountStrategyAnalyzer.getValues()); - } - - } - - public static class TransactionCodecDecoder implements AgentStatCodec.CodecDecoder { - - private final AgentStatDataPointCodec codec; - private List collectIntervals; - private List sampledNewCounts; - private List sampledContinuationCounts; - private List unsampledNewCounts; - private List unsampledContinuationCounts; - private List skippedNewCounts; - private List skippedContinuationCounts; - - public TransactionCodecDecoder(AgentStatDataPointCodec codec) { - this.codec = Objects.requireNonNull(codec, "codec"); - } - - @Override - public void decode(Buffer valueBuffer, AgentStatHeaderDecoder headerDecoder, int valueSize) { - EncodingStrategy collectIntervalEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy sampledNewCountEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy sampledContinuationCountEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy unsampledNewCountEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy unsampledContinuationCountEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - - EncodingStrategy skippedNewCountEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - EncodingStrategy skippedContinuationCountEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode()); - - // decode values - this.collectIntervals = this.codec.decodeValues(valueBuffer, collectIntervalEncodingStrategy, valueSize); - this.sampledNewCounts = this.codec.decodeValues(valueBuffer, sampledNewCountEncodingStrategy, valueSize); - this.sampledContinuationCounts = this.codec.decodeValues(valueBuffer, sampledContinuationCountEncodingStrategy, valueSize); - this.unsampledNewCounts = this.codec.decodeValues(valueBuffer, unsampledNewCountEncodingStrategy, valueSize); - this.unsampledContinuationCounts = this.codec.decodeValues(valueBuffer, unsampledContinuationCountEncodingStrategy, valueSize); - if (valueBuffer.remaining() > 0) { - // Since 1.8.5-SNAPSHOT - this.skippedNewCounts = this.codec.decodeValues(valueBuffer, skippedNewCountEncodingStrategy, valueSize); - this.skippedContinuationCounts = this.codec.decodeValues(valueBuffer, skippedContinuationCountEncodingStrategy, valueSize); - } - } - - @Override - public TransactionBo getValue(int index) { - TransactionBo transactionBo = new TransactionBo(); - transactionBo.setCollectInterval(collectIntervals.get(index)); - transactionBo.setSampledNewCount(sampledNewCounts.get(index)); - transactionBo.setSampledContinuationCount(sampledContinuationCounts.get(index)); - transactionBo.setUnsampledNewCount(unsampledNewCounts.get(index)); - transactionBo.setUnsampledContinuationCount(unsampledContinuationCounts.get(index)); - if (skippedNewCounts != null) { - transactionBo.setSkippedNewSkipCount(skippedNewCounts.get(index)); - } - if (skippedContinuationCounts != null) { - transactionBo.setSkippedContinuationCount(skippedContinuationCounts.get(index)); - } - return transactionBo; - } - - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatDecodingContext.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatDecodingContext.java deleted file mode 100644 index ad5a3b5835a4..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatDecodingContext.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.serializer.stat; - -/** - * @author HyunGil Jeong - */ -public class AgentStatDecodingContext { - - private String agentId; - - private long baseTimestamp; - - private long timestampDelta; - - public String getAgentId() { - return agentId; - } - - public void setAgentId(String agentId) { - this.agentId = agentId; - } - - public long getBaseTimestamp() { - return baseTimestamp; - } - - public void setBaseTimestamp(long baseTimestamp) { - this.baseTimestamp = baseTimestamp; - } - - public long getTimestampDelta() { - return timestampDelta; - } - - public void setTimestampDelta(long timestampDelta) { - this.timestampDelta = timestampDelta; - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatHbaseOperationFactory.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatHbaseOperationFactory.java deleted file mode 100644 index 6b91d8821d9a..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatHbaseOperationFactory.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.serializer.stat; - -import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; -import com.navercorp.pinpoint.common.server.bo.serializer.HbaseSerializer; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; -import com.sematext.hbase.wd.AbstractRowKeyDistributor; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.client.Scan; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.TreeMap; - -/** - * @author HyunGil Jeong - */ -public class AgentStatHbaseOperationFactory { - - private final AgentStatRowKeyEncoder rowKeyEncoder; - - private final AgentStatRowKeyDecoder rowKeyDecoder; - - private final AbstractRowKeyDistributor rowKeyDistributor; - - public AgentStatHbaseOperationFactory( - AgentStatRowKeyEncoder rowKeyEncoder, - AgentStatRowKeyDecoder rowKeyDecoder, - AbstractRowKeyDistributor rowKeyDistributor) { - this.rowKeyEncoder = Objects.requireNonNull(rowKeyEncoder, "rowKeyEncoder"); - this.rowKeyDecoder = Objects.requireNonNull(rowKeyDecoder, "rowKeyDecoder"); - this.rowKeyDistributor = Objects.requireNonNull(rowKeyDistributor, "rowKeyDistributor"); - } - - public List createPuts(String agentId, AgentStatType agentStatType, List agentStatDataPoints, HbaseSerializer, Put> agentStatSerializer) { - if (CollectionUtils.isEmpty(agentStatDataPoints)) { - return Collections.emptyList(); - } - Map> timeslots = slotAgentStatDataPoints(agentStatDataPoints); - List puts = new ArrayList<>(); - for (Map.Entry> timeslot : timeslots.entrySet()) { - long baseTimestamp = timeslot.getKey(); - List slottedAgentStatDataPoints = timeslot.getValue(); - - final AgentStatRowKeyComponent rowKeyComponent = new AgentStatRowKeyComponent(agentId, agentStatType, baseTimestamp); - byte[] rowKey = this.rowKeyEncoder.encodeRowKey(rowKeyComponent); - byte[] distributedRowKey = this.rowKeyDistributor.getDistributedKey(rowKey); - - Put put = new Put(distributedRowKey, true); - agentStatSerializer.serialize(slottedAgentStatDataPoints, put, null); - puts.add(put); - } - return puts; - } - - public Scan createScan(String agentId, AgentStatType agentStatType, long startTimestamp, long endTimestamp) { - final AgentStatRowKeyComponent startRowKeyComponent = new AgentStatRowKeyComponent(agentId, agentStatType, AgentStatUtils.getBaseTimestamp(endTimestamp)); - final AgentStatRowKeyComponent endRowKeyComponent = new AgentStatRowKeyComponent(agentId, agentStatType, AgentStatUtils.getBaseTimestamp(startTimestamp) - HbaseColumnFamily.AGENT_STAT_STATISTICS.TIMESPAN_MS); - byte[] startRowKey = this.rowKeyEncoder.encodeRowKey(startRowKeyComponent); - byte[] endRowKey = this.rowKeyEncoder.encodeRowKey(endRowKeyComponent); - Scan scan = new Scan(); - scan.withStartRow(startRowKey); - scan.withStopRow(endRowKey); - return scan; - } - - public AbstractRowKeyDistributor getRowKeyDistributor() { - return this.rowKeyDistributor; - } - - public String getAgentId(byte[] distributedRowKey) { - byte[] originalRowKey = this.rowKeyDistributor.getOriginalKey(distributedRowKey); - return this.rowKeyDecoder.decodeRowKey(originalRowKey).getAgentId(); - } - - public AgentStatType getAgentStatType(byte[] distributedRowKey) { - byte[] originalRowKey = this.rowKeyDistributor.getOriginalKey(distributedRowKey); - return this.rowKeyDecoder.decodeRowKey(originalRowKey).getAgentStatType(); - } - - public long getBaseTimestamp(byte[] distributedRowKey) { - byte[] originalRowKey = this.rowKeyDistributor.getOriginalKey(distributedRowKey); - return this.rowKeyDecoder.decodeRowKey(originalRowKey).getBaseTimestamp(); - } - - private Map> slotAgentStatDataPoints(List agentStatDataPoints) { - Map> timeslots = new TreeMap<>(); - for (T agentStatDataPoint : agentStatDataPoints) { - long timestamp = agentStatDataPoint.getTimestamp(); - long timeslot = AgentStatUtils.getBaseTimestamp(timestamp); - List slottedDataPoints = timeslots.computeIfAbsent(timeslot, k -> new ArrayList<>()); - slottedDataPoints.add(agentStatDataPoint); - } - return timeslots; - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatRowKeyComponent.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatRowKeyComponent.java deleted file mode 100644 index 43e2198c178d..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatRowKeyComponent.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.serializer.stat; - -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; - -/** - * @author HyunGil Jeong - */ -public class AgentStatRowKeyComponent { - - private final String agentId; - private final AgentStatType agentStatType; - private final long baseTimestamp; - - public AgentStatRowKeyComponent(String agentId, AgentStatType agentStatType, long baseTimestamp) { - this.agentId = agentId; - this.agentStatType = agentStatType; - this.baseTimestamp = baseTimestamp; - } - - public String getAgentId() { - return this.agentId; - } - - public AgentStatType getAgentStatType() { - return this.agentStatType; - } - - public long getBaseTimestamp() { - return this.baseTimestamp; - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatRowKeyDecoder.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatRowKeyDecoder.java deleted file mode 100644 index dccf2f17cfe0..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatRowKeyDecoder.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.serializer.stat; - -import com.navercorp.pinpoint.common.server.bo.serializer.RowKeyDecoder; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; -import com.navercorp.pinpoint.common.util.BytesUtils; -import com.navercorp.pinpoint.common.util.TimeUtils; - -import static com.navercorp.pinpoint.common.hbase.HbaseTableConstants.AGENT_ID_MAX_LEN; -import static com.navercorp.pinpoint.common.server.bo.stat.AgentStatType.TYPE_CODE_BYTE_LENGTH; - -/** - * @author HyunGil Jeong - */ -public class AgentStatRowKeyDecoder implements RowKeyDecoder { - - @Override - public AgentStatRowKeyComponent decodeRowKey(byte[] rowkey) { - final String agentId = BytesUtils.toStringAndRightTrim(rowkey, 0, AGENT_ID_MAX_LEN); - final AgentStatType agentStatType = AgentStatType.fromTypeCode(rowkey[AGENT_ID_MAX_LEN]); - final long reversedBaseTimestamp = BytesUtils.bytesToLong(rowkey, AGENT_ID_MAX_LEN + TYPE_CODE_BYTE_LENGTH); - final long baseTimestamp = TimeUtils.recoveryTimeMillis(reversedBaseTimestamp); - return new AgentStatRowKeyComponent(agentId, agentStatType, baseTimestamp); - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatRowKeyEncoder.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatRowKeyEncoder.java deleted file mode 100644 index a0ef06b2c3b1..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatRowKeyEncoder.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.serializer.stat; - -import com.navercorp.pinpoint.common.server.bo.serializer.RowKeyEncoder; -import com.navercorp.pinpoint.common.util.BytesUtils; -import com.navercorp.pinpoint.common.util.TimeUtils; - -import java.util.Objects; - -import static com.navercorp.pinpoint.common.hbase.HbaseTableConstants.AGENT_ID_MAX_LEN; - -/** - * @author HyunGil Jeong - */ -public class AgentStatRowKeyEncoder implements RowKeyEncoder { - - @Override - public byte[] encodeRowKey(AgentStatRowKeyComponent component) { - Objects.requireNonNull(component, "component"); - - byte[] bAgentId = BytesUtils.toBytes(component.getAgentId()); - byte[] bStatType = new byte[]{component.getAgentStatType().getRawTypeCode()}; - byte[] rowKey = new byte[AGENT_ID_MAX_LEN + bStatType.length + BytesUtils.LONG_BYTE_LENGTH]; - - BytesUtils.writeBytes(rowKey, 0, bAgentId); - BytesUtils.writeBytes(rowKey, AGENT_ID_MAX_LEN, bStatType); - BytesUtils.writeLong(TimeUtils.reverseTimeMillis(component.getBaseTimestamp()), rowKey, AGENT_ID_MAX_LEN + bStatType.length); - - return rowKey; - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatSerializer.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatSerializer.java deleted file mode 100644 index 5e2c5233f30b..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatSerializer.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.serializer.stat; - -import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatEncoder; -import com.navercorp.pinpoint.common.server.bo.serializer.HbaseSerializer; -import com.navercorp.pinpoint.common.server.bo.serializer.SerializationContext; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.client.Put; - -import java.nio.ByteBuffer; -import java.util.List; -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -public class AgentStatSerializer implements HbaseSerializer, Put> { - - private final AgentStatEncoder encoder; - - public AgentStatSerializer(AgentStatEncoder encoder) { - this.encoder = Objects.requireNonNull(encoder, "encoder"); - } - - @Override - public void serialize(List agentStatBos, Put put, SerializationContext context) { - if (CollectionUtils.isEmpty(agentStatBos)) { - throw new IllegalArgumentException("agentStatBos should not be empty"); - } - long initialTimestamp = agentStatBos.get(0).getTimestamp(); - long baseTimestamp = AgentStatUtils.getBaseTimestamp(initialTimestamp); - long timestampDelta = initialTimestamp - baseTimestamp; - ByteBuffer qualifierBuffer = this.encoder.encodeQualifier(timestampDelta); - ByteBuffer valueBuffer = this.encoder.encodeValue(agentStatBos); - put.addColumn(HbaseColumnFamily.AGENT_STAT_STATISTICS.getName(), qualifierBuffer, HConstants.LATEST_TIMESTAMP, valueBuffer); - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatUtils.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatUtils.java deleted file mode 100644 index 22022fe6500f..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatUtils.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.serializer.stat; - -import com.navercorp.pinpoint.common.profiler.clock.Clock; -import com.navercorp.pinpoint.common.profiler.clock.TickClock; -import org.apache.commons.math3.util.Precision; - -import static com.navercorp.pinpoint.common.hbase.HbaseColumnFamily.AGENT_STAT_STATISTICS; - -/** - * @author HyunGil Jeong - */ -public class AgentStatUtils { - - public static final int NUM_DECIMALS = 4; - public static final long CONVERT_VALUE = (long) Math.pow(10, NUM_DECIMALS); - - private static final TickClock CLOCK = new TickClock(Clock.systemUTC(), AGENT_STAT_STATISTICS.TIMESPAN_MS); - - public static long convertDoubleToLong(double value) { - long convertedValue = (long) (value * CONVERT_VALUE); - return convertedValue; - } - - public static double convertLongToDouble(long value) { - double convertedValue = ((double) value) / CONVERT_VALUE; - return convertedValue; - } - - public static double calculateRate(long count, long timeMs, int numDecimals, double defaultRate) { - if (numDecimals < 0) { - throw new IllegalArgumentException("numDecimals must be greater than 0"); - } - if (timeMs < 1) { - return defaultRate; - } - return Precision.round(count / (timeMs / 1000D), numDecimals); - } - - public static long getBaseTimestamp(long timestamp) { - return CLOCK.tick(timestamp); - } -} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/config/AgentStatSerializeConfiguration.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/config/AgentStatSerializeConfiguration.java deleted file mode 100644 index 1ab68d22dfa9..000000000000 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/config/AgentStatSerializeConfiguration.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.navercorp.pinpoint.common.server.bo.serializer.stat.config; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatEncoder; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatHbaseOperationFactory; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatRowKeyDecoder; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatRowKeyEncoder; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatSerializer; -import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; -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.DeadlockThreadCountBo; -import com.navercorp.pinpoint.common.server.bo.stat.DirectBufferBo; -import com.navercorp.pinpoint.common.server.bo.stat.FileDescriptorBo; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; -import com.navercorp.pinpoint.common.server.bo.stat.LoadedClassBo; -import com.navercorp.pinpoint.common.server.bo.stat.ResponseTimeBo; -import com.navercorp.pinpoint.common.server.bo.stat.TotalThreadCountBo; -import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; -import com.sematext.hbase.wd.AbstractRowKeyDistributor; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class AgentStatSerializeConfiguration { - - @Bean - public AgentStatHbaseOperationFactory agentStatHbaseOperationFactory( - AgentStatRowKeyEncoder rowKeyEncoder, - AgentStatRowKeyDecoder rowKeyDecoder, - @Qualifier("agentStatV2RowKeyDistributor") AbstractRowKeyDistributor rowKeyDistributor) { - return new AgentStatHbaseOperationFactory(rowKeyEncoder, rowKeyDecoder, rowKeyDistributor); - } - - @Bean - public AgentStatRowKeyDecoder agentStatRowKeyDecoder() { - return new AgentStatRowKeyDecoder(); - } - - @Bean - public AgentStatRowKeyEncoder agentStatRowKeyEncoder() { - return new AgentStatRowKeyEncoder(); - } - - @Bean - public AgentStatSerializer getAgentActiveTraceSerializer(AgentStatEncoder coder) { - return new AgentStatSerializer<>(coder); - } - - @Bean - public AgentStatSerializer getAgentCpuLoadSerializer(AgentStatEncoder coder) { - return new AgentStatSerializer<>(coder); - } - - @Bean - public AgentStatSerializer getAgentDataSourceSerializer(AgentStatEncoder coder) { - return new AgentStatSerializer<>(coder); - } - - @Bean - public AgentStatSerializer getAgentDeadlockThreadCountSerializer(AgentStatEncoder coder) { - return new AgentStatSerializer<>(coder); - } - - @Bean - public AgentStatSerializer getAgentDirectBufferSerializer(AgentStatEncoder coder) { - return new AgentStatSerializer<>(coder); - } - - @Bean - public AgentStatSerializer getAgentFileDescriptorSerializer(AgentStatEncoder coder) { - return new AgentStatSerializer<>(coder); - } - - @Bean - public AgentStatSerializer getAgentJvmGcDetailedSerializer(AgentStatEncoder coder) { - return new AgentStatSerializer<>(coder); - } - - @Bean - public AgentStatSerializer getAgentJvmGcSerializer(AgentStatEncoder coder) { - return new AgentStatSerializer<>(coder); - } - - @Bean - public AgentStatSerializer getAgentLoadedClassSerializer(AgentStatEncoder coder) { - return new AgentStatSerializer<>(coder); - } - - @Bean - public AgentStatSerializer getAgentResponseTimeSerializer(AgentStatEncoder coder) { - return new AgentStatSerializer<>(coder); - } - - @Bean - public AgentStatSerializer getAgentTotalThreadCountSerializer(AgentStatEncoder coder) { - return new AgentStatSerializer<>(coder); - } - - @Bean - public AgentStatSerializer getAgentTransactionSerializer(AgentStatEncoder coder) { - return new AgentStatSerializer<>(coder); - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatCodecTestBase.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatCodecTestBase.java deleted file mode 100644 index dcb0e0ae9d23..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatCodecTestBase.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat; - -import com.navercorp.pinpoint.common.buffer.AutomaticBuffer; -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.buffer.FixedBuffer; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatUtils; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -public abstract class AgentStatCodecTestBase { - - private static final String AGENT_ID = "testAgentId"; - private static final long AGENT_START_TIMESTAMP = System.currentTimeMillis(); - private static final int NUM_TEST_RUNS = 20; - - protected abstract List createAgentStats(String agentId, long startTimestamp, long initialTimestamp); - - protected abstract AgentStatCodec getCodec(); - - protected abstract void verify(T expected, T actual); - - @Test - public void should_be_encoded_and_decoded_to_same_value() { - for (int i = 0; i < NUM_TEST_RUNS; i++) { - runTest(); - } - } - - private void runTest() { - // Given - final long initialTimestamp = System.currentTimeMillis(); - final long baseTimestamp = AgentStatUtils.getBaseTimestamp(initialTimestamp); - final long timestampDelta = initialTimestamp - baseTimestamp; - final List expectedAgentStats = createAgentStats(AGENT_ID, AGENT_START_TIMESTAMP, initialTimestamp); - // When - Buffer encodedValueBuffer = new AutomaticBuffer(); - getCodec().encodeValues(encodedValueBuffer, expectedAgentStats); - // Then - AgentStatDecodingContext decodingContext = new AgentStatDecodingContext(); - decodingContext.setAgentId(AGENT_ID); - decodingContext.setBaseTimestamp(baseTimestamp); - decodingContext.setTimestampDelta(timestampDelta); - - Buffer valueBuffer = new FixedBuffer(encodedValueBuffer.getBuffer()); - List actualAgentStats = getCodec().decodeValues(valueBuffer, decodingContext); - Assertions.assertEquals(expectedAgentStats.size(), actualAgentStats.size()); - for (int i = 0; i < expectedAgentStats.size(); i++) { - T expectedAgentStat = expectedAgentStats.get(i); - T actualAgentStat = actualAgentStats.get(i); - verify(expectedAgentStat, actualAgentStat); - } - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatDataPointCodecTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatDataPointCodecTest.java deleted file mode 100644 index d3137421b92e..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatDataPointCodecTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat; - -import com.navercorp.pinpoint.common.buffer.AutomaticBuffer; -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.buffer.FixedBuffer; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author HyunGil Jeong - */ -public class AgentStatDataPointCodecTest { - - private final AgentStatDataPointCodec codec = new AgentStatDataPointCodec(); - - @Test - public void test_timestamps() { - // Given - final long initialTimestamp = System.currentTimeMillis(); - final long intervalMs = 5000L; - final long randomDelta = 10L; - final int numValues = (int) (Math.random() * 100) + 1; - final List expectedTimestamps = createTimestamps(initialTimestamp, intervalMs, randomDelta, numValues); - final Buffer timestampBuffer = new AutomaticBuffer(); - // When - codec.encodeTimestamps(timestampBuffer, expectedTimestamps); - // Then - List decodedTimestamps = codec.decodeTimestamps(initialTimestamp, new FixedBuffer(timestampBuffer.getBuffer()), numValues); - Assertions.assertEquals(expectedTimestamps, decodedTimestamps); - } - - @Test - public void test_single_timestamp() { - // Given - final long givenTimestamp = System.currentTimeMillis(); - final List expectedTimestamp = List.of(givenTimestamp); - final Buffer timestampBuffer = new AutomaticBuffer(); - // When - codec.encodeTimestamps(timestampBuffer, expectedTimestamp); - // Then - List decodedTimestamp = codec.decodeTimestamps(givenTimestamp, new FixedBuffer(timestampBuffer.getBuffer()), 1); - Assertions.assertEquals(expectedTimestamp, decodedTimestamp); - } - - private List createTimestamps(long initialTimestampMs, long intervalMs, long randomDelta, int numValues) { - List timestamps = new ArrayList<>(numValues); - timestamps.add(initialTimestampMs); - long prevTimestamp = initialTimestampMs; - for (int i = 1; i < numValues; i++) { - long delta = ((long) (Math.random() * (randomDelta * 2))) - randomDelta; - long timestamp = prevTimestamp + (intervalMs + delta); - timestamps.add(timestamp); - prevTimestamp = timestamp; - } - return timestamps; - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatEncoderTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatEncoderTest.java deleted file mode 100644 index 5e8109766f20..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/AgentStatEncoderTest.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.buffer.FixedBuffer; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatUtils; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -/** - * @author HyunGil Jeong - */ -public class AgentStatEncoderTest { - - private static final String AGENT_ID = "testAgentId"; - private static final long AGENT_START_TIMESTAMP = System.currentTimeMillis(); - private static final long COLLECT_INTERVAL = 5000L; - private static final Random RANDOM = new Random(); - - private AgentStatCodec codec = new TestAgentStatCodec(); - - private AgentStatEncoder encoder = new AgentStatEncoder<>(codec); - - private AgentStatDecoder decoder = new AgentStatDecoder<>(List.of(codec)); - - @Test - public void stats_should_be_encoded_and_decoded_into_same_value() { - long initialTimestamp = System.currentTimeMillis(); - int numStats = RANDOM.nextInt(1, 21); - List expectedAgentStats = this.createTestAgentStats(initialTimestamp, numStats); - long baseTimestamp = AgentStatUtils.getBaseTimestamp(initialTimestamp); - long timestampDelta = initialTimestamp - baseTimestamp; - ByteBuffer qualifierBuffer = encoder.encodeQualifier(timestampDelta); - ByteBuffer valueBuffer = encoder.encodeValue(expectedAgentStats); - - Buffer encodedQualifierBuffer = new FixedBuffer(qualifierBuffer.array()); - Buffer encodedValueBuffer = new FixedBuffer(valueBuffer.array()); - - AgentStatDecodingContext context = new AgentStatDecodingContext(); - context.setAgentId(AGENT_ID); - context.setBaseTimestamp(baseTimestamp); - List decodedAgentStats = decode(encodedQualifierBuffer, encodedValueBuffer, context); - verify(expectedAgentStats, decodedAgentStats); - } - - private List createTestAgentStats(long initialTimestamp, int numStats) { - List agentStats = new ArrayList<>(numStats); - for (int i = 0; i < numStats; i++) { - long timestamp = initialTimestamp + (COLLECT_INTERVAL * i); - TestAgentStat agentStat = new TestAgentStat(); - agentStat.setAgentId(AGENT_ID); - agentStat.setStartTimestamp(AGENT_START_TIMESTAMP); - agentStat.setTimestamp(timestamp); - agentStat.setValue(RANDOM.nextLong()); - agentStats.add(agentStat); - } - return agentStats; - } - - protected void verify(List expectedAgentStats, List actualAgentStats) { - Assertions.assertEquals(expectedAgentStats, actualAgentStats); - } - - private List decode(Buffer encodedQualifierBuffer, Buffer encodedValueBuffer, AgentStatDecodingContext decodingContext) { - long timestampDelta = decoder.decodeQualifier(encodedQualifierBuffer); - decodingContext.setTimestampDelta(timestampDelta); - return decoder.decodeValue(encodedValueBuffer, decodingContext); - } - - private static class TestAgentStatCodec implements AgentStatCodec { - - @Override - public byte getVersion() { - return 0; - } - - @Override - public void encodeValues(Buffer valueBuffer, List agentStats) { - valueBuffer.putInt(agentStats.size()); - for (TestAgentStat agentStat : agentStats) { - valueBuffer.putLong(agentStat.getStartTimestamp()); - valueBuffer.putLong(agentStat.getTimestamp()); - valueBuffer.putLong(agentStat.getValue()); - } - } - - @Override - public List decodeValues(Buffer valueBuffer, AgentStatDecodingContext decodingContext) { - int size = valueBuffer.readInt(); - List agentStats = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - TestAgentStat agentStat = new TestAgentStat(); - agentStat.setAgentId(decodingContext.getAgentId()); - agentStat.setStartTimestamp(valueBuffer.readLong()); - agentStat.setTimestamp(valueBuffer.readLong()); - agentStat.setValue(valueBuffer.readLong()); - agentStats.add(agentStat); - } - return agentStats; - } - } - - private static class TestAgentStat implements AgentStatDataPoint { - - private String applicationName; - private String agentId; - private long startTimestamp; - private long timestamp; - private long value; - - @Override - public String getAgentId() { - return this.agentId; - } - - @Override - public void setAgentId(String agentId) { - this.agentId = agentId; - } - - @Override - public long getStartTimestamp() { - return startTimestamp; - } - - @Override - public void setStartTimestamp(long startTimestamp) { - this.startTimestamp = startTimestamp; - } - - @Override - public long getTimestamp() { - return this.timestamp; - } - - @Override - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - - public long getValue() { - return this.value; - } - - public void setValue(long value) { - this.value = value; - } - - @Override - public AgentStatType getAgentStatType() { - return AgentStatType.UNKNOWN; - } - - @Override - public String getApplicationName() { - return this.applicationName; - } - - @Override - public void setApplicationName(String applicationName) { - this.applicationName = applicationName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - TestAgentStat that = (TestAgentStat) o; - - if (startTimestamp != that.startTimestamp) return false; - if (timestamp != that.timestamp) return false; - if (value != that.value) return false; - return agentId != null ? agentId.equals(that.agentId) : that.agentId == null; - - } - - @Override - public int hashCode() { - int result = agentId != null ? agentId.hashCode() : 0; - result = 31 * result + (int) (startTimestamp ^ (startTimestamp >>> 32)); - result = 31 * result + (int) (timestamp ^ (timestamp >>> 32)); - result = 31 * result + (int) (value ^ (value >>> 32)); - return result; - } - - @Override - public String toString() { - return "TestAgentStat{" + - "agentId='" + agentId + '\'' + - ", startTimestamp=" + startTimestamp + - ", timestamp=" + timestamp + - ", value=" + value + - '}'; - } - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/BitCountingHeaderEncoderTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/BitCountingHeaderEncoderTest.java deleted file mode 100644 index 1541477b0992..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/header/BitCountingHeaderEncoderTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.header; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -/** - * @author HyunGil Jeong - */ -public class BitCountingHeaderEncoderTest { - - private static final int MAX_NUM_TEST_VALUES = 20 + 1; // Random API's upper bound field is exclusive - - private static final Random RANDOM = new Random(); - - @Test - public void test_with_random_codes() { - // Given - final int numCodes = RANDOM.nextInt(1, MAX_NUM_TEST_VALUES); - final List givenCodes = new ArrayList<>(numCodes); - for (int i = 0; i < numCodes; i++) { - givenCodes.add(RANDOM.nextInt(5)); - } - // When - AgentStatHeaderEncoder encoder = new BitCountingHeaderEncoder(); - for (int i = 0; i < givenCodes.size(); i++) { - encoder.addCode(givenCodes.get(i)); - } - final byte[] header = encoder.getHeader(); - // Then - List decodedCodes = new ArrayList<>(numCodes); - AgentStatHeaderDecoder decoder = new BitCountingHeaderDecoder(header); - for (int i = 0; i < numCodes; i++) { - int code = decoder.getCode(); - decodedCodes.add(code); - } - Assertions.assertEquals(givenCodes, decodedCodes); - } - - @Test - public void test_zeroes() { - // Given - final int numCodes = RANDOM.nextInt(1, MAX_NUM_TEST_VALUES); - // When - AgentStatHeaderEncoder encoder = new BitCountingHeaderEncoder(); - for (int i = 0; i < numCodes; i++) { - encoder.addCode(0); - } - final byte[] header = encoder.getHeader(); - // Then - AgentStatHeaderDecoder decoder = new BitCountingHeaderDecoder(header); - for (int i = 0; i < numCodes; i++) { - Assertions.assertEquals(0, decoder.getCode()); - } - } - - @Test - public void test_zeroes_followed_by_random_codes() { - // Given - final int numZeroes = RANDOM.nextInt(1, MAX_NUM_TEST_VALUES); - final int numRandomCodes = RANDOM.nextInt(1, MAX_NUM_TEST_VALUES); - final int numTotalCodes = numZeroes + numRandomCodes; - List givenCodes = new ArrayList<>(numTotalCodes); - for (int i = 0; i < numZeroes; i++) { - givenCodes.add(0); - } - for (int i = 0; i < numRandomCodes; i++) { - givenCodes.add(RANDOM.nextInt(5)); - } - // When - AgentStatHeaderEncoder encoder = new BitCountingHeaderEncoder(); - for (int expectedCode : givenCodes) { - encoder.addCode(expectedCode); - } - final byte[] header = encoder.getHeader(); - // Then - AgentStatHeaderDecoder decoder = new BitCountingHeaderDecoder(header); - List decodedCodes = new ArrayList<>(numTotalCodes); - for (int i = 0; i < numTotalCodes; i++) { - decodedCodes.add(decoder.getCode()); - } - Assertions.assertEquals(givenCodes, decodedCodes); - } - - @Test - public void test_empty_codes() { - AgentStatHeaderEncoder encoder = new BitCountingHeaderEncoder(); - final byte[] header = encoder.getHeader(); - AgentStatHeaderDecoder decoder = new BitCountingHeaderDecoder(header); - Assertions.assertEquals(0, decoder.getCode()); - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/EncodingStrategyTestBase.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/EncodingStrategyTestBase.java deleted file mode 100644 index 5a5ef4446cc3..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/EncodingStrategyTestBase.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.strategy; - -import com.navercorp.pinpoint.common.buffer.AutomaticBuffer; -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.junit.jupiter.api.Assertions; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * @author HyunGil Jeong - */ -public abstract class EncodingStrategyTestBase { - - private final Logger logger = LogManager.getLogger(this.getClass()); - - private final AgentStatDataPointCodec codec = new AgentStatDataPointCodec(); - - protected static final int NUM_TEST_RUNS = 20; - - protected abstract StrategyAnalyzer.StrategyAnalyzerBuilder getStrategyAnalyzerBuilder(); - - protected abstract List> getEncodingStrategies(); - - protected abstract void checkBuilder(StrategyAnalyzer.StrategyAnalyzerBuilder analyzerBuilder, Map, Integer> bufferSizes); - - protected void testFor(List testValues) { - StrategyAnalyzer.StrategyAnalyzerBuilder builder = this.getStrategyAnalyzerBuilder(); - for (T testValue : testValues) { - builder.addValue(testValue); - } - - final StrategyAnalyzer analyzer = builder.build(); - logger.debug("Values : {}", analyzer.getValues()); - - Map, Integer> bufferSizes = this.getBufferSizes(testValues); - checkBuilder(builder, bufferSizes); - checkStrategy(analyzer, getBestEncodingStrategies(bufferSizes)); - } - - private void checkStrategy(StrategyAnalyzer analyzer, Set> bestStrategies) { - EncodingStrategy chosenStrategy = analyzer.getBestStrategy(); - List values = analyzer.getValues(); - logger.debug("Chosen : {}", analyzer.getBestStrategy()); - Assertions.assertTrue(bestStrategies.contains(chosenStrategy), createTestFailMessage(values, bestStrategies, chosenStrategy)); - } - - private > String createTestFailMessage(List values, Set bestStrategies, EncodingStrategy chosenStrategy) { - StringBuilder sb = new StringBuilder("Wrong strategy chosen - "); - sb.append("expected one of ").append(bestStrategies); - sb.append(", but got ").append(chosenStrategy); - sb.append(". Value : ").append(values); - return sb.toString(); - } - - private Set> getBestEncodingStrategies(Map, Integer> bufferSizes) { - int minimumBufferSize = Integer.MAX_VALUE; - Set> bestStrategies = new HashSet<>(); - for (Map.Entry, Integer> entry : bufferSizes.entrySet()) { - EncodingStrategy strategy = entry.getKey(); - int bufferSize = entry.getValue(); - if (bufferSize < minimumBufferSize) { - bestStrategies.clear(); - bestStrategies.add(strategy); - minimumBufferSize = bufferSize; - } else if (bufferSize == minimumBufferSize) { - bestStrategies.add(strategy); - } - } - return bestStrategies; - } - - private Map, Integer> getBufferSizes(List values) { - Map, Integer> bufferSizes = new HashMap<>(); - for (EncodingStrategy strategy : getEncodingStrategies()) { - Buffer encodedBuffer = new AutomaticBuffer(); - codec.encodeValues(encodedBuffer, strategy, values); - int encodedBufferSize = encodedBuffer.getBuffer().length; - bufferSizes.put(strategy, encodedBufferSize); - } - logger.debug("Strategies : {}", bufferSizes); - return bufferSizes; - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/StringEncodingStrategyTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/StringEncodingStrategyTest.java deleted file mode 100644 index 92c1c8c7bf39..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/StringEncodingStrategyTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2017 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.common.server.bo.codec.stat.strategy; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** - * @author Taejin Koo - */ -public class StringEncodingStrategyTest { - - private static final String[] STRING_CANDIDATES = {"aTest", "bTest", "cTest"}; - - @Test - public void noneTest() throws Exception { - StringEncodingStrategy.Analyzer.Builder builder = new StringEncodingStrategy.Analyzer.Builder(); - for (String string : STRING_CANDIDATES) { - builder.addValue(string); - } - StrategyAnalyzer build = builder.build(); - Assertions.assertEquals(build.getBestStrategy(), StringEncodingStrategy.NONE); - } - - @Test - public void repeatTest() throws Exception { - StringEncodingStrategy.Analyzer.Builder builder = new StringEncodingStrategy.Analyzer.Builder(); - for (String string : STRING_CANDIDATES) { - builder.addValue(string); - builder.addValue(string); - } - StrategyAnalyzer build = builder.build(); - Assertions.assertEquals(build.getBestStrategy(), StringEncodingStrategy.REPEAT_COUNT); - } - - @Test - public void alwaysSameTest() throws Exception { - StringEncodingStrategy.Analyzer.Builder builder = new StringEncodingStrategy.Analyzer.Builder(); - builder.addValue(STRING_CANDIDATES[0]); - builder.addValue(STRING_CANDIDATES[0]); - builder.addValue(STRING_CANDIDATES[0]); - builder.addValue(STRING_CANDIDATES[0]); - - StrategyAnalyzer build = builder.build(); - Assertions.assertEquals(build.getBestStrategy(), StringEncodingStrategy.ALWAYS_SAME_VALUE); - } - -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedIntegerEncodingStrategyTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedIntegerEncodingStrategyTest.java deleted file mode 100644 index 92e643bbe909..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedIntegerEncodingStrategyTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.strategy; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatDataPointFactory; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.Map; - -/** - * @author HyunGil Jeong - */ -public class UnsignedIntegerEncodingStrategyTest extends EncodingStrategyTestBase { - - @Override - protected StrategyAnalyzer.StrategyAnalyzerBuilder getStrategyAnalyzerBuilder() { - return new UnsignedIntegerEncodingStrategy.Analyzer.Builder(); - } - - @Override - protected List> getEncodingStrategies() { - return List.of(UnsignedIntegerEncodingStrategy.values()); - } - - @Override - protected void checkBuilder(StrategyAnalyzer.StrategyAnalyzerBuilder analyzerBuilder, Map, Integer> bufferSizes) { - UnsignedIntegerEncodingStrategy.Analyzer.Builder builder = (UnsignedIntegerEncodingStrategy.Analyzer.Builder) analyzerBuilder; - int actualValueEncodedSize = bufferSizes.get(UnsignedIntegerEncodingStrategy.NONE); - int actualRepeatCountEncodedSize = bufferSizes.get(UnsignedIntegerEncodingStrategy.REPEAT_COUNT); - int actualDeltaEncodedSize = bufferSizes.get(UnsignedIntegerEncodingStrategy.DELTA); - int actualDeltaOfDeltaEncodedSize = bufferSizes.get(UnsignedIntegerEncodingStrategy.DELTA_OF_DELTA); - Assertions.assertEquals(actualValueEncodedSize, builder.getByteSizeValue()); - Assertions.assertEquals(actualRepeatCountEncodedSize, builder.getByteSizeRepeatCount()); - Assertions.assertEquals(actualDeltaEncodedSize, builder.getByteSizeDelta()); - Assertions.assertEquals(actualDeltaOfDeltaEncodedSize, builder.getByteSizeDeltaOfDelta()); - } - - @Test - public void test_small_values() { - int minValue = 10; - int maxValue = 100; - testValues(minValue, maxValue); - } - - @Test - public void test_medium_values() { - int minValue = 1000; - int maxValue = 1000000; - testValues(minValue, maxValue); - } - - @Test - public void test_large_values() { - int minValue = 1000000; - int maxValue = 1000000000; - testValues(minValue, maxValue); - } - - private void testValues(int minValue, int maxValue) { - for (int i = 0; i < NUM_TEST_RUNS; i++) { - List constantValues = TestAgentStatDataPointFactory.INTEGER.createConstantValues(minValue, maxValue); - testFor(constantValues); - List randomValues = TestAgentStatDataPointFactory.INTEGER.createRandomValues(minValue, maxValue); - testFor(randomValues); - List increasingValues1 = TestAgentStatDataPointFactory.INTEGER.createIncreasingValues(minValue, maxValue, 0, minValue / 10); - testFor(increasingValues1); - List increasingValues2 = TestAgentStatDataPointFactory.INTEGER.createIncreasingValues(minValue, maxValue, minValue / 10, maxValue / 10); - testFor(increasingValues2); - List decreasingValues1 = TestAgentStatDataPointFactory.INTEGER.createDecreasingValues(minValue, maxValue, 0, minValue / 10); - testFor(decreasingValues1); - List decreasingValues2 = TestAgentStatDataPointFactory.INTEGER.createDecreasingValues(minValue, maxValue, minValue / 10, maxValue / 10); - testFor(decreasingValues2); - List fluctuatingValues1 = TestAgentStatDataPointFactory.INTEGER.createFluctuatingValues(minValue, maxValue, 0, minValue / 10); - testFor(fluctuatingValues1); - List fluctuatingValues2 = TestAgentStatDataPointFactory.INTEGER.createFluctuatingValues(minValue, maxValue, minValue / 10, maxValue / 10); - testFor(fluctuatingValues2); - } - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedLongEncodingStrategyTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedLongEncodingStrategyTest.java deleted file mode 100644 index 6bc4be407809..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedLongEncodingStrategyTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.strategy; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatDataPointFactory; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.Map; - -/** - * @author HyunGil Jeong - */ -public class UnsignedLongEncodingStrategyTest extends EncodingStrategyTestBase { - - @Override - protected StrategyAnalyzer.StrategyAnalyzerBuilder getStrategyAnalyzerBuilder() { - return new UnsignedLongEncodingStrategy.Analyzer.Builder(); - } - - @Override - protected List> getEncodingStrategies() { - return List.of(UnsignedLongEncodingStrategy.values()); - } - - @Override - protected void checkBuilder(StrategyAnalyzer.StrategyAnalyzerBuilder analyzerBuilder, Map, Integer> bufferSizes) { - UnsignedLongEncodingStrategy.Analyzer.Builder builder = (UnsignedLongEncodingStrategy.Analyzer.Builder) analyzerBuilder; - int actualValueEncodedSize = bufferSizes.get(UnsignedLongEncodingStrategy.NONE); - int actualRepeatCountEncodedSize = bufferSizes.get(UnsignedLongEncodingStrategy.REPEAT_COUNT); - int actualDeltaEncodedSize = bufferSizes.get(UnsignedLongEncodingStrategy.DELTA); - int actualDeltaOfDeltaEncodedSize = bufferSizes.get(UnsignedLongEncodingStrategy.DELTA_OF_DELTA); - Assertions.assertEquals(actualValueEncodedSize, builder.getByteSizeValue()); - Assertions.assertEquals(actualRepeatCountEncodedSize, builder.getByteSizeRepeatCount()); - Assertions.assertEquals(actualDeltaEncodedSize, builder.getByteSizeDelta()); - Assertions.assertEquals(actualDeltaOfDeltaEncodedSize, builder.getByteSizeDeltaOfDelta()); - } - - @Test - public void test_small_values() { - long minValue = 10; - long maxValue = 100; - testValues(minValue, maxValue); - } - - @Test - public void test_medium_values() { - long minValue = 1000; - long maxValue = 1000000; - testValues(minValue, maxValue); - } - - @Test - public void test_large_values() { - long minValue = 1000000; - long maxValue = 1000000000; - testValues(minValue, maxValue); - } - - @Test - public void test_huge_values() { - long minValue = 1000000000; - long maxValue = 100000000000000000L; - testValues(minValue, maxValue); - } - - private void testValues(long minValue, long maxValue) { - for (int i = 0; i < NUM_TEST_RUNS; i++) { - List constantValues = TestAgentStatDataPointFactory.LONG.createConstantValues(minValue, maxValue); - testFor(constantValues); - List randomValues = TestAgentStatDataPointFactory.LONG.createRandomValues(minValue, maxValue); - testFor(randomValues); - List increasingValues1 = TestAgentStatDataPointFactory.LONG.createIncreasingValues(minValue, maxValue, 0L, minValue / 10); - testFor(increasingValues1); - List increasingValues2 = TestAgentStatDataPointFactory.LONG.createIncreasingValues(minValue, maxValue, minValue / 10, maxValue / 10); - testFor(increasingValues2); - List decreasingValues1 = TestAgentStatDataPointFactory.LONG.createDecreasingValues(minValue, maxValue, 0L, minValue / 10); - testFor(decreasingValues1); - List decreasingValues2 = TestAgentStatDataPointFactory.LONG.createDecreasingValues(minValue, maxValue, minValue / 10, maxValue / 10); - testFor(decreasingValues2); - List fluctuatingValues1 = TestAgentStatDataPointFactory.LONG.createFluctuatingValues(minValue, maxValue, 0L, minValue / 10); - testFor(fluctuatingValues1); - List fluctuatingValues2 = TestAgentStatDataPointFactory.LONG.createFluctuatingValues(minValue, maxValue, minValue / 10, maxValue / 10); - testFor(fluctuatingValues2); - } - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedShortEncodingStrategyTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedShortEncodingStrategyTest.java deleted file mode 100644 index 0b7e2f64f7e2..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/strategy/UnsignedShortEncodingStrategyTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.strategy; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatDataPointFactory; -import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.Map; - -/** - * @author HyunGil Jeong - */ -public class UnsignedShortEncodingStrategyTest extends EncodingStrategyTestBase { - - @Override - protected StrategyAnalyzer.StrategyAnalyzerBuilder getStrategyAnalyzerBuilder() { - return new UnsignedShortEncodingStrategy.Analyzer.Builder(); - } - - @Override - protected List> getEncodingStrategies() { - return List.of(UnsignedShortEncodingStrategy.values()); - } - - @Override - protected void checkBuilder(StrategyAnalyzer.StrategyAnalyzerBuilder analyzerBuilder, Map, Integer> bufferSizes) { - UnsignedShortEncodingStrategy.Analyzer.Builder builder = (UnsignedShortEncodingStrategy.Analyzer.Builder) analyzerBuilder; - int actualValueEncodedSize = bufferSizes.get(UnsignedShortEncodingStrategy.NONE); - int actualRepeatCountEncodedSize = bufferSizes.get(UnsignedShortEncodingStrategy.REPEAT_COUNT); - Assertions.assertEquals(actualValueEncodedSize, builder.getByteSizeValue(), "none"); - Assertions.assertEquals(actualRepeatCountEncodedSize, builder.getByteSizeRepeatCount(), "repeatCount"); - } - - @Test - public void test_small_values() { - short minValue = 10; - short maxValue = 100; - testValues(minValue, maxValue); - } - - @Test - public void test_medium_values() { - short minValue = 100; - short maxValue = 1000; - testValues(minValue, maxValue); - } - - @Test - public void test_large_values() { - short minValue = 1000; - short maxValue = 10000; - testValues(minValue, maxValue); - } - - private void testValues(short minValue, short maxValue) { - for (int i = 0; i < NUM_TEST_RUNS; i++) { - List constantValues = TestAgentStatDataPointFactory.SHORT.createConstantValues(minValue, maxValue); - testFor(constantValues); - List randomValues = TestAgentStatDataPointFactory.SHORT.createRandomValues(minValue, maxValue); - testFor(randomValues); - List increasingValues1 = TestAgentStatDataPointFactory.SHORT.createIncreasingValues(minValue, maxValue, (short) 0, (short) (minValue / 10)); - testFor(increasingValues1); - List increasingValues2 = TestAgentStatDataPointFactory.SHORT.createIncreasingValues(minValue, maxValue, (short) (minValue / 10), (short) (maxValue / 10)); - testFor(increasingValues2); - List decreasingValues1 = TestAgentStatDataPointFactory.SHORT.createDecreasingValues(minValue, maxValue, (short) 0, (short) (minValue / 10)); - testFor(decreasingValues1); - List decreasingValues2 = TestAgentStatDataPointFactory.SHORT.createDecreasingValues(minValue, maxValue, (short) (minValue / 10), (short) (maxValue / 10)); - testFor(decreasingValues2); - List fluctuatingValues1 = TestAgentStatDataPointFactory.SHORT.createFluctuatingValues(minValue, maxValue, (short) 0, (short) (minValue / 10)); - testFor(fluctuatingValues1); - List fluctuatingValues2 = TestAgentStatDataPointFactory.SHORT.createFluctuatingValues(minValue, maxValue, (short) (minValue / 10), (short) (maxValue / 10)); - testFor(fluctuatingValues2); - } - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/ActiveTraceCodecV2Test.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/ActiveTraceCodecV2Test.java deleted file mode 100644 index a5687a091ae8..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/ActiveTraceCodecV2Test.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodecTestBase; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecTestConfig; -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatFactory; -import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = CodecTestConfig.class) -public class ActiveTraceCodecV2Test extends AgentStatCodecTestBase { - - @Autowired - private AgentStatCodecV2 codec; - - @Override - protected List createAgentStats(String agentId, long startTimestamp, long initialTimestamp) { - return TestAgentStatFactory.createActiveTraceBos(agentId, startTimestamp, initialTimestamp); - } - - @Override - protected AgentStatCodec getCodec() { - return codec; - } - - @Override - protected void verify(ActiveTraceBo expected, ActiveTraceBo actual) { - Assertions.assertEquals(expected.getAgentId(), actual.getAgentId(), "agentId"); - Assertions.assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp(), "startTimestamp"); - Assertions.assertEquals(expected.getTimestamp(), actual.getTimestamp(), "timestamp"); - Assertions.assertEquals(expected.getVersion(), actual.getVersion(), "version"); - Assertions.assertEquals(expected.getHistogramSchemaType(), actual.getHistogramSchemaType(), "histogramSchemaType"); - Assertions.assertEquals(expected.getActiveTraceHistogram(), actual.getActiveTraceHistogram(), "activeTraceCounts"); - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/CpuLoadCodecV2Test.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/CpuLoadCodecV2Test.java deleted file mode 100644 index bf4cd1675f7a..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/CpuLoadCodecV2Test.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodecTestBase; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecTestConfig; -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatFactory; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatUtils; -import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = CodecTestConfig.class) -public class CpuLoadCodecV2Test extends AgentStatCodecTestBase { - - private static final double DOUBLE_COMPARISON_DELTA = (double) 1 / AgentStatUtils.CONVERT_VALUE; - - @Autowired - private AgentStatCodecV2 codec; - - @Override - protected List createAgentStats(String agentId, long startTimestamp, long initialTimestamp) { - return TestAgentStatFactory.createCpuLoadBos(agentId, startTimestamp, initialTimestamp); - } - - @Override - protected AgentStatCodec getCodec() { - return codec; - } - - @Override - protected void verify(CpuLoadBo expected, CpuLoadBo actual) { - Assertions.assertEquals(expected.getAgentId(), actual.getAgentId(), "agentId"); - Assertions.assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp(), "startTimestamp"); - Assertions.assertEquals(expected.getTimestamp(), actual.getTimestamp(), "timestamp"); - Assertions.assertEquals(expected.getAgentStatType(), actual.getAgentStatType(), "agentStatType"); - Assertions.assertEquals(expected.getJvmCpuLoad(), actual.getJvmCpuLoad(), DOUBLE_COMPARISON_DELTA, "jvmCpuLoad"); - Assertions.assertEquals(expected.getSystemCpuLoad(), actual.getSystemCpuLoad(), DOUBLE_COMPARISON_DELTA, "systemCpuLoad"); - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DataSourceCodecV2Test.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DataSourceCodecV2Test.java deleted file mode 100644 index 8d733d7a4e44..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DataSourceCodecV2Test.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2017 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodecTestBase; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecTestConfig; -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatFactory; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceBo; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceListBo; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * @author Taejin Koo - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = CodecTestConfig.class) -public class DataSourceCodecV2Test extends AgentStatCodecTestBase { - - @Autowired - private AgentStatCodec codec; - - @Override - protected List createAgentStats(String agentId, long startTimestamp, long initialTimestamp) { - return TestAgentStatFactory.createDataSourceListBos(agentId, startTimestamp, initialTimestamp); - } - - @Override - protected AgentStatCodec getCodec() { - return codec; - } - - @Override - protected void verify(DataSourceListBo expected, DataSourceListBo actual) { - assertEquals(expected.getAgentId(), actual.getAgentId(), "agentId"); - assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp(), "startTimestamp"); - assertEquals(expected.getTimestamp(), actual.getTimestamp(), "timestamp"); - assertEquals(expected.size(), actual.size()); - - List expectedDataSourceList = expected.getList(); - List actualDataSourceList = actual.getList(); - - for (int i = 0; i < expectedDataSourceList.size(); i++) { - verify(expectedDataSourceList.get(i), actualDataSourceList.get(i)); - } - } - - private void verify(DataSourceBo expected, DataSourceBo actual) { - assertEquals(expected.getAgentId(), actual.getAgentId(), "agentId"); - assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp(), "startTimestamp"); - assertEquals(expected.getTimestamp(), actual.getTimestamp(), "timestamp"); - - assertEquals(expected.getId(), actual.getId(), "id"); - assertEquals(expected.getServiceTypeCode(), actual.getServiceTypeCode(), "serviceTypeCode"); - assertEquals(expected.getDatabaseName(), actual.getDatabaseName(), "name"); - assertEquals(expected.getJdbcUrl(), actual.getJdbcUrl(), "jdbcUrl"); - assertEquals(expected.getActiveConnectionSize(), actual.getActiveConnectionSize(), "activeConnectionSize"); - assertEquals(expected.getMaxConnectionSize(), actual.getMaxConnectionSize(), "maxConnectionSize"); - } - -} - diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DeadlockCodecV2Test.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DeadlockCodecV2Test.java deleted file mode 100644 index 5f0b27b92f62..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DeadlockCodecV2Test.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2017 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodecTestBase; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecTestConfig; -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatFactory; -import com.navercorp.pinpoint.common.server.bo.stat.DeadlockThreadCountBo; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -/** - * @author Taejin Koo - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = CodecTestConfig.class) -public class DeadlockCodecV2Test extends AgentStatCodecTestBase { - - @Autowired - private AgentStatCodecV2 codec; - - @Override - protected List createAgentStats(String agentId, long startTimestamp, long initialTimestamp) { - return TestAgentStatFactory.createDeadlockBos(agentId, startTimestamp, initialTimestamp); - } - - @Override - protected AgentStatCodec getCodec() { - return codec; - } - - @Override - protected void verify(DeadlockThreadCountBo expected, DeadlockThreadCountBo actual) { - Assertions.assertEquals(expected.getAgentId(), actual.getAgentId(), "agentId"); - Assertions.assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp(), "startTimestamp"); - Assertions.assertEquals(expected.getTimestamp(), actual.getTimestamp(), "timestamp"); - Assertions.assertEquals(expected.getDeadlockedThreadCount(), actual.getDeadlockedThreadCount(), "deadlockedThreadCount"); - } - -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DirectBufferCodecV2Test.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DirectBufferCodecV2Test.java deleted file mode 100644 index fc39a8f78a3c..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/DirectBufferCodecV2Test.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2018 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodecTestBase; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecTestConfig; -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatFactory; -import com.navercorp.pinpoint.common.server.bo.stat.DirectBufferBo; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -/** - * @author Roy Kim - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = CodecTestConfig.class) -public class DirectBufferCodecV2Test extends AgentStatCodecTestBase { - - @Autowired - private AgentStatCodecV2 codec; - - @Override - protected List createAgentStats(String agentId, long startTimestamp, long initialTimestamp) { - return TestAgentStatFactory.createDirectBufferBos(agentId, startTimestamp, initialTimestamp); - } - - @Override - protected AgentStatCodec getCodec() { - return codec; - } - - @Override - protected void verify(DirectBufferBo expected, DirectBufferBo actual) { - Assertions.assertEquals(expected.getAgentId(), actual.getAgentId(), "agentId"); - Assertions.assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp(), "startTimestamp"); - Assertions.assertEquals(expected.getTimestamp(), actual.getTimestamp(), "timestamp"); - Assertions.assertEquals(expected.getAgentStatType(), actual.getAgentStatType(), "agentStatType"); - Assertions.assertEquals(expected.getDirectCount(), actual.getDirectCount(), "directCount"); - Assertions.assertEquals(expected.getDirectMemoryUsed(), actual.getDirectMemoryUsed(), "directMemoryUsed"); - Assertions.assertEquals(expected.getMappedCount(), actual.getMappedCount(), "mappedCount"); - Assertions.assertEquals(expected.getMappedMemoryUsed(), actual.getMappedMemoryUsed(), "mappedMemoryUsed"); - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/FileDescriptorCodecV2Test.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/FileDescriptorCodecV2Test.java deleted file mode 100644 index 1bb0f0da5793..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/FileDescriptorCodecV2Test.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2018 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodecTestBase; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecTestConfig; -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatFactory; -import com.navercorp.pinpoint.common.server.bo.stat.FileDescriptorBo; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -/** - * @author Roy Kim - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = CodecTestConfig.class) -public class FileDescriptorCodecV2Test extends AgentStatCodecTestBase { - - @Autowired - private AgentStatCodecV2 codec; - - @Override - protected List createAgentStats(String agentId, long startTimestamp, long initialTimestamp) { - return TestAgentStatFactory.createFileDescriptorBos(agentId, startTimestamp, initialTimestamp); - } - - @Override - protected AgentStatCodec getCodec() { - return codec; - } - - @Override - protected void verify(FileDescriptorBo expected, FileDescriptorBo actual) { - Assertions.assertEquals(expected.getAgentId(), actual.getAgentId(), "agentId"); - Assertions.assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp(), "startTimestamp"); - Assertions.assertEquals(expected.getTimestamp(), actual.getTimestamp(), "timestamp"); - Assertions.assertEquals(expected.getAgentStatType(), actual.getAgentStatType(), "agentStatType"); - Assertions.assertEquals(expected.getOpenFileDescriptorCount(), actual.getOpenFileDescriptorCount(), "openFileDescriptor"); - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/JvmGcCodecV2Test.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/JvmGcCodecV2Test.java deleted file mode 100644 index 53b53b2887ee..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/JvmGcCodecV2Test.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodecTestBase; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecTestConfig; -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatFactory; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = CodecTestConfig.class) -public class JvmGcCodecV2Test extends AgentStatCodecTestBase { - - @Autowired - @Qualifier("jvmGcCodecV2") - private AgentStatCodec codec; - - @Override - protected List createAgentStats(String agentId, long startTimestamp, long initialTimestamp) { - return TestAgentStatFactory.createJvmGcBos(agentId, startTimestamp, initialTimestamp); - } - - @Override - protected AgentStatCodec getCodec() { - return codec; - } - - @Override - protected void verify(JvmGcBo expected, JvmGcBo actual) { - Assertions.assertEquals(expected.getAgentId(), actual.getAgentId(), "agentId"); - Assertions.assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp(), "startTimestamp"); - Assertions.assertEquals(expected.getTimestamp(), actual.getTimestamp(), "timestamp"); - Assertions.assertEquals(expected.getGcType(), actual.getGcType(), "gcType"); - Assertions.assertEquals(expected.getHeapUsed(), actual.getHeapUsed(), "heapUsed"); - Assertions.assertEquals(expected.getHeapMax(), actual.getHeapMax(), "heapMax"); - Assertions.assertEquals(expected.getNonHeapUsed(), actual.getNonHeapUsed(), "nonHeapUsed"); - Assertions.assertEquals(expected.getNonHeapMax(), actual.getNonHeapMax(), "nonHeapMax"); - Assertions.assertEquals(expected.getGcOldCount(), actual.getGcOldCount(), "gcOldCount"); - Assertions.assertEquals(expected.getGcOldTime(), actual.getGcOldTime(), "gcOldTime"); - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/JvmGcDetailedCodecV2Test.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/JvmGcDetailedCodecV2Test.java deleted file mode 100644 index 6c8e49db7e48..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/JvmGcDetailedCodecV2Test.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodecTestBase; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecTestConfig; -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatFactory; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatUtils; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = CodecTestConfig.class) -public class JvmGcDetailedCodecV2Test extends AgentStatCodecTestBase { - - private static final double DOUBLE_COMPARISON_DELTA = (double) 1 / AgentStatUtils.CONVERT_VALUE; - - @Autowired - private AgentStatCodecV2 codec; - - @Override - protected List createAgentStats(String agentId, long startTimestamp, long initialTimestamp) { - return TestAgentStatFactory.createJvmGcDetailedBos(agentId, startTimestamp, initialTimestamp); - } - - @Override - protected AgentStatCodec getCodec() { - return codec; - } - - @Override - protected void verify(JvmGcDetailedBo expected, JvmGcDetailedBo actual) { - Assertions.assertEquals(expected.getAgentId(), actual.getAgentId(), "agentId"); - Assertions.assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp(), "startTimestamp"); - Assertions.assertEquals(expected.getTimestamp(), actual.getTimestamp(), "timestamp"); - Assertions.assertEquals(expected.getAgentStatType(), actual.getAgentStatType(), "agentStatType"); - Assertions.assertEquals(expected.getGcNewCount(), actual.getGcNewCount(), "gcNewCount"); - Assertions.assertEquals(expected.getGcNewTime(), actual.getGcNewTime(), "gcNewTime"); - Assertions.assertEquals(expected.getCodeCacheUsed(), actual.getCodeCacheUsed(), DOUBLE_COMPARISON_DELTA, "codeCacheUsed"); - Assertions.assertEquals(expected.getCodeCacheUsed(), actual.getCodeCacheUsed(), DOUBLE_COMPARISON_DELTA, "codeCacheUsed"); - Assertions.assertEquals(expected.getNewGenUsed(), actual.getNewGenUsed(), DOUBLE_COMPARISON_DELTA, "newGenUsed"); - Assertions.assertEquals(expected.getOldGenUsed(), actual.getOldGenUsed(), DOUBLE_COMPARISON_DELTA, "oldGenUsed"); - Assertions.assertEquals(expected.getSurvivorSpaceUsed(), actual.getSurvivorSpaceUsed(), DOUBLE_COMPARISON_DELTA, "survivorSpaceUsed"); - Assertions.assertEquals(expected.getPermGenUsed(), actual.getPermGenUsed(), DOUBLE_COMPARISON_DELTA, "permGenUsed"); - Assertions.assertEquals(expected.getMetaspaceUsed(), actual.getMetaspaceUsed(), DOUBLE_COMPARISON_DELTA, "metaspaceUsed"); - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/LoadedClassCodecV2Test.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/LoadedClassCodecV2Test.java deleted file mode 100644 index 7b711867453c..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/LoadedClassCodecV2Test.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2020 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodecTestBase; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecTestConfig; -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatFactory; -import com.navercorp.pinpoint.common.server.bo.stat.LoadedClassBo; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = CodecTestConfig.class) -public class LoadedClassCodecV2Test extends AgentStatCodecTestBase { - - @Autowired - private AgentStatCodecV2 codec; - - @Override - protected List createAgentStats(String agentId, long startTimestamp, long initialTimestamp) { - return TestAgentStatFactory.createLoadedClassBos(agentId, startTimestamp, initialTimestamp); - } - - @Override - protected AgentStatCodec getCodec() { - return codec; - } - - @Override - protected void verify(LoadedClassBo expected, LoadedClassBo actual) { - Assertions.assertEquals(expected.getAgentId(), actual.getAgentId(), "agentId"); - Assertions.assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp(), "startTimestamp"); - Assertions.assertEquals(expected.getTimestamp(), actual.getTimestamp(), "timestamp"); - Assertions.assertEquals(expected.getLoadedClassCount(), actual.getLoadedClassCount(), "loadedClassCount"); - Assertions.assertEquals(expected.getUnloadedClassCount(), actual.getUnloadedClassCount(), "unloadedClassCount"); - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/ResponseTimeCodecV2Test.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/ResponseTimeCodecV2Test.java deleted file mode 100644 index b3d98f82f2ba..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/ResponseTimeCodecV2Test.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2017 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodecTestBase; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecTestConfig; -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatFactory; -import com.navercorp.pinpoint.common.server.bo.stat.ResponseTimeBo; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -/** - * @author Taejin Koo - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = CodecTestConfig.class) -public class ResponseTimeCodecV2Test extends AgentStatCodecTestBase { - - @Autowired - private AgentStatCodecV2 codec; - - @Override - protected List createAgentStats(String agentId, long startTimestamp, long initialTimestamp) { - return TestAgentStatFactory.createResponseTimeBos(agentId, startTimestamp, initialTimestamp); - } - - @Override - protected AgentStatCodec getCodec() { - return codec; - } - - @Override - protected void verify(ResponseTimeBo expected, ResponseTimeBo actual) { - Assertions.assertEquals(expected.getAgentId(), actual.getAgentId(), "agentId"); - Assertions.assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp(), "startTimestamp"); - Assertions.assertEquals(expected.getTimestamp(), actual.getTimestamp(), "timestamp"); - Assertions.assertEquals(expected.getAvg(), actual.getAvg(), "avg"); - } - -} - diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/TotalThreadCountCodecV2Test.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/TotalThreadCountCodecV2Test.java deleted file mode 100644 index dd32b5cd4a10..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/TotalThreadCountCodecV2Test.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2020 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodecTestBase; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecTestConfig; -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatFactory; -import com.navercorp.pinpoint.common.server.bo.stat.TotalThreadCountBo; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = CodecTestConfig.class) -public class TotalThreadCountCodecV2Test extends AgentStatCodecTestBase { - - @Autowired - private AgentStatCodecV2 codec; - - @Override - protected List createAgentStats(String agentId, long startTimestamp, long initialTimestamp) { - return TestAgentStatFactory.createTotalThreadCountBos(agentId, startTimestamp, initialTimestamp); - } - - @Override - protected AgentStatCodec getCodec() { - return codec; - } - - @Override - protected void verify(TotalThreadCountBo expected, TotalThreadCountBo actual) { - Assertions.assertEquals(expected.getAgentId(), actual.getAgentId(), "agentId"); - Assertions.assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp(), "startTimestamp"); - Assertions.assertEquals(expected.getTimestamp(), actual.getTimestamp(), "timestamp"); - Assertions.assertEquals(expected.getTotalThreadCount(), actual.getTotalThreadCount(), "totalThreadCount"); - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/TransactionCodecV2Test.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/TransactionCodecV2Test.java deleted file mode 100644 index 2fd7cbe01401..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/codec/stat/v2/TransactionCodecV2Test.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.codec.stat.v2; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodecTestBase; -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecTestConfig; -import com.navercorp.pinpoint.common.server.bo.codec.stat.TestAgentStatFactory; -import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = CodecTestConfig.class) -public class TransactionCodecV2Test extends AgentStatCodecTestBase { - - @Autowired - private AgentStatCodecV2 codec; - - @Override - protected List createAgentStats(String agentId, long startTimestamp, long initialTimestamp) { - return TestAgentStatFactory.createTransactionBos(agentId, startTimestamp, initialTimestamp); - } - - @Override - protected AgentStatCodec getCodec() { - return codec; - } - - @Override - protected void verify(TransactionBo expected, TransactionBo actual) { - Assertions.assertEquals(expected.getAgentId(), actual.getAgentId(), "agentId"); - Assertions.assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp(), "startTimestamp"); - Assertions.assertEquals(expected.getTimestamp(), actual.getTimestamp(), "timestamp"); - Assertions.assertEquals(expected.getCollectInterval(), actual.getCollectInterval(), "collectInterval"); - Assertions.assertEquals(expected.getSampledNewCount(), actual.getSampledNewCount(), "sampledNewCount"); - Assertions.assertEquals(expected.getSampledContinuationCount(), actual.getSampledContinuationCount(), "sampledContinuationCount"); - Assertions.assertEquals(expected.getUnsampledNewCount(), actual.getUnsampledNewCount(), "unsampledNewCount"); - Assertions.assertEquals(expected.getUnsampledContinuationCount(), actual.getUnsampledContinuationCount(), "unsampledContinuationCount"); - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatHbaseOperationFactoryTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatHbaseOperationFactoryTest.java deleted file mode 100644 index ccc7cab0033a..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatHbaseOperationFactoryTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.serializer.stat; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.CodecTestConfig; -import com.navercorp.pinpoint.common.server.bo.serializer.HbaseSerializer; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; -import org.apache.hadoop.hbase.client.Put; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -import static com.navercorp.pinpoint.common.hbase.HbaseColumnFamily.AGENT_STAT_STATISTICS; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.lenient; -import static org.mockito.Mockito.mock; - -/** - * @author HyunGil Jeong - */ -@ExtendWith({SpringExtension.class, MockitoExtension.class}) -@ContextConfiguration(classes = CodecTestConfig.class) -public class AgentStatHbaseOperationFactoryTest { - - protected static final String TEST_AGENT_ID = "testAgentId"; - private static final AgentStatType TEST_AGENT_STAT_TYPE = AgentStatType.JVM_GC; - protected static final long TEST_COLLECTION_INTERVAL = 5000L; - - @Mock - private HbaseSerializer, Put> mockSerializer; - - @Autowired - private AgentStatHbaseOperationFactory agentStatHbaseOperationFactory; - - @Test - public void create_should_return_empty_list_for_null_dataPoints() { - List dataPoints = null; - List puts = this.agentStatHbaseOperationFactory.createPuts(TEST_AGENT_ID, TEST_AGENT_STAT_TYPE, dataPoints, this.mockSerializer); - assertEquals(Collections.emptyList(), puts); - } - - @Test - public void create_should_return_empty_list_for_empty_dataPoints() { - List dataPoints = Collections.emptyList(); - List puts = this.agentStatHbaseOperationFactory.createPuts(TEST_AGENT_ID, TEST_AGENT_STAT_TYPE, dataPoints, this.mockSerializer); - assertEquals(Collections.emptyList(), puts); - } - - @Test - public void create_should_create_one_put_if_there_is_only_one_dataPoint() { - // Given - final int numDataPoints = 1; - final long initialTimestamp = AGENT_STAT_STATISTICS.TIMESPAN_MS + 1L; - final long expectedBaseTimestamp = AgentStatUtils.getBaseTimestamp(initialTimestamp); - final List testDataPoints = createTestDataPoints(initialTimestamp, TEST_COLLECTION_INTERVAL, numDataPoints); - // When - List puts = this.agentStatHbaseOperationFactory.createPuts(TEST_AGENT_ID, TEST_AGENT_STAT_TYPE, testDataPoints, this.mockSerializer); - // Then - assertThat(puts).hasSize(1); - Put put = puts.get(0); - assertPut(put, expectedBaseTimestamp); - } - - @Test - public void create_should_create_one_put_if_dataPoints_fit_into_a_single_slot() { - // Given - final int numDataPoints = 6; - final long initialTimestamp = AGENT_STAT_STATISTICS.TIMESPAN_MS; - final long expectedBaseTimestamp = AgentStatUtils.getBaseTimestamp(initialTimestamp); - final List testDataPoints = createTestDataPoints(initialTimestamp, TEST_COLLECTION_INTERVAL, numDataPoints); - // When - List puts = this.agentStatHbaseOperationFactory.createPuts(TEST_AGENT_ID, TEST_AGENT_STAT_TYPE, testDataPoints, this.mockSerializer); - // Then - assertThat(puts).hasSize(1); - Put put = puts.get(0); - assertPut(put, expectedBaseTimestamp); - } - - @Test - public void create_should_create_two_puts_if_dataPoints_span_over_a_timespan() { - // Given - final int numDataPoints = 6; - final long initialTimestamp = AGENT_STAT_STATISTICS.TIMESPAN_MS - TEST_COLLECTION_INTERVAL; - final long expectedBaseTimestamp1 = AgentStatUtils.getBaseTimestamp(initialTimestamp); - final long expectedBaseTimestamp2 = AgentStatUtils.getBaseTimestamp(expectedBaseTimestamp1 + AGENT_STAT_STATISTICS.TIMESPAN_MS); - final List testDataPoints = createTestDataPoints(initialTimestamp, TEST_COLLECTION_INTERVAL, numDataPoints); - // When - List puts = this.agentStatHbaseOperationFactory.createPuts(TEST_AGENT_ID, TEST_AGENT_STAT_TYPE, testDataPoints, this.mockSerializer); - // Then - assertThat(puts).hasSize(2); - Put firstPut = puts.get(0); - assertPut(firstPut, expectedBaseTimestamp1); - Put secondPut = puts.get(1); - assertPut(secondPut, expectedBaseTimestamp2); - } - - private void assertPut(Put put, long expectedBaseTimestamp) { - assertEquals(TEST_AGENT_ID, this.agentStatHbaseOperationFactory.getAgentId(put.getRow())); - assertEquals(TEST_AGENT_STAT_TYPE, this.agentStatHbaseOperationFactory.getAgentStatType(put.getRow())); - assertEquals(expectedBaseTimestamp, this.agentStatHbaseOperationFactory.getBaseTimestamp(put.getRow())); - } - - @Test - public void create_should_create_the_same_number_of_puts_as_dataPoints_if_collectionInterval_equals_timespan() { - // Given - final int numDataPoints = 100; - final long initialTimestamp = AGENT_STAT_STATISTICS.TIMESPAN_MS - 1L; - final long expectedInitialBaseTimestamp = AgentStatUtils.getBaseTimestamp(initialTimestamp); - final List testDataPoints = createTestDataPoints(initialTimestamp, AGENT_STAT_STATISTICS.TIMESPAN_MS, numDataPoints); - // When - List puts = this.agentStatHbaseOperationFactory.createPuts(TEST_AGENT_ID, TEST_AGENT_STAT_TYPE, testDataPoints, this.mockSerializer); - // Then - assertThat(puts).hasSize(numDataPoints); - for (int i = 0; i < puts.size(); i++) { - Put put = puts.get(i); - assertEquals(TEST_AGENT_ID, this.agentStatHbaseOperationFactory.getAgentId(put.getRow())); - assertEquals(TEST_AGENT_STAT_TYPE, this.agentStatHbaseOperationFactory.getAgentStatType(put.getRow())); - long expectedBaseTimestamp = expectedInitialBaseTimestamp + (i * AGENT_STAT_STATISTICS.TIMESPAN_MS); - assertEquals(expectedBaseTimestamp, this.agentStatHbaseOperationFactory.getBaseTimestamp(put.getRow())); - } - } - - @Test - public void test_using_current_timestamp() { - // Given - final int numDataPoints = 6; - final long initialTimestamp = System.currentTimeMillis() - (TEST_COLLECTION_INTERVAL * numDataPoints); - final List testDataPoints = createTestDataPoints(initialTimestamp, TEST_COLLECTION_INTERVAL, numDataPoints); - final Set uniqueTimeslots = new TreeSet<>(); - for (AgentStatDataPoint testDataPoint : testDataPoints) { - uniqueTimeslots.add(AgentStatUtils.getBaseTimestamp(testDataPoint.getTimestamp())); - } - // When - List puts = this.agentStatHbaseOperationFactory.createPuts(TEST_AGENT_ID, TEST_AGENT_STAT_TYPE, testDataPoints, this.mockSerializer); - // Then - assertThat(puts).hasSameSizeAs(uniqueTimeslots); - int i = 0; - for (Long timeslot : uniqueTimeslots) { - long expectedBaseTimestamp = timeslot; - Put put = puts.get(i++); - assertPut(put, expectedBaseTimestamp); - } - } - - private List createTestDataPoints(long initialTimestamp, long interval, int count) { - List dataPoints = new ArrayList<>(count); - long timestamp = initialTimestamp; - for (int i = 0; i < count; i++) { - AgentStatDataPoint dataPoint = createTestDataPoint(timestamp); - dataPoints.add(dataPoint); - timestamp += interval; - } - return dataPoints; - } - - private AgentStatDataPoint createTestDataPoint(final long testTimestamp) { - final String testAgentId = "testAgentId"; - final long testStartTimestamp = 0L; - - AgentStatDataPoint mock = mock(AgentStatDataPoint.class); - lenient().when(mock.getAgentId()).thenReturn(testAgentId); - lenient().when(mock.getStartTimestamp()).thenReturn(testStartTimestamp); - lenient().when(mock.getTimestamp()).thenReturn(testTimestamp); - lenient().when(mock.getAgentStatType()).thenReturn(AgentStatType.UNKNOWN); - return mock; - } -} diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatUtilsTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatUtilsTest.java deleted file mode 100644 index 54dd68a80b37..000000000000 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/stat/AgentStatUtilsTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2016 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.common.server.bo.serializer.stat; - -import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.Random; - -/** - * @author HyunGil Jeong - */ -public class AgentStatUtilsTest { - - private static final Random RANDOM = new Random(); - - private static final double DECIMAL_COMPARISON_DELTA = 1 / Math.pow(10, AgentStatUtils.NUM_DECIMALS); - - @Test - public void testConversion() { - double originalValue = Math.random(); - double convertedValue = AgentStatUtils.convertLongToDouble(AgentStatUtils.convertDoubleToLong(originalValue)); - Assertions.assertEquals(originalValue, convertedValue, DECIMAL_COMPARISON_DELTA); - - originalValue = 0; - convertedValue = AgentStatUtils.convertLongToDouble(AgentStatUtils.convertDoubleToLong(originalValue)); - Assertions.assertEquals(originalValue, convertedValue, DECIMAL_COMPARISON_DELTA); - - originalValue = -1 * Math.random(); - convertedValue = AgentStatUtils.convertLongToDouble(AgentStatUtils.convertDoubleToLong(originalValue)); - Assertions.assertEquals(originalValue, convertedValue, DECIMAL_COMPARISON_DELTA); - } - - @Test - public void calculateRate_should_return_defaultRate_if_time_is_not_greater_than_0() { - long count = 1000; - int numDecimals = 2; - double defaultRate = 99; - double validDelta = 1 / Math.pow(10, numDecimals); - - long timeMs = 0; - double rate = AgentStatUtils.calculateRate(count, timeMs, numDecimals, defaultRate); - Assertions.assertEquals(defaultRate, rate, validDelta); - - timeMs = -1; - rate = AgentStatUtils.calculateRate(count, timeMs, numDecimals, defaultRate); - Assertions.assertEquals(defaultRate, rate, validDelta); - } - - @Test - public void calculateRate_should_return_correct_rate_to_numDecimal_places() { - long count = 1000; - long timeMs = 1000; - int numDecimals = 0; - double defaultRate = 0; - double expectedRate = 1000; - - double rate = AgentStatUtils.calculateRate(count, timeMs, numDecimals, defaultRate); - Assertions.assertEquals(Double.doubleToLongBits(expectedRate), Double.doubleToLongBits(rate)); - } - - @Test - public void getBaseTimestamp_should_return_a_multiple_of_AGENT_STAT_TIMESPAN_MS() { - long timestamp = RANDOM.nextLong(); - long baseTimestamp = AgentStatUtils.getBaseTimestamp(timestamp); - Assertions.assertEquals(0, (baseTimestamp % HbaseColumnFamily.AGENT_STAT_STATISTICS.TIMESPAN_MS)); - } -} diff --git a/otlpmetric/otlpmetric-web/src/main/resources/otlpmetric/web/profiles/local/otlpmetric-web.properties b/otlpmetric/otlpmetric-web/src/main/resources/otlpmetric/web/profiles/local/otlpmetric-web.properties index 5fe5f09311cc..bcca6dde97ce 100644 --- a/otlpmetric/otlpmetric-web/src/main/resources/otlpmetric/web/profiles/local/otlpmetric-web.properties +++ b/otlpmetric/otlpmetric-web/src/main/resources/otlpmetric/web/profiles/local/otlpmetric-web.properties @@ -5,4 +5,4 @@ pinot.otlpmetric.topic.long.prefix=otlpMetricLong pinot.otlpmetric.topic.long.padding.length=2 pinot.otlpmetric.topic.long.count=1 -config.show.otlpMetric=false \ No newline at end of file +config.show.otlpMetric=true \ No newline at end of file diff --git a/otlpmetric/otlpmetric-web/src/main/resources/otlpmetric/web/profiles/release/otlpmetric-web.properties b/otlpmetric/otlpmetric-web/src/main/resources/otlpmetric/web/profiles/release/otlpmetric-web.properties index 5fe5f09311cc..bcca6dde97ce 100644 --- a/otlpmetric/otlpmetric-web/src/main/resources/otlpmetric/web/profiles/release/otlpmetric-web.properties +++ b/otlpmetric/otlpmetric-web/src/main/resources/otlpmetric/web/profiles/release/otlpmetric-web.properties @@ -5,4 +5,4 @@ pinot.otlpmetric.topic.long.prefix=otlpMetricLong pinot.otlpmetric.topic.long.padding.length=2 pinot.otlpmetric.topic.long.count=1 -config.show.otlpMetric=false \ No newline at end of file +config.show.otlpMetric=true \ No newline at end of file diff --git a/web-starter/src/main/resources/application.yml b/web-starter/src/main/resources/application.yml index acb0430561e1..8894fe0befb6 100644 --- a/web-starter/src/main/resources/application.yml +++ b/web-starter/src/main/resources/application.yml @@ -28,7 +28,9 @@ pinpoint: enabled: true realtime: enabled: true - + otlpmetric: + enabled: true + pinpoint.web.websocket: async-send-timeout: max-session-idle-timeout: 10800000 # 3 hours diff --git a/web/src/main/java/com/navercorp/pinpoint/web/WebHbaseModule.java b/web/src/main/java/com/navercorp/pinpoint/web/WebHbaseModule.java index 0e19b0bd0259..cb29dc0a117b 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/WebHbaseModule.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/WebHbaseModule.java @@ -6,9 +6,6 @@ import com.navercorp.pinpoint.common.server.CommonsHbaseConfiguration; import com.navercorp.pinpoint.common.server.hbase.config.HbaseClientConfiguration; import com.navercorp.pinpoint.web.applicationmap.config.MapHbaseConfiguration; -import com.navercorp.pinpoint.web.dao.hbase.config.AgentStatDaoConfiguration; -import com.navercorp.pinpoint.web.dao.hbase.config.AgentStatOperationConfiguration; -import com.navercorp.pinpoint.web.dao.hbase.config.SampledAgentStatDaoConfiguration; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.context.annotation.ComponentScan; @@ -20,10 +17,6 @@ @Configuration @Import({ CommonsHbaseConfiguration.class, - AgentStatDaoConfiguration.class, - AgentStatOperationConfiguration.class, - - SampledAgentStatDaoConfiguration.class, HbaseNamespaceConfiguration.class, DistributorConfiguration.class, diff --git a/web/src/main/java/com/navercorp/pinpoint/web/alarm/DataCollectorCategory.java b/web/src/main/java/com/navercorp/pinpoint/web/alarm/DataCollectorCategory.java index b342a29d8dbc..bb655ad818e3 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/alarm/DataCollectorCategory.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/alarm/DataCollectorCategory.java @@ -2,7 +2,6 @@ public enum DataCollectorCategory { RESPONSE_TIME, - AGENT_STAT, AGENT_EVENT, DATA_SOURCE_STAT, CALLER_STAT, diff --git a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentStatController.java b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentStatController.java deleted file mode 100644 index f507147eebe4..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentStatController.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2014 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.web.authorization.controller; - - -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.web.service.stat.AgentStatChartService; -import com.navercorp.pinpoint.web.service.stat.AgentStatService; -import com.navercorp.pinpoint.common.server.util.timewindow.FixedTimeWindowSampler; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindowSampler; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindowSlotCentricSampler; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChart; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.PositiveOrZero; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; -import java.util.Map; - -/** - * @author emeroad - * @author minwoo.jung - * @author HyunGil Jeong - */ -@RestController -@RequestMapping("/api/getAgentStat/{chartType}") -@Validated -public class AgentStatController { - private final Logger logger = LogManager.getLogger(this.getClass()); - private final TimeWindowSampler defaultStatTimeWindowSampler = new TimeWindowSlotCentricSampler(); - - private final Map> agentStatServiceMap; - - private final Map> agentStatChartServiceMap; - - public AgentStatController( - List> agentStatServiceList, - List> agentStatChartServiceList - ) { - this.agentStatServiceMap = buildDispatchMap(agentStatServiceList); - this.agentStatChartServiceMap = buildDispatchMap(agentStatChartServiceList); - } - - private Map buildDispatchMap(List list) { - final ChartTypeMappingBuilder mapping = new ChartTypeMappingBuilder<>(); - - final Map map = mapping.build(list); - - for (final Map.Entry entry : map.entrySet()) { - Class serviceClass = entry.getValue().getClass(); - String chartType = entry.getKey(); - logger.info("chartType:{} {}", chartType, serviceClass.getSimpleName()); - } - return map; - } - - private static T getChartService(Map map, String chartType) { - final T service = map.get(chartType); - if (service == null) { - throw new IllegalArgumentException("chartType pathVariable not found chartType:" + chartType); - } - return service; - } - - @GetMapping() - public List getAgentStat( - @RequestParam("agentId") @NotBlank String agentId, - @PathVariable("chartType") @NotBlank String chartType, - @RequestParam("from") @PositiveOrZero long from, - @RequestParam("to") @PositiveOrZero long to) { - final Range rangeToScan = Range.between(from, to); - - final AgentStatService agentStatService = getChartService(this.agentStatServiceMap, chartType); - return agentStatService.selectAgentStatList(agentId, rangeToScan); - } - - - @GetMapping(value = "/chart") - public StatChart getAgentStatChart( - @RequestParam("agentId") @NotBlank String agentId, - @PathVariable("chartType") @NotBlank String chartType, - @RequestParam("from") @PositiveOrZero long from, - @RequestParam("to") @PositiveOrZero long to) { - final TimeWindow timeWindow = new TimeWindow(Range.between(from, to), defaultStatTimeWindowSampler); - - final AgentStatChartService agentStatChartService = - getChartService(this.agentStatChartServiceMap, chartType); - return agentStatChartService.selectAgentChart(agentId, timeWindow); - } - - @GetMapping(value = "/chart", params = {"interval"}) - public StatChart getAgentStatChart( - @RequestParam("agentId") @NotBlank String agentId, - @PathVariable("chartType") @NotBlank String chartType, - @RequestParam("from") @PositiveOrZero long from, - @RequestParam("to") @PositiveOrZero long to, - @RequestParam("interval") @PositiveOrZero Integer interval) { - final int minSamplingInterval = 5; - final long intervalMs = interval < minSamplingInterval ? minSamplingInterval * 1000L : interval * 1000L; - final TimeWindowSampler sampler = new FixedTimeWindowSampler(intervalMs); - final TimeWindow timeWindow = new TimeWindow(Range.between(from, to), sampler); - - final AgentStatChartService> agentStatChartService = - getChartService(this.agentStatChartServiceMap, chartType); - return agentStatChartService.selectAgentChart(agentId, timeWindow); - } - - @GetMapping(value = "/chartList") - public List> getAgentStatChartList( - @RequestParam("agentId") @NotBlank String agentId, - @PathVariable("chartType") @NotBlank String chartType, - @RequestParam("from") @PositiveOrZero long from, - @RequestParam("to") @PositiveOrZero long to) { - final TimeWindow timeWindow = new TimeWindow(Range.between(from, to), defaultStatTimeWindowSampler); - - final AgentStatChartService> agentStatChartService = - getChartService(this.agentStatChartServiceMap, chartType); - return agentStatChartService.selectAgentChartList(agentId, timeWindow); - } - - @GetMapping(value = "/chartList", params = {"interval"}) - public List> getAgentStatChartList( - @RequestParam("agentId") @NotBlank String agentId, - @PathVariable("chartType") @NotBlank String chartType, - @RequestParam("from") @PositiveOrZero long from, - @RequestParam("to") @PositiveOrZero long to, - @RequestParam("interval") Integer interval) { - final int minSamplingInterval = 5; - final long intervalMs = interval < minSamplingInterval ? minSamplingInterval * 1000L : interval * 1000L; - final TimeWindowSampler sampler = new FixedTimeWindowSampler(intervalMs); - final TimeWindow timeWindow = new TimeWindow(Range.between(from, to), sampler); - - final AgentStatChartService agentStatChartService = - getChartService(this.agentStatChartServiceMap, chartType); - return agentStatChartService.selectAgentChartList(agentId, timeWindow); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/ChartTypeMappingBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/ChartTypeMappingBuilder.java deleted file mode 100644 index f1199574fb11..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/ChartTypeMappingBuilder.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.navercorp.pinpoint.web.authorization.controller; - -import com.navercorp.pinpoint.web.service.stat.ChartTypeSupport; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class ChartTypeMappingBuilder { - - - public ChartTypeMappingBuilder() { - } - - public Map build(List serviceList) { - final Map map = new HashMap<>(); - for (final T service : serviceList) { - final String chartType = getChartType(service); - - final T duplicate = map.put(chartType, service); - if (duplicate != null) { - String errorMessage = String.format("Duplicated ChartService chartType:%s %s:%s", chartType, service, duplicate); - throw new IllegalArgumentException(errorMessage); - } - } - - return Map.copyOf(map); - } - - protected String getChartType(T service) { - if (service instanceof ChartTypeSupport chartTypeSupport) { - return chartTypeSupport.getChartType(); - } - throw new RuntimeException("Unknown ChartTypeSupport " + service); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/SampledAgentStatDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/SampledAgentStatDao.java deleted file mode 100644 index b3a8aca623ba..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/SampledAgentStatDao.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2016 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.web.dao; - -import com.navercorp.pinpoint.web.service.stat.ChartTypeSupport; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -@Repository -public interface SampledAgentStatDao extends ChartTypeSupport { - - List getSampledAgentStatList(String agentId, TimeWindow timeWindow); -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HBaseUtils.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HBaseUtils.java index 24f22c49aa6c..a678660540ac 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HBaseUtils.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HBaseUtils.java @@ -1,7 +1,5 @@ package com.navercorp.pinpoint.web.dao.hbase; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatUtils; -import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.common.util.ArrayUtils; import com.navercorp.pinpoint.common.util.CollectionUtils; import org.apache.hadoop.hbase.filter.Filter; @@ -10,7 +8,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Objects; public final class HBaseUtils { private HBaseUtils() { @@ -37,21 +34,4 @@ public static Filter newFilterList(Filter... filters) { } return new FilterList(nonNullFilters); } - - public static int getScanCacheSize(Range range, long timespan, int maxCacheSize) { - Objects.requireNonNull(range, "range"); - - long scanRange = range.durationMillis(); - long expectedNumRows = ((scanRange - 1) / timespan) + 1; - if (range.getFrom() != AgentStatUtils.getBaseTimestamp(range.getFrom())) { - expectedNumRows++; - } - if (expectedNumRows > maxCacheSize) { - return maxCacheSize; - } else { - // expectedNumRows guaranteed to be within integer range at this point - return (int) expectedNumRows; - } - } - } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/config/AgentStatDaoConfiguration.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/config/AgentStatDaoConfiguration.java deleted file mode 100644 index 9b49980381fd..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/config/AgentStatDaoConfiguration.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.navercorp.pinpoint.web.dao.hbase.config; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDecoder; -import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -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.DataSourceListBo; -import com.navercorp.pinpoint.common.server.bo.stat.DeadlockThreadCountBo; -import com.navercorp.pinpoint.common.server.bo.stat.DirectBufferBo; -import com.navercorp.pinpoint.common.server.bo.stat.FileDescriptorBo; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; -import com.navercorp.pinpoint.common.server.bo.stat.LoadedClassBo; -import com.navercorp.pinpoint.common.server.bo.stat.ResponseTimeBo; -import com.navercorp.pinpoint.common.server.bo.stat.TotalThreadCountBo; -import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; -import com.navercorp.pinpoint.web.dao.hbase.stat.DefaultAgentStatDao; -import com.navercorp.pinpoint.web.dao.hbase.stat.HbaseAgentStatDaoOperations; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.Objects; - -@Configuration -public class AgentStatDaoConfiguration { - private final HbaseAgentStatDaoOperations operations; - - public AgentStatDaoConfiguration(HbaseAgentStatDaoOperations operations) { - this.operations = Objects.requireNonNull(operations, "operations"); - } - - private AgentStatDao newStatDao(AgentStatType statType, AgentStatDecoder decoder) { - Objects.requireNonNull(statType, "statType"); - Objects.requireNonNull(decoder, "decoder"); - - return new DefaultAgentStatDao<>(statType, operations, decoder); - } - - @Bean - public AgentStatDao getJvmGcWebDao(AgentStatDecoder decoder) { - return newStatDao(AgentStatType.JVM_GC, decoder); - } - - @Bean - public AgentStatDao getJvmGcDetailedWebDao(AgentStatDecoder decoder) { - return newStatDao(AgentStatType.JVM_GC_DETAILED, decoder); - } - - @Bean - public AgentStatDao getCpuLoadWebDao(AgentStatDecoder decoder) { - return newStatDao(AgentStatType.CPU_LOAD, decoder); - } - - @Bean - public AgentStatDao getTransactionWebDao(AgentStatDecoder decoder) { - return newStatDao(AgentStatType.TRANSACTION, decoder); - } - - @Bean - public AgentStatDao getActiveTraceWebDao(AgentStatDecoder decoder) { - return newStatDao(AgentStatType.ACTIVE_TRACE, decoder); - } - - @Bean - public AgentStatDao getDataSourceListWebDao(AgentStatDecoder decoder) { - return newStatDao(AgentStatType.DATASOURCE, decoder); - } - - @Bean - public AgentStatDao getResponseTimeWebDao(AgentStatDecoder decoder) { - return newStatDao(AgentStatType.RESPONSE_TIME, decoder); - } - - @Bean - public AgentStatDao getDeadlockThreadCountWebDao(AgentStatDecoder decoder) { - return newStatDao(AgentStatType.DEADLOCK, decoder); - } - - @Bean - public AgentStatDao getFileDescriptorWebDao(AgentStatDecoder decoder) { - return newStatDao(AgentStatType.FILE_DESCRIPTOR, decoder); - } - - @Bean - public AgentStatDao getDirectBufferWebDao(AgentStatDecoder decoder) { - return newStatDao(AgentStatType.DIRECT_BUFFER, decoder); - } - - @Bean - public AgentStatDao getTotalThreadCountWebDao(AgentStatDecoder decoder) { - return newStatDao(AgentStatType.TOTAL_THREAD, decoder); - } - - @Bean - public AgentStatDao getLoadedClassWebDao(AgentStatDecoder decoder) { - return newStatDao(AgentStatType.LOADED_CLASS, decoder); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/config/AgentStatOperationConfiguration.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/config/AgentStatOperationConfiguration.java deleted file mode 100644 index a0451f634369..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/config/AgentStatOperationConfiguration.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.navercorp.pinpoint.web.dao.hbase.config; - -import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; -import com.navercorp.pinpoint.common.hbase.HbaseOperations; -import com.navercorp.pinpoint.common.hbase.TableNameProvider; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatHbaseOperationFactory; -import com.navercorp.pinpoint.web.dao.hbase.stat.HbaseAgentStatDaoOperations; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -@Configuration -public class AgentStatOperationConfiguration { - - @Primary - @Bean - public HbaseAgentStatDaoOperations agentStatDaoOperations(HbaseOperations hbaseOperations, - TableNameProvider tableNameProvider, - AgentStatHbaseOperationFactory operationFactory) { - HbaseColumnFamily.AgentStatStatistics stat = HbaseColumnFamily.AGENT_STAT_STATISTICS; - return new HbaseAgentStatDaoOperations(stat, stat.TIMESPAN_MS, hbaseOperations, tableNameProvider, operationFactory); - } - - @Bean - public HbaseAgentStatDaoOperations agentUriDaoOperations(HbaseOperations hbaseOperations, - TableNameProvider tableNameProvider, - AgentStatHbaseOperationFactory operationFactory) { - HbaseColumnFamily.AgentUriStatStatistics uri = HbaseColumnFamily.AGENT_URI_STAT_STATISTICS; - return new HbaseAgentStatDaoOperations(uri, uri.TIMESPAN_MS, hbaseOperations, tableNameProvider, operationFactory); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/config/SampledAgentStatDaoConfiguration.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/config/SampledAgentStatDaoConfiguration.java deleted file mode 100644 index b0a298efb02b..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/config/SampledAgentStatDaoConfiguration.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.navercorp.pinpoint.web.dao.hbase.config; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDecoder; -import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -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.DataSourceBo; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceListBo; -import com.navercorp.pinpoint.common.server.bo.stat.DeadlockThreadCountBo; -import com.navercorp.pinpoint.common.server.bo.stat.DirectBufferBo; -import com.navercorp.pinpoint.common.server.bo.stat.FileDescriptorBo; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; -import com.navercorp.pinpoint.common.server.bo.stat.LoadedClassBo; -import com.navercorp.pinpoint.common.server.bo.stat.ResponseTimeBo; -import com.navercorp.pinpoint.common.server.bo.stat.TotalThreadCountBo; -import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; -import com.navercorp.pinpoint.web.dao.SampledAgentStatDao; -import com.navercorp.pinpoint.web.dao.hbase.stat.DefaultSampledAgentStatDao; -import com.navercorp.pinpoint.web.dao.hbase.stat.HbaseAgentStatDaoOperations; -import com.navercorp.pinpoint.web.dao.hbase.stat.HbaseSampledDataSourceDao; -import com.navercorp.pinpoint.web.dao.hbase.stat.SampledAgentStatResultExtractorSupplier; -import com.navercorp.pinpoint.web.dao.hbase.stat.SampledResultsExtractorSupplier; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.AgentStatSampler; -import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; -import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; -import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSource; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSourceList; -import com.navercorp.pinpoint.web.vo.stat.SampledDeadlock; -import com.navercorp.pinpoint.web.vo.stat.SampledDirectBuffer; -import com.navercorp.pinpoint.web.vo.stat.SampledFileDescriptor; -import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; -import com.navercorp.pinpoint.web.vo.stat.SampledJvmGcDetailed; -import com.navercorp.pinpoint.web.vo.stat.SampledLoadedClassCount; -import com.navercorp.pinpoint.web.vo.stat.SampledResponseTime; -import com.navercorp.pinpoint.web.vo.stat.SampledTotalThreadCount; -import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.Objects; - -@Configuration -public class SampledAgentStatDaoConfiguration { - - private final HbaseAgentStatDaoOperations operations; - - public SampledAgentStatDaoConfiguration(HbaseAgentStatDaoOperations operations) { - this.operations = Objects.requireNonNull(operations, "operations"); - } - - - private SampledAgentStatDao newSampledDao(AgentStatType statType, - AgentStatDecoder decoder, - AgentStatSampler sampler) { - Objects.requireNonNull(statType, "statType"); - Objects.requireNonNull(decoder, "decoder"); - Objects.requireNonNull(sampler, "sampler"); - - SampledResultsExtractorSupplier supplier = new SampledAgentStatResultExtractorSupplier<>(sampler); - return new DefaultSampledAgentStatDao<>(statType, operations, decoder, supplier); - } - - @Bean - public SampledAgentStatDao getSampledJvmGcDao(AgentStatDecoder decoder, - AgentStatSampler sampler) { - return newSampledDao(AgentStatType.JVM_GC, decoder, sampler); - } - - @Bean - public SampledAgentStatDao getSampledJvmGcDetailedDao(AgentStatDecoder decoder, - AgentStatSampler sampler) { - return newSampledDao(AgentStatType.JVM_GC_DETAILED, decoder, sampler); - } - - @Bean - public SampledAgentStatDao getSampledCpuLoadDao(AgentStatDecoder decoder, - AgentStatSampler sampler) { - return newSampledDao(AgentStatType.CPU_LOAD, decoder, sampler); - } - - @Bean - public SampledAgentStatDao getSampledTransactionDao(AgentStatDecoder decoder, - AgentStatSampler sampler) { - return newSampledDao(AgentStatType.TRANSACTION, decoder, sampler); - } - - - @Bean - public SampledAgentStatDao getSampledActiveTraceDao(AgentStatDecoder decoder, - AgentStatSampler sampler) { - return newSampledDao(AgentStatType.ACTIVE_TRACE, decoder, sampler); - } - -// @Bean - public SampledAgentStatDao getSampledDataSourceListDao(AgentStatDecoder decoder, - AgentStatSampler sampler) { - return new HbaseSampledDataSourceDao(operations, decoder, sampler); - } - - @Bean - public SampledAgentStatDao getSampledResponseTimeDao(AgentStatDecoder decoder, - AgentStatSampler sampler) { - return newSampledDao(AgentStatType.RESPONSE_TIME, decoder, sampler); - } - - @Bean - public SampledAgentStatDao getSampledDeadlockDao(AgentStatDecoder decoder, - AgentStatSampler sampler) { - return newSampledDao(AgentStatType.DEADLOCK, decoder, sampler); - } - - @Bean - public SampledAgentStatDao getSampledFileDescriptorDao(AgentStatDecoder decoder, - AgentStatSampler sampler) { - return newSampledDao(AgentStatType.FILE_DESCRIPTOR, decoder, sampler); - } - - - @Bean - public SampledAgentStatDao getSampledDirectBufferDao(AgentStatDecoder decoder, - AgentStatSampler sampler) { - return newSampledDao(AgentStatType.DIRECT_BUFFER, decoder, sampler); - } - - @Bean - public SampledAgentStatDao getSampledTotalThreadCountDao(AgentStatDecoder decoder, - AgentStatSampler sampler) { - return newSampledDao(AgentStatType.TOTAL_THREAD, decoder, sampler); - } - - - @Bean - public SampledAgentStatDao getSampledLoadedClassCountDao(AgentStatDecoder decoder, - AgentStatSampler sampler) { - return newSampledDao(AgentStatType.LOADED_CLASS, decoder, sampler); - } - -} \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/DefaultAgentStatDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/DefaultAgentStatDao.java deleted file mode 100644 index dfa8b3c33327..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/DefaultAgentStatDao.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.navercorp.pinpoint.web.dao.hbase.stat; - -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDecoder; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; -import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; - -import java.util.List; -import java.util.Objects; - -public class DefaultAgentStatDao implements AgentStatDao { - private final AgentStatType statType; - private final HbaseAgentStatDaoOperations operations; - private final AgentStatDecoder decoder; - - public DefaultAgentStatDao(AgentStatType statType, HbaseAgentStatDaoOperations operations, AgentStatDecoder decoder) { - this.statType = Objects.requireNonNull(statType, "statType"); - this.operations = Objects.requireNonNull(operations, "operations"); - this.decoder = Objects.requireNonNull(decoder, "decoder"); - } - - @Override - public List getAgentStatList(String agentId, Range range) { - Objects.requireNonNull(agentId, "agentId"); - Objects.requireNonNull(range, "range"); - - AgentStatMapperV2 mapper = operations.createRowMapper(decoder, range); - return operations.getAgentStatList(statType, mapper, agentId, range); - } - - @Override - public boolean agentStatExists(String agentId, Range range) { - Objects.requireNonNull(agentId, "agentId"); - Objects.requireNonNull(range, "range"); - - AgentStatMapperV2 mapper = operations.createRowMapper(decoder, range); - return operations.agentStatExists(statType, mapper, agentId, range); - } - - @Override - public String getChartType() { - return statType.getChartType(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/DefaultSampledAgentStatDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/DefaultSampledAgentStatDao.java deleted file mode 100644 index 2e6438df7cae..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/DefaultSampledAgentStatDao.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.navercorp.pinpoint.web.dao.hbase.stat; - -import com.navercorp.pinpoint.common.hbase.ResultsExtractor; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDecoder; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.web.dao.SampledAgentStatDao; -import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; - -import java.util.List; -import java.util.Objects; - -public class DefaultSampledAgentStatDao implements SampledAgentStatDao { - private final AgentStatType statType; - private final HbaseAgentStatDaoOperations operations; - private final AgentStatDecoder decoder; - private final SampledResultsExtractorSupplier resultExtractor; - - public DefaultSampledAgentStatDao(AgentStatType statType, - HbaseAgentStatDaoOperations operations, - AgentStatDecoder decoder, - SampledResultsExtractorSupplier resultExtractor) { - this.statType = Objects.requireNonNull(statType, "statType"); - this.operations = Objects.requireNonNull(operations, "operations"); - this.decoder = Objects.requireNonNull(decoder, "decoder"); - this.resultExtractor = Objects.requireNonNull(resultExtractor, "resultExtractor"); - } - - @Override - public List getSampledAgentStatList(String agentId, TimeWindow timeWindow) { - Objects.requireNonNull(agentId, "agentId"); - Objects.requireNonNull(timeWindow, "timeWindow"); - - Range range = timeWindow.getWindowSlotRange(); - - AgentStatMapperV2 mapper = operations.createRowMapper(decoder, range); - - ResultsExtractor> resultExtractor = this.resultExtractor.apply(timeWindow, mapper); - return operations.getSampledAgentStatList(statType, resultExtractor, agentId, range); - } - - @Override - public String getChartType() { - return statType.getChartType(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/HbaseAgentStatDaoOperations.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/HbaseAgentStatDaoOperations.java deleted file mode 100644 index 79fd6b7343c3..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/HbaseAgentStatDaoOperations.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2016 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.web.dao.hbase.stat; - -import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; -import com.navercorp.pinpoint.common.hbase.HbaseOperations; -import com.navercorp.pinpoint.common.hbase.ResultsExtractor; -import com.navercorp.pinpoint.common.hbase.TableNameProvider; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDecoder; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatHbaseOperationFactory; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.web.dao.hbase.HBaseUtils; -import com.navercorp.pinpoint.web.mapper.RangeTimestampFilter; -import com.navercorp.pinpoint.web.mapper.TimestampFilter; -import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; -import com.navercorp.pinpoint.web.util.ListListUtils; -import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; -import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.client.Scan; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.List; -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -public class HbaseAgentStatDaoOperations { - - private static final int AGENT_STAT_VER2_NUM_PARTITIONS = 32; - private static final int MAX_SCAN_CACHE_SIZE = 256; - - private final Logger logger = LogManager.getLogger(this.getClass()); - private final HbaseColumnFamily columnFamily; - private final long timespan; - - private final HbaseOperations hbaseOperations; - private final TableNameProvider tableNameProvider; - - private final AgentStatHbaseOperationFactory operationFactory; - - - public HbaseAgentStatDaoOperations(HbaseColumnFamily columnFamily, long timespan, - HbaseOperations hbaseOperations, - TableNameProvider tableNameProvider, - AgentStatHbaseOperationFactory operationFactory) { - this.hbaseOperations = Objects.requireNonNull(hbaseOperations, "hbaseOperations"); - this.columnFamily = Objects.requireNonNull(columnFamily, "columnFamily"); - this.timespan = timespan; - this.tableNameProvider = Objects.requireNonNull(tableNameProvider, "tableNameProvider"); - this.operationFactory = Objects.requireNonNull(operationFactory, "operationFactory"); - } - - List getAgentStatList(AgentStatType agentStatType, AgentStatMapperV2 mapper, String agentId, Range range) { - Objects.requireNonNull(agentId, "agentId"); - Objects.requireNonNull(range, "range"); - - Scan scan = this.createScan(agentStatType, agentId, range); - - TableName agentStatTableName = tableNameProvider.getTableName(columnFamily.getTable()); - List> intermediate = hbaseOperations.findParallel(agentStatTableName, scan, this.operationFactory.getRowKeyDistributor(), mapper, AGENT_STAT_VER2_NUM_PARTITIONS); - int expectedSize = (int) (range.durationMillis() / timespan); - - return ListListUtils.toList(intermediate, expectedSize); - } - - boolean agentStatExists(AgentStatType agentStatType, AgentStatMapperV2 mapper, String agentId, Range range) { - Objects.requireNonNull(agentId, "agentId"); - Objects.requireNonNull(range, "range"); - - if (logger.isDebugEnabled()) { - logger.debug("checking for stat data existence : agentId={}, {}", agentId, range); - } - - int resultLimit = 20; - Scan scan = this.checkExist(agentStatType, agentId, range, resultLimit); - - TableName agentStatTableName = tableNameProvider.getTableName(columnFamily.getTable()); - List> result = hbaseOperations.findParallel(agentStatTableName, scan, this.operationFactory.getRowKeyDistributor(), resultLimit, mapper, AGENT_STAT_VER2_NUM_PARTITIONS); - if (result.isEmpty()) { - return false; - } else { - return true; - } - } - - List getSampledAgentStatList(AgentStatType agentStatType, ResultsExtractor> resultExtractor, String agentId, Range range) { - Objects.requireNonNull(agentId, "agentId"); - Objects.requireNonNull(range, "range"); - Objects.requireNonNull(resultExtractor, "resultExtractor"); - - Scan scan = this.createScan(agentStatType, agentId, range); - - TableName agentStatTableName = tableNameProvider.getTableName(columnFamily.getTable()); - return hbaseOperations.findParallel(agentStatTableName, scan, this.operationFactory.getRowKeyDistributor(), resultExtractor, AGENT_STAT_VER2_NUM_PARTITIONS); - } - - AgentStatMapperV2 createRowMapper(AgentStatDecoder decoder, Range range) { - TimestampFilter filter = new RangeTimestampFilter(range); - return new AgentStatMapperV2<>(this.operationFactory, decoder, filter, columnFamily); - } - - private Scan createScan(AgentStatType agentStatType, String agentId, Range range) { - int scanCacheSize = HBaseUtils.getScanCacheSize(range, timespan, MAX_SCAN_CACHE_SIZE); - return this.createScan(agentStatType, agentId, range, scanCacheSize); - } - - private Scan createScan(AgentStatType agentStatType, String agentId, Range range, int scanCacheSize) { - Scan scan = this.operationFactory.createScan(agentId, agentStatType, range.getFrom(), range.getTo()); - scan.setCaching(scanCacheSize); - scan.setId(agentStatType.getChartType()); - scan.addFamily(columnFamily.getName()); - return scan; - } - - private Scan checkExist(AgentStatType agentStatType, String agentId, Range range, int scanCacheSize) { - Scan scan = this.operationFactory.createScan(agentId, agentStatType, range.getFrom(), range.getTo()); - scan.setCaching(scanCacheSize); - scan.setOneRowLimit(); - scan.setId(agentStatType.getChartType()); - scan.addFamily(columnFamily.getName()); - return scan; - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/HbaseSampledDataSourceDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/HbaseSampledDataSourceDao.java deleted file mode 100644 index f59896b787d9..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/HbaseSampledDataSourceDao.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2017 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.web.dao.hbase.stat; - -import com.navercorp.pinpoint.common.hbase.ResultsExtractor; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDecoder; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceBo; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceListBo; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.web.dao.SampledAgentStatDao; -import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; -import com.navercorp.pinpoint.web.mapper.stat.SampledDataSourceResultExtractor; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.AgentStatSampler; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSource; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSourceList; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.Objects; - -/** - * @author Taejin Koo - */ -@Repository -public class HbaseSampledDataSourceDao implements SampledAgentStatDao { - - private final AgentStatType statType = AgentStatType.DATASOURCE; - private final HbaseAgentStatDaoOperations operations; - - private final AgentStatDecoder decoder; - private final AgentStatSampler sampler; - - public HbaseSampledDataSourceDao(HbaseAgentStatDaoOperations operations, - AgentStatDecoder decoder, - AgentStatSampler sampler) { - this.operations = Objects.requireNonNull(operations, "operations"); - this.decoder = Objects.requireNonNull(decoder, "decoder"); - this.sampler = Objects.requireNonNull(sampler, "sampler"); - } - - @Override - public List getSampledAgentStatList(String agentId, TimeWindow timeWindow) { - Range range = timeWindow.getWindowSlotRange(); - - AgentStatMapperV2 mapper = operations.createRowMapper(decoder, range); - ResultsExtractor> resultExtractor = new SampledDataSourceResultExtractor(timeWindow, mapper, sampler); - return operations.getSampledAgentStatList(statType, resultExtractor, agentId, range); - } - - @Override - public String getChartType() { - return statType.getChartType(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/SampledAgentStatResultExtractorSupplier.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/SampledAgentStatResultExtractorSupplier.java deleted file mode 100644 index 95a648017150..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/SampledAgentStatResultExtractorSupplier.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.navercorp.pinpoint.web.dao.hbase.stat; - -import com.navercorp.pinpoint.common.hbase.ResultsExtractor; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; -import com.navercorp.pinpoint.web.mapper.stat.SampledAgentStatResultExtractor; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.AgentStatSampler; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; - -import java.util.List; -import java.util.Objects; - -public class SampledAgentStatResultExtractorSupplier - implements SampledResultsExtractorSupplier { - - private final AgentStatSampler sampler; - - public SampledAgentStatResultExtractorSupplier(AgentStatSampler sampler) { - this.sampler = Objects.requireNonNull(sampler, "sampler"); - } - - @Override - public ResultsExtractor> apply(TimeWindow timeWindow, AgentStatMapperV2 mapper) { - return new SampledAgentStatResultExtractor<>(timeWindow, mapper, sampler); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/SampledResultsExtractorSupplier.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/SampledResultsExtractorSupplier.java deleted file mode 100644 index b84248bef68a..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/SampledResultsExtractorSupplier.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.web.dao.hbase.stat; - -import com.navercorp.pinpoint.common.hbase.ResultsExtractor; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; - -import java.util.List; - -/** - * @author Woonduk Kang(emeroad) - */ -@FunctionalInterface -public interface SampledResultsExtractorSupplier { - ResultsExtractor> apply(TimeWindow timeWindow, AgentStatMapperV2 mapper); -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/AgentStatDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/AgentStatDao.java deleted file mode 100644 index a67de26d0042..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/AgentStatDao.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2014 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.web.dao.stat; - -import java.util.List; - -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.web.service.stat.ChartTypeSupport; -import org.springframework.stereotype.Repository; - -/** - * @author HyunGil Jeong - */ -@Repository -public interface AgentStatDao extends ChartTypeSupport { - - List getAgentStatList(String agentId, Range range); - - boolean agentStatExists(String agentId, Range range); -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapper.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapper.java deleted file mode 100644 index d1e71070043d..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapper.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2016 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.web.mapper.stat; - -import com.navercorp.pinpoint.common.hbase.RowMapper; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -public interface AgentStatMapper extends RowMapper> { -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2.java deleted file mode 100644 index 53956dd711fc..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2016 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.web.mapper.stat; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer; -import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDecoder; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatHbaseOperationFactory; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPointList; -import com.navercorp.pinpoint.web.mapper.TimestampFilter; -import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.client.Result; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -public class AgentStatMapperV2 implements AgentStatMapper { - - public final static Comparator REVERSE_TIMESTAMP_COMPARATOR - = Comparator.comparingLong(AgentStatDataPoint::getTimestamp).reversed(); - - private final AgentStatHbaseOperationFactory hbaseOperationFactory; - private final AgentStatDecoder decoder; - private final TimestampFilter filter; - private final HbaseColumnFamily targetHbaseColumnFamily; - - public AgentStatMapperV2(AgentStatHbaseOperationFactory hbaseOperationFactory, AgentStatDecoder decoder, TimestampFilter filter, HbaseColumnFamily targetHbaseColumnFamily) { - this.hbaseOperationFactory = hbaseOperationFactory; - this.decoder = decoder; - this.filter = filter; - this.targetHbaseColumnFamily = Objects.requireNonNull(targetHbaseColumnFamily, "targetHbaseColumnFamily"); - } - - @Override - public List mapRow(Result result, int rowNum) throws Exception { - if (result.isEmpty()) { - return Collections.emptyList(); - } - final byte[] distributedRowKey = result.getRow(); - final String agentId = this.hbaseOperationFactory.getAgentId(distributedRowKey); - final long baseTimestamp = this.hbaseOperationFactory.getBaseTimestamp(distributedRowKey); - - List dataPoints = new ArrayList<>(); - - for (Cell cell : result.rawCells()) { - if (CellUtil.matchingFamily(cell, targetHbaseColumnFamily.getName())) { - Buffer qualifierBuffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); - Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); - - long timestampDelta = this.decoder.decodeQualifier(qualifierBuffer); - - AgentStatDecodingContext decodingContext = new AgentStatDecodingContext(); - decodingContext.setAgentId(agentId); - decodingContext.setBaseTimestamp(baseTimestamp); - decodingContext.setTimestampDelta(timestampDelta); - List candidates = this.decoder.decodeValue(valueBuffer, decodingContext); - for (T candidate : candidates) { - if (filter(candidate)) { - continue; - } - dataPoints.add(candidate); - } - } - } - // Reverse sort as timestamp is stored in a reversed order. - dataPoints.sort(REVERSE_TIMESTAMP_COMPARATOR); - return dataPoints; - } - - private boolean filter(T candidate) { - if (candidate instanceof AgentStatDataPointList agentStatDataPointList) { - List list = agentStatDataPointList.getList(); - for (AgentStatDataPoint agentStatDataPoint : list) { - long timestamp = agentStatDataPoint.getTimestamp(); - if (!this.filter.filter(timestamp)) { - return false; - } - } - return true; - } else { - long timestamp = candidate.getTimestamp(); - return this.filter.filter(timestamp); - } - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractor.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractor.java deleted file mode 100644 index 7623c205bbb4..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2016 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.web.mapper.stat; - -import com.navercorp.pinpoint.common.hbase.ResultsExtractor; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.web.mapper.stat.sampling.AgentStatSamplingHandler; -import com.navercorp.pinpoint.web.mapper.stat.sampling.EagerSamplingHandler; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.AgentStatSampler; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; -import org.apache.hadoop.hbase.client.Result; -import org.apache.hadoop.hbase.client.ResultScanner; - -import java.util.List; - - -/** - * @author HyunGil Jeong - */ -public class SampledAgentStatResultExtractor implements ResultsExtractor> { - - private final TimeWindow timeWindow; - private final AgentStatMapper rowMapper; - private final AgentStatSampler sampler; - - public SampledAgentStatResultExtractor(TimeWindow timeWindow, AgentStatMapper rowMapper, AgentStatSampler sampler) { - if (timeWindow.getWindowRangeCount() > Integer.MAX_VALUE) { - throw new IllegalArgumentException("range yields too many timeslots"); - } - this.timeWindow = timeWindow; - this.rowMapper = rowMapper; - this.sampler = sampler; - } - - @Override - public List extractData(ResultScanner results) throws Exception { - int rowNum = 0; - AgentStatSamplingHandler samplingHandler = new EagerSamplingHandler<>(timeWindow, sampler); - for (Result result : results) { - for (T dataPoint : this.rowMapper.mapRow(result, rowNum++)) { - samplingHandler.addDataPoint(dataPoint); - } - } - return samplingHandler.getSampledDataPoints(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledApplicationStatResultExtractor.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledApplicationStatResultExtractor.java deleted file mode 100644 index 91cb3352b6e2..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledApplicationStatResultExtractor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat; - -import com.navercorp.pinpoint.common.hbase.ResultsExtractor; -import com.navercorp.pinpoint.common.hbase.RowMapper; -import com.navercorp.pinpoint.common.server.bo.stat.join.JoinStatBo; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.ApplicationStatSampler; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.ApplicationStatSamplingHandler; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.join.EagerSamplingHandler; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.AggregationStatData; -import org.apache.hadoop.hbase.client.Result; -import org.apache.hadoop.hbase.client.ResultScanner; - -import java.util.List; - -/** - * @author minwoo.jung - */ -public class SampledApplicationStatResultExtractor - implements ResultsExtractor> { - - private final TimeWindow timeWindow; - private final RowMapper> rowMapper; - private final ApplicationStatSampler sampler; - - public SampledApplicationStatResultExtractor(TimeWindow timeWindow, RowMapper> rowMapper, ApplicationStatSampler sampler) { - if (timeWindow.getWindowRangeCount() > Integer.MAX_VALUE) { - throw new IllegalArgumentException("range yields too many timeslots"); - } - this.timeWindow = timeWindow; - this.rowMapper = rowMapper; - this.sampler = sampler; - } - - @Override - public List extractData(ResultScanner results) throws Exception { - int rowNum = 0; - ApplicationStatSamplingHandler samplingHandler = new EagerSamplingHandler<>(timeWindow, sampler); - for (Result result : results) { - for (IN dataPoint : this.rowMapper.mapRow(result, rowNum++)) { - samplingHandler.addDataPoint(dataPoint); - } - } - return samplingHandler.getSampledDataPoints(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledDataSourceResultExtractor.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledDataSourceResultExtractor.java deleted file mode 100644 index 52d6b162209e..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledDataSourceResultExtractor.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat; - -import com.navercorp.pinpoint.common.hbase.ResultsExtractor; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceBo; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceListBo; -import com.navercorp.pinpoint.web.mapper.stat.sampling.AgentStatSamplingHandler; -import com.navercorp.pinpoint.web.mapper.stat.sampling.EagerSamplingHandler; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.AgentStatSampler; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSource; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSourceList; -import org.apache.hadoop.hbase.client.Result; -import org.apache.hadoop.hbase.client.ResultScanner; -import org.springframework.util.CollectionUtils; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Taejin Koo - */ -public class SampledDataSourceResultExtractor implements ResultsExtractor> { - - private final TimeWindow timeWindow; - private final AgentStatMapper rowMapper; - private final AgentStatSampler sampler; - - public SampledDataSourceResultExtractor(TimeWindow timeWindow, AgentStatMapper rowMapper, AgentStatSampler sampler) { - if (timeWindow.getWindowRangeCount() > Integer.MAX_VALUE) { - throw new IllegalArgumentException("range yields too many timeslots"); - } - this.timeWindow = timeWindow; - this.rowMapper = rowMapper; - this.sampler = sampler; - } - - @Override - public List extractData(ResultScanner results) throws Exception { - // divide by dataSource id - Map> dataSourceBoListMap = divideByDataSourceId(results); - - List result = new ArrayList<>(dataSourceBoListMap.size()); - - for (List dataSourceBoList : dataSourceBoListMap.values()) { - result.add(getSampleData(dataSourceBoList)); - } - - return result; - } - - private Map> divideByDataSourceId(ResultScanner results) throws Exception { - int rowNum = 0; - Map> dataSourceBoListMap = new HashMap<>(); - for (Result result : results) { - for (DataSourceListBo dataPoint : this.rowMapper.mapRow(result, rowNum++)) { - if (dataPoint.size() == 0) { - continue; - } - DataSourceBo first = CollectionUtils.firstElement(dataPoint.getList()); - if(first != null) { - int id = first.getId(); - - List dataSourceBoList = dataSourceBoListMap.computeIfAbsent(id, k -> new ArrayList<>()); - - dataSourceBoList.addAll(dataPoint.getList()); - } - } - } - return dataSourceBoListMap; - } - - private SampledDataSourceList getSampleData(List dataSourceBoList) { - dataSourceBoList.sort(Comparator.comparingLong(DataSourceBo::getTimestamp).reversed()); - - AgentStatSamplingHandler samplingHandler = new EagerSamplingHandler<>(timeWindow, sampler); - for (DataSourceBo dataSourceBo : dataSourceBoList) { - samplingHandler.addDataPoint(dataSourceBo); - } - List sampledDataSources = samplingHandler.getSampledDataPoints(); - - SampledDataSourceList sampledDataSourceList = new SampledDataSourceList(); - for (SampledDataSource sampledDataSource : sampledDataSources) { - sampledDataSourceList.addSampledDataSource(sampledDataSource); - } - - return sampledDataSourceList; - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/AgentStatSamplingHandler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/AgentStatSamplingHandler.java deleted file mode 100644 index 3677fc180092..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/AgentStatSamplingHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling; - -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -public interface AgentStatSamplingHandler { - - void addDataPoint(T dataPoint); - - List getSampledDataPoints(); -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/EagerSamplingHandler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/EagerSamplingHandler.java deleted file mode 100644 index 171c8273afd0..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/EagerSamplingHandler.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling; - -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.AgentStatSampler; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; - -/** - * @author HyunGil Jeong - */ -public class EagerSamplingHandler implements AgentStatSamplingHandler { - - private final TimeWindow timeWindow; - private final AgentStatSampler sampler; - - private final Map samplingContexts = new HashMap<>(); - private final Map> sampledPointProjection = new TreeMap<>(); - - public EagerSamplingHandler(TimeWindow timeWindow, AgentStatSampler sampler) { - this.timeWindow = timeWindow; - this.sampler = sampler; - } - - public void addDataPoint(T dataPoint) { - long startTimestamp = dataPoint.getStartTimestamp(); - long timestamp = dataPoint.getTimestamp(); - long timeslotTimestamp = timeWindow.refineTimestamp(timestamp); - SamplingPartitionContext samplingContext = samplingContexts.get(startTimestamp); - if (samplingContext == null) { - samplingContext = new SamplingPartitionContext(timeslotTimestamp, dataPoint); - samplingContexts.put(startTimestamp, samplingContext); - } else { - long timeslotTimestampToSample = samplingContext.getTimeslotTimestamp(); - if (timeslotTimestampToSample == timeslotTimestamp) { - samplingContext.addDataPoint(dataPoint); - } else if (timeslotTimestampToSample > timeslotTimestamp){ - S sampledPoint = samplingContext.sampleDataPoints(dataPoint); - SortedMap sampledPoints = sampledPointProjection.computeIfAbsent(timeslotTimestampToSample, k -> new TreeMap<>()); - sampledPoints.put(startTimestamp, sampledPoint); - samplingContext = new SamplingPartitionContext(timeslotTimestamp, dataPoint); - samplingContexts.put(startTimestamp, samplingContext); - } else { - // Results should be sorted in a descending order of their actual timestamp values - // as they are stored using reverse timestamp. - throw new IllegalStateException("Out of order AgentStatDataPoint"); - } - } - } - - public List getSampledDataPoints() { - // sample remaining data point projections - for (Map.Entry e : samplingContexts.entrySet()) { - long startTimestamp = e.getKey(); - SamplingPartitionContext samplingPartitionContext = e.getValue(); - long timeslotTimestamp = samplingPartitionContext.getTimeslotTimestamp(); - S sampledDataPoint = samplingPartitionContext.sampleDataPoints(); - SortedMap reduceCandidates = sampledPointProjection.computeIfAbsent(timeslotTimestamp, k -> new TreeMap<>()); - reduceCandidates.put(startTimestamp, sampledDataPoint); - } - // reduce projection - if (sampledPointProjection.isEmpty()) { - return Collections.emptyList(); - } else { - List sampledDataPoints = new ArrayList<>(sampledPointProjection.size()); - for (SortedMap sampledPointCandidates : sampledPointProjection.values()) { - sampledDataPoints.add(reduceSampledPoints(sampledPointCandidates)); - } - return sampledDataPoints; - } - } - - private S reduceSampledPoints(SortedMap sampledPointCandidates) { - Long lastKey = sampledPointCandidates.lastKey(); - return sampledPointCandidates.get(lastKey); - } - - private class SamplingPartitionContext { - - private final int timeslotIndex; - private final long timeslotTimestamp; - private final List dataPoints = new ArrayList<>(); - - private SamplingPartitionContext(long timeslotTimestamp, T initialDataPoint) { - this.timeslotTimestamp = timeslotTimestamp; - this.dataPoints.add(initialDataPoint); - this.timeslotIndex = timeWindow.getWindowIndex(this.timeslotTimestamp); - } - - private void addDataPoint(T dataPoint) { - this.dataPoints.add(dataPoint); - } - - private long getTimeslotTimestamp() { - return timeslotTimestamp; - } - - private S sampleDataPoints() { - return sampleDataPoints(null); - } - - private S sampleDataPoints(T previousDataPoint) { - return sampler.sampleDataPoints(timeslotIndex, timeslotTimestamp, dataPoints, previousDataPoint); - } - - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/ActiveTraceSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/ActiveTraceSampler.java deleted file mode 100644 index 08e0126af657..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/ActiveTraceSampler.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; -import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceHistogram; -import com.navercorp.pinpoint.common.trace.BaseHistogramSchema; -import com.navercorp.pinpoint.common.trace.HistogramSchema; -import com.navercorp.pinpoint.common.trace.HistogramSlot; -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.TitledAgentStatPoint; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.math3.util.Precision; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.IntSummaryStatistics; -import java.util.List; -import java.util.function.ToIntFunction; - -/** - * @author HyunGil Jeong - */ -@Component -public class ActiveTraceSampler implements AgentStatSampler { - - @Override - public SampledActiveTrace sampleDataPoints(int timeWindowIndex, long timestamp, List dataPoints, ActiveTraceBo previousDataPoint) { - - final HistogramSchema schema = BaseHistogramSchema.getDefaultHistogramSchemaByTypeCode(dataPoints.get(0).getHistogramSchemaType()); - if (schema == null) { - return newUnSampledActiveTrace(timestamp); - } - - AgentStatPoint fast = newAgentStatPoint(schema.getFastSlot(), timestamp, dataPoints, ActiveTraceHistogram::getFastCount); - AgentStatPoint normal = newAgentStatPoint(schema.getNormalSlot(), timestamp, dataPoints, ActiveTraceHistogram::getNormalCount); - AgentStatPoint slow = newAgentStatPoint(schema.getSlowSlot(), timestamp, dataPoints, ActiveTraceHistogram::getSlowCount); - AgentStatPoint verySlow = newAgentStatPoint(schema.getVerySlowSlot(), timestamp, dataPoints, ActiveTraceHistogram::getVerySlowCount); - SampledActiveTrace sampledActiveTrace = new SampledActiveTrace(fast, normal, slow, verySlow); - - return sampledActiveTrace; - } - - private SampledActiveTrace newUnSampledActiveTrace(long timestamp) { - Point.UncollectedPointCreator> uncollected = SampledActiveTrace.UNCOLLECTED_POINT_CREATOR; - AgentStatPoint fast = uncollected.createUnCollectedPoint(timestamp); - AgentStatPoint normal = uncollected.createUnCollectedPoint(timestamp); - AgentStatPoint slow = uncollected.createUnCollectedPoint(timestamp); - AgentStatPoint verySlow = uncollected.createUnCollectedPoint(timestamp); - return new SampledActiveTrace(fast, normal, slow, verySlow); - } - - private AgentStatPoint newAgentStatPoint(HistogramSlot slot, long timestamp, List dataPoints, ToIntFunction counter) { - List fastCounts = filterActiveTraceBoList(dataPoints, counter); - return createSampledTitledPoint(slot.getSlotName(), timestamp, fastCounts); - } - - private List filterActiveTraceBoList(List dataPoints, ToIntFunction counter) { - final List result = new ArrayList<>(dataPoints.size()); - for (ActiveTraceBo activeTraceBo : dataPoints) { - final ActiveTraceHistogram activeTraceHistogram = activeTraceBo.getActiveTraceHistogram(); - final int count = counter.applyAsInt(activeTraceHistogram); - if (count != ActiveTraceBo.UNCOLLECTED_ACTIVE_TRACE_COUNT) { - result.add(count); - } - } - return result; - } - - private AgentStatPoint createSampledTitledPoint(String title, long timestamp, List values) { - if (CollectionUtils.isEmpty(values)) { - return SampledActiveTrace.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp); - } - IntSummaryStatistics stats = values.stream() - .mapToInt(Integer::intValue) - .summaryStatistics(); - double avg = Precision.round(stats.getAverage(), 1); - return new TitledAgentStatPoint<>( - title, - timestamp, - stats.getMin(), - stats.getMax(), - avg, - (int) stats.getSum()); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/AgentStatPointFactory.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/AgentStatPointFactory.java deleted file mode 100644 index 112845a6b31b..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/AgentStatPointFactory.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2020 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary; -import org.apache.commons.collections4.CollectionUtils; - -import java.util.List; - -/** - * @author Taejin Koo - */ -public class AgentStatPointFactory { - - private final Point.UncollectedPointCreator> uncollectedIntValuePointCreator; - private final Point.UncollectedPointCreator> uncollectedLongValuePointCreator; - private final Point.UncollectedPointCreator> uncollectedDoubleValuePointCreator; - - private final int defaultValueDecimal; - - public AgentStatPointFactory(int uncollectedIntValue, long uncollectedLongValue, double uncollectedDoubleValue) { - this(uncollectedIntValue, uncollectedLongValue, uncollectedDoubleValue, 0); - } - - public AgentStatPointFactory(int uncollectedIntValue, long uncollectedLongValue, double uncollectedDoubleValue, int defaultValueDecimal) { - this.uncollectedIntValuePointCreator = UncollectedPointCreatorFactory.createIntPointCreator(uncollectedIntValue); - this.uncollectedLongValuePointCreator = UncollectedPointCreatorFactory.createLongPointCreator(uncollectedLongValue); - this.uncollectedDoubleValuePointCreator = UncollectedPointCreatorFactory.createDoublePointCreator(uncollectedDoubleValue); - - this.defaultValueDecimal = defaultValueDecimal; - } - - public AgentStatPoint createIntPoint(long timestamp, List values) { - return createIntPoint(timestamp, values, defaultValueDecimal); - } - - public AgentStatPoint createIntPoint(long timestamp, List values, int numDecimals) { - if (CollectionUtils.isEmpty(values)) { - return uncollectedIntValuePointCreator.createUnCollectedPoint(timestamp); - } - return AgentStatPointSummary.intSummary(timestamp, values, numDecimals); - } - - public AgentStatPoint createLongPoint(long timestamp, List values) { - return createLongPoint(timestamp, values, defaultValueDecimal); - } - - public AgentStatPoint createLongPoint(long timestamp, List values, int numDecimals) { - if (CollectionUtils.isEmpty(values)) { - return uncollectedLongValuePointCreator.createUnCollectedPoint(timestamp); - } - return AgentStatPointSummary.longSummary(timestamp, values, numDecimals); - } - - public AgentStatPoint createDoublePoint(long timestamp, List values) { - return createDoublePoint(timestamp, values, defaultValueDecimal); - } - - public AgentStatPoint createDoublePoint(long timestamp, List values, int numDecimals) { - if (CollectionUtils.isEmpty(values)) { - return uncollectedDoubleValuePointCreator.createUnCollectedPoint(timestamp); - } - return AgentStatPointSummary.doubleSummary(timestamp, values, numDecimals); - } - - public Point.UncollectedPointCreator> getUncollectedIntValuePointCreator() { - return uncollectedIntValuePointCreator; - } - - public Point.UncollectedPointCreator> getUncollectedLongValuePointCreator() { - return uncollectedLongValuePointCreator; - } - - public Point.UncollectedPointCreator> getUncollectedDoubleValuePointCreator() { - return uncollectedDoubleValuePointCreator; - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/AgentStatSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/AgentStatSampler.java deleted file mode 100644 index f8e78618898b..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/AgentStatSampler.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -public interface AgentStatSampler { - - OUT sampleDataPoints(int index, long timestamp, List dataPoints, IN previousDataPoint); -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/ApplicationStatSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/ApplicationStatSampler.java deleted file mode 100644 index cf6e4e55f187..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/ApplicationStatSampler.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.stat.join.JoinStatBo; -import com.navercorp.pinpoint.web.vo.stat.AggregationStatData; - -import java.util.List; - -/** - * @author minwoo.jung - */ -public interface ApplicationStatSampler { - - OUT sampleDataPoints(int index, long timestamp, List dataPoints, IN previousDataPoint); - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/ApplicationStatSamplingHandler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/ApplicationStatSamplingHandler.java deleted file mode 100644 index ec6d4c278f96..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/ApplicationStatSamplingHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.stat.join.JoinStatBo; -import com.navercorp.pinpoint.web.vo.stat.AggregationStatData; - -import java.util.List; - -/** - * @author minwoo.jung - */ -public interface ApplicationStatSamplingHandler { - - void addDataPoint(IN dataPoint); - - List getSampledDataPoints(); -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/CpuLoadSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/CpuLoadSampler.java deleted file mode 100644 index f47f7202b8f7..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/CpuLoadSampler.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; -import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.ToDoubleFunction; - -/** - * @author HyunGil Jeong - */ -@Component -public class CpuLoadSampler implements AgentStatSampler { - - private static final int NUM_DECIMAL_PLACES = 1; - - @Override - public SampledCpuLoad sampleDataPoints(int timeWindowIndex, long timestamp, List dataPoints, CpuLoadBo previousDataPoint) { - final AgentStatPoint jvmCpuLoad = newAgentStatPoint(timestamp, dataPoints, CpuLoadBo::getJvmCpuLoad); - final AgentStatPoint systemCpuLoad = newAgentStatPoint(timestamp, dataPoints, CpuLoadBo::getSystemCpuLoad); - - SampledCpuLoad sampledCpuLoad = new SampledCpuLoad(jvmCpuLoad, systemCpuLoad); - return sampledCpuLoad; - } - - private AgentStatPoint newAgentStatPoint(long timestamp, List dataPoints, ToDoubleFunction filter) { - List jvmCpuLoads = filter(dataPoints, filter); - return createPoint(timestamp, jvmCpuLoads); - } - - private List filter(List dataPoints, ToDoubleFunction filter) { - final List result = new ArrayList<>(dataPoints.size()); - for (CpuLoadBo cpuLoadBo : dataPoints) { - final double apply = filter.applyAsDouble(cpuLoadBo); - if (apply != CpuLoadBo.UNCOLLECTED_VALUE) { - result.add(apply * 100); - } - } - return result; - } - - private AgentStatPoint createPoint(long timestamp, List values) { - if (CollectionUtils.isEmpty(values)) { - return SampledCpuLoad.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp); - } - return AgentStatPointSummary.doubleSummaryWithAllScale(timestamp, values, NUM_DECIMAL_PLACES); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/DataSourceSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/DataSourceSampler.java deleted file mode 100644 index fae30845ea84..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/DataSourceSampler.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceBo; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSource; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Taejin Koo - */ -@Component -public class DataSourceSampler implements AgentStatSampler { - - @Override - public SampledDataSource sampleDataPoints(int timeWindowIndex, long timestamp, List dataSourceBoList, DataSourceBo previousDataSourceBo) { - if (CollectionUtils.isEmpty(dataSourceBoList)) { - return null; - } - - final List activeConnectionSizes = new ArrayList<>(dataSourceBoList.size()); - final List maxConnectionSizes = new ArrayList<>(dataSourceBoList.size()); - - final DataSourceBo defaultDataSourceBo = dataSourceBoList.get(0); - final int id = defaultDataSourceBo.getId(); - final short serviceTypeCode = defaultDataSourceBo.getServiceTypeCode(); - String databaseName = defaultDataSourceBo.getDatabaseName(); - String jdbcUrl = defaultDataSourceBo.getJdbcUrl(); - for (DataSourceBo dataSourceBo : dataSourceBoList) { - - final int activeConnectionSize = dataSourceBo.getActiveConnectionSize(); - if (activeConnectionSize >= 0) { - activeConnectionSizes.add(activeConnectionSize); - } - - final int maxConnectionSize = dataSourceBo.getMaxConnectionSize(); - if (maxConnectionSize >= 0) { - maxConnectionSizes.add(maxConnectionSize); - } - - if (dataSourceBo.getId() != id) { - throw new IllegalArgumentException("id must be same"); - } - if (dataSourceBo.getServiceTypeCode() != serviceTypeCode) { - throw new IllegalArgumentException("serviceTypeCode must be same"); - } - - if (databaseName == null && dataSourceBo.getDatabaseName() != null) { - databaseName = dataSourceBo.getDatabaseName(); - } - - if (jdbcUrl == null && dataSourceBo.getJdbcUrl() != null) { - jdbcUrl = dataSourceBo.getJdbcUrl(); - } - } - - SampledDataSource sampledDataSource = new SampledDataSource(); - sampledDataSource.setId(id); - sampledDataSource.setServiceTypeCode(serviceTypeCode); - sampledDataSource.setDatabaseName(databaseName); - sampledDataSource.setJdbcUrl(jdbcUrl); - sampledDataSource.setActiveConnectionSize(createPoint(timestamp, activeConnectionSizes)); - sampledDataSource.setMaxConnectionSize(createPoint(timestamp, maxConnectionSizes)); - return sampledDataSource; - } - - private AgentStatPoint createPoint(long timestamp, List values) { - if (CollectionUtils.isEmpty(values)) { - return SampledDataSource.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp); - } - - return AgentStatPointSummary.intSummary(timestamp, values, 3); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/DeadlockSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/DeadlockSampler.java deleted file mode 100644 index 4a14f13a23f0..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/DeadlockSampler.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.stat.DeadlockThreadCountBo; -import com.navercorp.pinpoint.web.vo.stat.SampledDeadlock; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Taejin Koo - */ -@Component -public class DeadlockSampler implements AgentStatSampler { - - @Override - public SampledDeadlock sampleDataPoints(int index, long timestamp, List deadlockThreadCountBoList, DeadlockThreadCountBo previousDataPoint) { - List deadlockedThreadCountList = filter(deadlockThreadCountBoList); - - AgentStatPoint point = createPoint(timestamp, deadlockedThreadCountList); - SampledDeadlock sampledDeadlock = new SampledDeadlock(point); - - return sampledDeadlock; - } - - public List filter(List deadlockThreadCountBoList) { - List deadlockedThreadCountList = new ArrayList<>(deadlockThreadCountBoList.size()); - - for (DeadlockThreadCountBo deadlockThreadCountBo : deadlockThreadCountBoList) { - deadlockedThreadCountList.add(deadlockThreadCountBo.getDeadlockedThreadCount()); - } - return deadlockedThreadCountList; - } - - private AgentStatPoint createPoint(long timestamp, List values) { - if (CollectionUtils.isEmpty(values)) { - return SampledDeadlock.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp); - } - return AgentStatPointSummary.intSummary(timestamp, values); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/DirectBufferSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/DirectBufferSampler.java deleted file mode 100644 index 0d0403f74643..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/DirectBufferSampler.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.stat.DirectBufferBo; -import com.navercorp.pinpoint.web.vo.stat.SampledDirectBuffer; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.ToLongFunction; - -/** - * @author Roy Kim - */ -@Component -public class DirectBufferSampler implements AgentStatSampler { - - @Override - public SampledDirectBuffer sampleDataPoints(int timeWindowIndex, long timestamp, List dataPoints, DirectBufferBo previousDataPoint) { - final AgentStatPoint directCount = newAgentStatPoint(timestamp, dataPoints, DirectBufferBo::getDirectCount); - final AgentStatPoint directMemoryUsed = newAgentStatPoint(timestamp, dataPoints, DirectBufferBo::getDirectMemoryUsed); - final AgentStatPoint mappedCount = newAgentStatPoint(timestamp, dataPoints, DirectBufferBo::getMappedCount); - final AgentStatPoint mappedMemoryUsed = newAgentStatPoint(timestamp, dataPoints, DirectBufferBo::getMappedMemoryUsed); - - SampledDirectBuffer sampledDirectBuffer = new SampledDirectBuffer(directCount, directMemoryUsed, mappedCount, mappedMemoryUsed); - return sampledDirectBuffer; - } - - private AgentStatPoint newAgentStatPoint(long timestamp, List dataPoints, ToLongFunction filter) { - List directBuffers = filter(dataPoints, filter); - return createPoint(timestamp, directBuffers); - } - - private List filter(List dataPoints, ToLongFunction filter) { - final List result = new ArrayList<>(dataPoints.size()); - for (DirectBufferBo directBufferBo : dataPoints) { - final long apply = filter.applyAsLong(directBufferBo); - if (apply != DirectBufferBo.UNCOLLECTED_VALUE) { - result.add(apply); - } - } - return result; - } - - private AgentStatPoint createPoint(long timestamp, List values) { - if (CollectionUtils.isEmpty(values)) { - return SampledDirectBuffer.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp); - } - return AgentStatPointSummary.longSummary(timestamp, values); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/FileDescriptorSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/FileDescriptorSampler.java deleted file mode 100644 index 9fda2eb8723e..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/FileDescriptorSampler.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.stat.FileDescriptorBo; -import com.navercorp.pinpoint.web.vo.stat.SampledFileDescriptor; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.ToLongFunction; - -/** - * @author Roy Kim - */ -@Component -public class FileDescriptorSampler implements AgentStatSampler { - - - @Override - public SampledFileDescriptor sampleDataPoints(int timeWindowIndex, long timestamp, List dataPoints, FileDescriptorBo previousDataPoint) { - final AgentStatPoint openFileDescriptorCount = newAgentStatPoint(timestamp, dataPoints, FileDescriptorBo::getOpenFileDescriptorCount); - - SampledFileDescriptor sampledFileDescriptor = new SampledFileDescriptor(openFileDescriptorCount); - return sampledFileDescriptor; - } - - private AgentStatPoint newAgentStatPoint(long timestamp, List dataPoints, ToLongFunction filter) { - List fileDescriptors = filter(dataPoints, filter); - return createPoint(timestamp, fileDescriptors); - } - - private List filter(List dataPoints, ToLongFunction filter) { - final List result = new ArrayList<>(dataPoints.size()); - for (FileDescriptorBo fileDescriptorBo : dataPoints) { - final long apply = filter.applyAsLong(fileDescriptorBo); - if (apply != FileDescriptorBo.UNCOLLECTED_VALUE) { - result.add(apply); - } - } - return result; - } - - private AgentStatPoint createPoint(long timestamp, List values) { - if (values.isEmpty()) { - return SampledFileDescriptor.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp); - } - return AgentStatPointSummary.longSummary(timestamp, values); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/JvmGcDetailedSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/JvmGcDetailedSampler.java deleted file mode 100644 index 98c02a1e29b4..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/JvmGcDetailedSampler.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; -import com.navercorp.pinpoint.web.vo.stat.SampledJvmGcDetailed; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.ToDoubleFunction; -import java.util.function.ToLongFunction; - -/** - * @author HyunGil Jeong - */ -@Component -public class JvmGcDetailedSampler implements AgentStatSampler { - - private static final int NUM_DECIMAL_PLACES = 1; - - @Override - public SampledJvmGcDetailed sampleDataPoints(int timeWindowIndex, long timestamp, List dataPoints, JvmGcDetailedBo previousDataPoint) { - AgentStatPoint gcNewCounts = newLongPoint(timestamp, dataPoints, JvmGcDetailedBo::getGcNewCount); - AgentStatPoint gcNewTimes = newLongPoint(timestamp, dataPoints, JvmGcDetailedBo::getGcNewTime); - AgentStatPoint codeCacheUseds = newDoublePoint(timestamp, dataPoints, JvmGcDetailedBo::getCodeCacheUsed); - AgentStatPoint newGenUseds = newDoublePoint(timestamp, dataPoints, JvmGcDetailedBo::getNewGenUsed); - AgentStatPoint oldGenUseds = newDoublePoint(timestamp, dataPoints, JvmGcDetailedBo::getOldGenUsed); - AgentStatPoint survivorSpaceUseds = newDoublePoint(timestamp, dataPoints, JvmGcDetailedBo::getSurvivorSpaceUsed); - AgentStatPoint permGenUseds = newDoublePoint(timestamp, dataPoints, JvmGcDetailedBo::getPermGenUsed); - AgentStatPoint metaspaceUseds = newDoublePoint(timestamp, dataPoints, JvmGcDetailedBo::getMetaspaceUsed); - - SampledJvmGcDetailed sampledJvmGcDetailed = new SampledJvmGcDetailed(gcNewCounts, gcNewTimes, codeCacheUseds, newGenUseds, - oldGenUseds, survivorSpaceUseds, permGenUseds, metaspaceUseds); - return sampledJvmGcDetailed; - } - - private AgentStatPoint newLongPoint(long timestamp, List dataPoints, ToLongFunction filter) { - List filteredList = longFilter(dataPoints, filter); - return createLongPoint(timestamp, filteredList); - } - - private List longFilter(List dataPoints, ToLongFunction filter) { - final List result = new ArrayList<>(dataPoints.size()); - for (JvmGcDetailedBo jvmGcDetailedBo : dataPoints) { - final long apply = filter.applyAsLong(jvmGcDetailedBo); - if (apply != JvmGcDetailedBo.UNCOLLECTED_VALUE) { - result.add(apply); - } - } - return result; - } - - private AgentStatPoint newDoublePoint(long timestamp, List dataPoints, ToDoubleFunction filter) { - List filteredList = doubleFilter(dataPoints, filter); - return createDoublePoint(timestamp, filteredList); - } - - private List doubleFilter(List dataPoints, ToDoubleFunction filter) { - final List result = new ArrayList<>(dataPoints.size()); - for (JvmGcDetailedBo jvmGcDetailedBo : dataPoints) { - final double apply = filter.applyAsDouble(jvmGcDetailedBo); - if (apply != JvmGcDetailedBo.UNCOLLECTED_PERCENTAGE) { - final double percentage = apply * 100; - result.add(percentage); - } - } - return result; - } - - - private AgentStatPoint createLongPoint(long timestamp, List values) { - if (values.isEmpty()) { - return SampledJvmGcDetailed.UNCOLLECTED_VALUE_POINT_CREATOR.createUnCollectedPoint(timestamp); - } - return AgentStatPointSummary.longSummary(timestamp, values); - } - - private AgentStatPoint createDoublePoint(long timestamp, List values) { - if (CollectionUtils.isEmpty(values)) { - return SampledJvmGcDetailed.UNCOLLECTED_PERCENTAGE_POINT_CREATOR.createUnCollectedPoint(timestamp); - } - - return AgentStatPointSummary.doubleSummaryWithAllScale(timestamp, values, NUM_DECIMAL_PLACES); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/JvmGcSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/JvmGcSampler.java deleted file mode 100644 index bc37d7f191b5..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/JvmGcSampler.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.JvmGcType; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; -import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author HyunGil Jeong - */ -@Component -public class JvmGcSampler implements AgentStatSampler { - - @Override - public SampledJvmGc sampleDataPoints(int timeWindowIndex, long timestamp, List dataPoints, JvmGcBo previousDataPoint) { - JvmGcType jvmGcType = JvmGcType.UNKNOWN; - List heapUseds = new ArrayList<>(dataPoints.size()); - List heapMaxes = new ArrayList<>(dataPoints.size()); - List nonHeapUseds = new ArrayList<>(dataPoints.size()); - List nonHeapMaxes = new ArrayList<>(dataPoints.size()); - List gcOldCounts = new ArrayList<>(dataPoints.size()); - List gcOldTimes = new ArrayList<>(dataPoints.size()); - // dataPoints are in descending order - JvmGcBo previousBo = previousDataPoint; - for (int i = dataPoints.size() - 1; i >= 0; --i) { - JvmGcBo jvmGcBo = dataPoints.get(i); - jvmGcType = jvmGcBo.getGcType(); - if (jvmGcBo.getHeapUsed() != JvmGcBo.UNCOLLECTED_VALUE) { - heapUseds.add(jvmGcBo.getHeapUsed()); - } - if (jvmGcBo.getHeapMax() != JvmGcBo.UNCOLLECTED_VALUE) { - heapMaxes.add(jvmGcBo.getHeapMax()); - } - if (jvmGcBo.getNonHeapUsed() != JvmGcBo.UNCOLLECTED_VALUE) { - nonHeapUseds.add(jvmGcBo.getNonHeapUsed()); - } - if (jvmGcBo.getNonHeapMax() != JvmGcBo.UNCOLLECTED_VALUE) { - nonHeapMaxes.add(jvmGcBo.getNonHeapMax()); - } - - if (previousBo != null) { - // Technically, this should not be needed as data should already be partitioned by their agent start - // timestamp and should only contain data from a single jvm life cycle. - // Added to maintain backwards compatibility for data that do not have agent start timestamp. - if (checkJvmRestart(previousBo, jvmGcBo)) { - if (isGcCollected(jvmGcBo)) { - gcOldCounts.add(jvmGcBo.getGcOldCount()); - gcOldTimes.add(jvmGcBo.getGcOldTime()); - } else { - jvmGcBo.setGcOldCount(0L); - jvmGcBo.setGcOldTime(0L); - } - } else { - if (isGcCollected(jvmGcBo) && isGcCollected(previousBo)) { - gcOldCounts.add(jvmGcBo.getGcOldCount() - previousBo.getGcOldCount()); - gcOldTimes.add(jvmGcBo.getGcOldTime() - previousBo.getGcOldTime()); - } else { - if (!isGcCollected(jvmGcBo)) { - jvmGcBo.setGcOldCount(previousBo.getGcOldCount()); - jvmGcBo.setGcOldTime(previousBo.getGcOldTime()); - } - } - } - } else { - if (isGcCollected(jvmGcBo)) { - if (timeWindowIndex > 0) { - gcOldCounts.add(jvmGcBo.getGcOldCount()); - gcOldTimes.add(jvmGcBo.getGcOldTime()); - } else { - gcOldCounts.add(0L); - gcOldTimes.add(0L); - } - } - } - previousBo = jvmGcBo; - } - SampledJvmGc sampledJvmGc = new SampledJvmGc(); - sampledJvmGc.setJvmGcType(jvmGcType); - sampledJvmGc.setHeapUsed(createSampledPoint(timestamp, heapUseds)); - sampledJvmGc.setHeapMax(createSampledPoint(timestamp, heapMaxes)); - sampledJvmGc.setNonHeapUsed(createSampledPoint(timestamp, nonHeapUseds)); - sampledJvmGc.setNonHeapMax(createSampledPoint(timestamp, nonHeapMaxes)); - sampledJvmGc.setGcOldCount(createSampledPoint(timestamp, gcOldCounts)); - sampledJvmGc.setGcOldTime(createSampledPoint(timestamp, gcOldTimes)); - return sampledJvmGc; - } - - private boolean isGcCollected(JvmGcBo jvmGcBo) { - return jvmGcBo.getGcOldCount() != JvmGcBo.UNCOLLECTED_VALUE && jvmGcBo.getGcOldTime() != JvmGcBo.UNCOLLECTED_VALUE; - } - - private boolean checkJvmRestart(JvmGcBo previous, JvmGcBo current) { - if (previous.getStartTimestamp() > 0 && current.getStartTimestamp() > 0) { - return previous.getStartTimestamp() != current.getStartTimestamp(); - } else { - // if start timestamp is not serialzied - if (current.getGcOldTime() == JvmGcBo.UNCOLLECTED_VALUE || current.getGcOldCount() == JvmGcBo.UNCOLLECTED_VALUE) { - return false; - } else { - long countDelta = current.getGcOldCount() - previous.getGcOldCount(); - long timeDelta = current.getGcOldTime() - previous.getGcOldTime(); - return countDelta < 0 && timeDelta < 0; - } - } - } - - private AgentStatPoint createSampledPoint(long timestamp, List values) { - if (CollectionUtils.isEmpty(values)) { - return SampledJvmGc.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp); - } - return AgentStatPointSummary.longSummary(timestamp, values); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/LoadedClassSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/LoadedClassSampler.java deleted file mode 100644 index 19dfd4f7f7ef..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/LoadedClassSampler.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - - -import com.navercorp.pinpoint.common.server.bo.stat.LoadedClassBo; -import com.navercorp.pinpoint.web.vo.stat.SampledLoadedClassCount; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.ToLongFunction; - -@Component -public class LoadedClassSampler implements AgentStatSampler { - - @Override - public SampledLoadedClassCount sampleDataPoints(int timeWindowIndex, long timestamp, List dataPoints, LoadedClassBo previousDataPoint) { - final AgentStatPoint loadedClassCount = newAgentStatPoint(timestamp, dataPoints, LoadedClassBo::getLoadedClassCount); - final AgentStatPoint unloadedClassCount = newAgentStatPoint(timestamp, dataPoints, LoadedClassBo::getUnloadedClassCount); - - SampledLoadedClassCount sampledLoadedClassCount = new SampledLoadedClassCount(loadedClassCount, unloadedClassCount); - return sampledLoadedClassCount; - } - - private AgentStatPoint newAgentStatPoint(long timestamp, List dataPoints, ToLongFunction filter) { - List loadedCounts = filter(dataPoints, filter); - return createPoint(timestamp, loadedCounts); - } - - private List filter(List dataPoints, ToLongFunction filter) { - final List result = new ArrayList<>(dataPoints.size()); - for (LoadedClassBo loadedClassBo : dataPoints) { - final long apply = filter.applyAsLong(loadedClassBo); - if (apply != LoadedClassBo.UNCOLLECTED_VALUE) { - result.add(apply); - } - } - return result; - } - - private AgentStatPoint createPoint(long timestamp, List values) { - if (CollectionUtils.isEmpty(values)) { - return SampledLoadedClassCount.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp); - } - return AgentStatPointSummary.longSummary(timestamp, values); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/ResponseTimeSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/ResponseTimeSampler.java deleted file mode 100644 index 1f8534aff2e8..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/ResponseTimeSampler.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.stat.ResponseTimeBo; -import com.navercorp.pinpoint.web.vo.stat.SampledResponseTime; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Taejin Koo - */ -@Component -public class ResponseTimeSampler implements AgentStatSampler { - - @Override - public SampledResponseTime sampleDataPoints(int timeWindowIndex, long timestamp, List dataPoints, ResponseTimeBo previousDataPoint) { - List avgs = getAvg(dataPoints); - AgentStatPoint avg = createPoint(timestamp, avgs); - - List maxs = getMax(dataPoints); - AgentStatPoint max = createPoint(timestamp, maxs); - - SampledResponseTime sampledResponseTime = new SampledResponseTime(avg, max); - return sampledResponseTime; - } - - private List getAvg(List dataPoints) { - List avgs = new ArrayList<>(dataPoints.size()); - for (ResponseTimeBo responseTimeBo : dataPoints) { - avgs.add(responseTimeBo.getAvg()); - } - return avgs; - } - - private List getMax(List dataPoints) { - List maxs = new ArrayList<>(dataPoints.size()); - for (ResponseTimeBo responseTimeBo : dataPoints) { - maxs.add(responseTimeBo.getMax()); - } - return maxs; - } - - private AgentStatPoint createPoint(long timestamp, List values) { - if (CollectionUtils.isEmpty(values)) { - return SampledResponseTime.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp); - } - return AgentStatPointSummary.longSummary(timestamp, values); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/TotalThreadCountSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/TotalThreadCountSampler.java deleted file mode 100644 index 78d445bd4108..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/TotalThreadCountSampler.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2020 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.stat.TotalThreadCountBo; -import com.navercorp.pinpoint.web.vo.stat.SampledTotalThreadCount; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.ToLongFunction; - -@Component -public class TotalThreadCountSampler implements AgentStatSampler { - - @Override - public SampledTotalThreadCount sampleDataPoints(int index, long timestamp, List dataPoints, TotalThreadCountBo previousDataPoint) { - final AgentStatPoint totalThreadCount = newAgentStatPoint(timestamp, dataPoints, TotalThreadCountBo::getTotalThreadCount); - return new SampledTotalThreadCount(totalThreadCount); - } - - private AgentStatPoint newAgentStatPoint(long timestamp, List dataPoints, ToLongFunction filter) { - List totalThreadCounts = filter(dataPoints, filter); - return createPoint(timestamp, totalThreadCounts); - } - - private List filter(List dataPoints, ToLongFunction filter) { - final List result = new ArrayList<>(dataPoints.size()); - for (TotalThreadCountBo totalThreadCountBo : dataPoints) { - final long apply = filter.applyAsLong(totalThreadCountBo); - if (apply != TotalThreadCountBo.UNCOLLECTED_VALUE) { - result.add(apply); - } - } - return result; - } - - private AgentStatPoint createPoint(long timestamp, List values) { - if (CollectionUtils.isEmpty(values)) { - return SampledTotalThreadCount.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp); - } - return AgentStatPointSummary.longSummary(timestamp, values); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/TransactionSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/TransactionSampler.java deleted file mode 100644 index 78e7d10b600d..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/TransactionSampler.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler; - -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatUtils; -import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; -import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.ToLongFunction; - -/** - * @author HyunGil Jeong - */ -@Component -public class TransactionSampler implements AgentStatSampler { - - private static final int NUM_DECIMAL_PLACES = 1; - - @Override - public SampledTransaction sampleDataPoints(int timeWindowIndex, long timestamp, List dataPoints, TransactionBo previousDataPoint) { - - final AgentStatPoint sampledNew = newAgentStatPoint(timestamp, dataPoints, TransactionBo::getSampledNewCount); - final AgentStatPoint sampledContinuation = newAgentStatPoint(timestamp, dataPoints, TransactionBo::getSampledContinuationCount); - final AgentStatPoint unsampledNew = newAgentStatPoint(timestamp, dataPoints, TransactionBo::getUnsampledNewCount); - final AgentStatPoint unsampledContinuation = newAgentStatPoint(timestamp, dataPoints, TransactionBo::getUnsampledContinuationCount); - final AgentStatPoint skippedNew = newAgentStatPoint(timestamp, dataPoints, TransactionBo::getSkippedNewSkipCount); - final AgentStatPoint skippedContinuation = newAgentStatPoint(timestamp, dataPoints, TransactionBo::getSkippedContinuationCount); - - final List totals = calculateTotalTps(dataPoints); - AgentStatPoint total = createPoint(timestamp, totals); - - SampledTransaction sampledTransaction = new SampledTransaction(sampledNew, sampledContinuation, unsampledNew, unsampledContinuation, skippedNew, skippedContinuation, total); - return sampledTransaction; - } - - private AgentStatPoint newAgentStatPoint(long timestamp, List dataPoints, ToLongFunction function) { - final List sampledNews = calculateTps(dataPoints, function); - return createPoint(timestamp, sampledNews); - } - - private List calculateTotalTps(List dataPoints) { - final List result = new ArrayList<>(dataPoints.size()); - for (TransactionBo transactionBo : dataPoints) { - final Double total = getTotalTps(transactionBo); - if (total != null) { - result.add(total); - } - } - return result; - } - - private Double getTotalTps(TransactionBo transactionBo) { - final long collectInterval = transactionBo.getCollectInterval(); - if (collectInterval > 0) { - boolean isTransactionCollected = false; - long totalCount = 0; - final long sampledNewCount = transactionBo.getSampledNewCount(); - if (sampledNewCount != TransactionBo.UNCOLLECTED_VALUE) { - isTransactionCollected = true; - totalCount += sampledNewCount; - } - final long sampledContinuationCount = transactionBo.getSampledContinuationCount(); - if (sampledContinuationCount != TransactionBo.UNCOLLECTED_VALUE) { - isTransactionCollected = true; - totalCount += sampledContinuationCount; - } - final long unsampledNewCount = transactionBo.getUnsampledNewCount(); - if (unsampledNewCount != TransactionBo.UNCOLLECTED_VALUE) { - isTransactionCollected = true; - totalCount += unsampledNewCount; - } - final long unsampledContinuationCount = transactionBo.getUnsampledContinuationCount(); - if (unsampledContinuationCount != TransactionBo.UNCOLLECTED_VALUE) { - isTransactionCollected = true; - totalCount += unsampledContinuationCount; - } - final long skippedNewCount = transactionBo.getSkippedNewSkipCount(); - if (skippedNewCount != TransactionBo.UNCOLLECTED_VALUE) { - isTransactionCollected = true; - totalCount += skippedNewCount; - } - final long skippedContinuationCount = transactionBo.getSkippedContinuationCount(); - if (skippedContinuationCount != TransactionBo.UNCOLLECTED_VALUE) { - isTransactionCollected = true; - totalCount += skippedContinuationCount; - } - if (isTransactionCollected) { - return calculateTps(totalCount, collectInterval); - } - } - return null; - } - - private List calculateTps(List dataPoints, ToLongFunction function) { - final List result = new ArrayList<>(dataPoints.size()); - for (TransactionBo transactionBo : dataPoints) { - final long collectInterval = transactionBo.getCollectInterval(); - if (collectInterval > 0) { - final long count = function.applyAsLong(transactionBo); - if (count != TransactionBo.UNCOLLECTED_VALUE) { - final double tps = calculateTps(count, collectInterval); - result.add(tps); - } - } - } - return result; - } - - private double calculateTps(long count, long intervalMs) { - return AgentStatUtils.calculateRate(count, intervalMs, NUM_DECIMAL_PLACES, SampledTransaction.UNCOLLECTED_VALUE); - } - - private AgentStatPoint createPoint(long timestamp, List values) { - if (CollectionUtils.isEmpty(values)) { - return SampledTransaction.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp); - } - return AgentStatPointSummary.doubleSummaryWithAllScale(timestamp, values, NUM_DECIMAL_PLACES); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/join/EagerSamplingHandler.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/join/EagerSamplingHandler.java deleted file mode 100644 index 7869d24af2bf..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/sampling/sampler/join/EagerSamplingHandler.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat.sampling.sampler.join; - -import com.navercorp.pinpoint.common.server.bo.stat.join.JoinStatBo; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.ApplicationStatSampler; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.ApplicationStatSamplingHandler; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.AggregationStatData; - -import java.util.*; - -/** - * @author minwoo.jung - */ -public class EagerSamplingHandler implements ApplicationStatSamplingHandler { - - private final TimeWindow timeWindow; - private final ApplicationStatSampler sampler; - - private final Map> samplingContexts = new HashMap<>(); - private final Map> sampledPointProjection = new TreeMap<>(); - - public EagerSamplingHandler(TimeWindow timeWindow, ApplicationStatSampler sampler) { - this.timeWindow = timeWindow; - this.sampler = sampler; - } - - public void addDataPoint(IN dataPoint) { - String id = dataPoint.getId(); - long timestamp = dataPoint.getTimestamp(); - long timeslotTimestamp = timeWindow.refineTimestamp(timestamp); - SamplingPartitionContext samplingContext = samplingContexts.get(id); - if (samplingContext == null) { - samplingContext = new SamplingPartitionContext<>(timeslotTimestamp, dataPoint, timeWindow, sampler); - samplingContexts.put(id, samplingContext); - } else { - long timeslotTimestampToSample = samplingContext.getTimeslotTimestamp(); - if (timeslotTimestampToSample == timeslotTimestamp) { - samplingContext.addDataPoint(dataPoint); - } else if (timeslotTimestampToSample > timeslotTimestamp) { - OUT sampledPoint = samplingContext.sampleDataPoints(dataPoint); - SortedMap sampledPoints = sampledPointProjection.computeIfAbsent(timeslotTimestampToSample, k -> new TreeMap<>()); - sampledPoints.put(id, sampledPoint); - samplingContext = new SamplingPartitionContext<>(timeslotTimestamp, dataPoint, timeWindow, sampler); - samplingContexts.put(id, samplingContext); - } else { - // Results should be sorted in a descending order of their actual timestamp values - // as they are stored using reverse timestamp. - throw new IllegalStateException("Out of order AgentStatDataPoint"); - } - } - } - - public List getSampledDataPoints() { - // sample remaining data point projections - for (Map.Entry> e : samplingContexts.entrySet()) { - String id = e.getKey(); - SamplingPartitionContext samplingPartitionContext = e.getValue(); - long timeslotTimestamp = samplingPartitionContext.getTimeslotTimestamp(); - OUT sampledDataPoint = samplingPartitionContext.sampleDataPoints(); - SortedMap reduceCandidates = sampledPointProjection.computeIfAbsent(timeslotTimestamp, k -> new TreeMap<>()); - reduceCandidates.put(id, sampledDataPoint); - } - // reduce projection - if (sampledPointProjection.isEmpty()) { - return Collections.emptyList(); - } else { - List sampledDataPoints = new ArrayList<>(sampledPointProjection.size()); - for (SortedMap sampledPointCandidates : sampledPointProjection.values()) { - sampledDataPoints.add(reduceSampledPoints(sampledPointCandidates)); - } - return sampledDataPoints; - } - } - - private OUT reduceSampledPoints(SortedMap sampledPointCandidates) { - String lastKey = sampledPointCandidates.lastKey(); - return sampledPointCandidates.get(lastKey); - } - - private static class SamplingPartitionContext { - - private final int timeslotIndex; - private final long timeslotTimestamp; - private final List dataPoints = new ArrayList<>(); - private final ApplicationStatSampler sampler; - - private SamplingPartitionContext(long timeslotTimestamp, IN initialDataPoint, - TimeWindow timeWindow, ApplicationStatSampler sampler) { - this.timeslotTimestamp = timeslotTimestamp; - this.dataPoints.add(initialDataPoint); - this.timeslotIndex = timeWindow.getWindowIndex(this.timeslotTimestamp); - this.sampler = sampler; - } - - private void addDataPoint(IN dataPoint) { - this.dataPoints.add(dataPoint); - } - - private long getTimeslotTimestamp() { - return timeslotTimestamp; - } - - private OUT sampleDataPoints() { - return sampleDataPoints(null); - } - - private OUT sampleDataPoints(IN previousDataPoint) { - return sampler.sampleDataPoints(timeslotIndex, timeslotTimestamp, dataPoints, previousDataPoint); - } - - } -} \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationAgentListServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationAgentListServiceImpl.java index 0ce20e31eb40..5ca08472e91a 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationAgentListServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/ApplicationAgentListServiceImpl.java @@ -115,10 +115,6 @@ private boolean isActiveAgentPredicate(AgentAndStatus agentAndStatus, AgentStatu if (agentStatusFilter.test(agentAndStatus.getStatus())) { return true; } - final AgentInfo agentInfo = agentAndStatus.getAgentInfo(); - if (legacyAgentCompatibility.isLegacyAgent(agentInfo.getServiceTypeCode(), agentInfo.getAgentVersion())) { - return legacyAgentCompatibility.isActiveAgent(agentInfo.getAgentId(), range); - } return false; } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/component/DefaultActiveAgentValidator.java b/web/src/main/java/com/navercorp/pinpoint/web/service/component/DefaultActiveAgentValidator.java index 7d647d3738b7..d19d5451a5b1 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/component/DefaultActiveAgentValidator.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/component/DefaultActiveAgentValidator.java @@ -27,10 +27,12 @@ public DefaultActiveAgentValidator(AgentEventService agentEventService, LegacyAg @Override public boolean isActiveAgent(String agentId, Range range) { Objects.requireNonNull(agentId, "agentId"); + if (isActiveAgentByEvent(agentId, range)) { return true; } - return agentCompatibility.isActiveAgent(agentId, range); + + return false; } @Override @@ -48,12 +50,8 @@ public boolean isActiveAgent(Application agent, String version, Range range) { if (isActiveAgentByEvent(agentId, range)) { return true; } - } else { - logger.trace("agentCompatibility.isActiveAgent"); - if (agentCompatibility.isActiveAgent(agentId, range)) { - return true; - } } + return false; } @@ -64,6 +62,7 @@ public boolean isActiveAgent(Application agent, String version, List rang return true; } } + return false; } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/component/DefaultLegacyAgentCompatibility.java b/web/src/main/java/com/navercorp/pinpoint/web/service/component/DefaultLegacyAgentCompatibility.java index 0b30cce535ad..6127cb9ce277 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/component/DefaultLegacyAgentCompatibility.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/component/DefaultLegacyAgentCompatibility.java @@ -1,11 +1,8 @@ package com.navercorp.pinpoint.web.service.component; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; import java.util.List; -import java.util.Objects; public class DefaultLegacyAgentCompatibility implements LegacyAgentCompatibility { @@ -15,12 +12,6 @@ public class DefaultLegacyAgentCompatibility implements LegacyAgentCompatibility new LegacyAgent(List.of((short)1400, (short)1401), "0.8.0"), }; - private final AgentStatDao jvmGcDao; - - public DefaultLegacyAgentCompatibility(AgentStatDao jvmGcDao) { - this.jvmGcDao = Objects.requireNonNull(jvmGcDao, "jvmGcDao"); - } - @Override public boolean isLegacyAgent(short serviceType) { return isLegacyAgent(serviceType, null); @@ -38,21 +29,4 @@ public boolean isLegacyAgent(short serviceType, String version) { } return true; } - -// @Override -// public boolean isActiveAgent(Application agent, String version, Range range) { -// if (!isLegacyAgent(agent.getServiceTypeCode(), version)) { -// return false; -// } -// if (isActiveAgent(agent.getName(), range)) { -// return true; -// } -// return false; -// } - - @Override - public boolean isActiveAgent(String agentId, Range range) { - return this.jvmGcDao.agentStatExists(agentId, range); - } - } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/component/DisableAgentCompatibility.java b/web/src/main/java/com/navercorp/pinpoint/web/service/component/DisableAgentCompatibility.java index 2ce241a5fc8c..e5517959c2e4 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/component/DisableAgentCompatibility.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/component/DisableAgentCompatibility.java @@ -12,9 +12,4 @@ public boolean isLegacyAgent(short serviceType) { public boolean isLegacyAgent(short serviceType, String version) { return false; } - - @Override - public boolean isActiveAgent(String agentId, Range range) { - return false; - } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/component/LegacyAgentCompatibility.java b/web/src/main/java/com/navercorp/pinpoint/web/service/component/LegacyAgentCompatibility.java index cdc6863e4d2b..5ab95b630509 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/component/LegacyAgentCompatibility.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/component/LegacyAgentCompatibility.java @@ -6,8 +6,4 @@ public interface LegacyAgentCompatibility { boolean isLegacyAgent(short serviceType); boolean isLegacyAgent(short serviceType, String version); - -// boolean isActiveAgent(Application agent, String version, Range range); - - boolean isActiveAgent(String agentId, Range range); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/component/LegacySupportConfiguration.java b/web/src/main/java/com/navercorp/pinpoint/web/service/component/LegacySupportConfiguration.java index 2935b087a33d..91e87936c6fb 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/component/LegacySupportConfiguration.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/component/LegacySupportConfiguration.java @@ -1,7 +1,5 @@ package com.navercorp.pinpoint.web.service.component; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -9,11 +7,10 @@ @Configuration public class LegacySupportConfiguration { @Bean - public LegacyAgentCompatibility legacyAgentCompatibility(AgentStatDao jvmGcDao, - @Value("${pinpoint.web.agent-status.legacy-agent-support:true}") + public LegacyAgentCompatibility legacyAgentCompatibility(@Value("${pinpoint.web.agent-status.legacy-agent-support:true}") boolean legacyAgentSupport) { if (legacyAgentSupport) { - return new DefaultLegacyAgentCompatibility(jvmGcDao); + return new DefaultLegacyAgentCompatibility(); } return new DisableAgentCompatibility(); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatChartService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatChartService.java deleted file mode 100644 index 2cecd1180414..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatChartService.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2016 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.web.service.stat; - -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChart; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -public interface AgentStatChartService> extends ChartTypeSupport { - - OUT selectAgentChart(String agentId, TimeWindow timeWindow); - - List selectAgentChartList(String agentId, TimeWindow timeWindow); - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatService.java deleted file mode 100644 index e98dc54fa70c..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatService.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2016 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.web.service.stat; - -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.util.time.Range; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ - -public interface AgentStatService extends ChartTypeSupport { - List selectAgentStatList(String agentId, Range range); -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatServiceConfiguration.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatServiceConfiguration.java deleted file mode 100644 index 108fd099988f..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatServiceConfiguration.java +++ /dev/null @@ -1,192 +0,0 @@ -package com.navercorp.pinpoint.web.service.stat; - -import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -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.DeadlockThreadCountBo; -import com.navercorp.pinpoint.common.server.bo.stat.DirectBufferBo; -import com.navercorp.pinpoint.common.server.bo.stat.FileDescriptorBo; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; -import com.navercorp.pinpoint.common.server.bo.stat.LoadedClassBo; -import com.navercorp.pinpoint.common.server.bo.stat.ResponseTimeBo; -import com.navercorp.pinpoint.common.server.bo.stat.TotalThreadCountBo; -import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; -import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; -import com.navercorp.pinpoint.web.dao.SampledAgentStatDao; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; -import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; -import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSourceList; -import com.navercorp.pinpoint.web.vo.stat.SampledDeadlock; -import com.navercorp.pinpoint.web.vo.stat.SampledDirectBuffer; -import com.navercorp.pinpoint.web.vo.stat.SampledFileDescriptor; -import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; -import com.navercorp.pinpoint.web.vo.stat.SampledJvmGcDetailed; -import com.navercorp.pinpoint.web.vo.stat.SampledLoadedClassCount; -import com.navercorp.pinpoint.web.vo.stat.SampledResponseTime; -import com.navercorp.pinpoint.web.vo.stat.SampledTotalThreadCount; -import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.ActiveTraceChart; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.CpuLoadChart; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.DataSourceChart; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.DeadlockChart; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.DirectBufferChart; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.FileDescriptorChart; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.JvmGcChart; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.JvmGcDetailedChart; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.LoadedClassCountChart; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.ResponseTimeChart; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.TotalThreadCountChart; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.TransactionChart; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class AgentStatServiceConfiguration { - - @Bean - public AgentStatChartService getActiveTraceChartService(SampledAgentStatDao statDao) { - return new DefaultAgentStatChartService<>(statDao, ActiveTraceChart::new); - } - - @Bean - public AgentStatService getActiveTraceService(AgentStatDao statDao) { - return new DefaultStatService<>(statDao); - } - - //----------------- - - @Bean - public AgentStatChartService getCpuLoadChartService(SampledAgentStatDao statDao) { - return new DefaultAgentStatChartService<>(statDao, CpuLoadChart::new); - } - - @Bean() - public AgentStatService getCpuLoadService(AgentStatDao statDao) { - return new DefaultStatService<>(statDao); - } - - //----------------------- - - @Bean - public AgentStatChartService getDeadlockChartService(SampledAgentStatDao statDao) { - return new DefaultAgentStatChartService<>(statDao, DeadlockChart::new); - } - - @Bean - public AgentStatService getDeadlockService(AgentStatDao statDao) { - return new DefaultStatService<>(statDao); - } - - //----------------------- - - @Bean - public AgentStatChartService getDirectBufferChartService(SampledAgentStatDao statDao) { - return new DefaultAgentStatChartService<>(statDao, DirectBufferChart::new); - } - - @Bean - public AgentStatService getDirectBufferService(AgentStatDao statDao) { - return new DefaultStatService<>(statDao); - } - - //----------------------- - - @Bean - public AgentStatChartService getFileDescriptorChartService(SampledAgentStatDao statDao) { - return new DefaultAgentStatChartService<>(statDao, FileDescriptorChart::new); - } - - @Bean - public AgentStatService getFileDescriptorService(AgentStatDao statDao) { - return new DefaultStatService<>(statDao); - } - - //----------------------- - - @Bean - public AgentStatChartService getJvmGcChartService(SampledAgentStatDao statDao) { - return new DefaultAgentStatChartService<>(statDao, JvmGcChart::new); - } - - @Bean - public AgentStatService getJvmGcService(AgentStatDao statDao) { - return new DefaultStatService<>(statDao); - } - - //----------------------- - - @Bean - public AgentStatChartService getJvmGcDetailedChartService(SampledAgentStatDao statDao) { - return new DefaultAgentStatChartService<>(statDao, JvmGcDetailedChart::new); - } - - @Bean - public AgentStatService getJvmGcDetailedService(AgentStatDao statDao) { - return new DefaultStatService<>(statDao); - } - - //----------------------- - - @Bean - public AgentStatChartService getLoadedClassCountChartService(SampledAgentStatDao statDao) { - return new DefaultAgentStatChartService<>(statDao, LoadedClassCountChart::new); - } - - @Bean - public AgentStatService getLoadedClassCountService(AgentStatDao statDao) { - return new DefaultStatService<>(statDao); - } - - - //----------------------- - - @Bean - public AgentStatChartService getResponseTimeChartService(SampledAgentStatDao statDao) { - return new DefaultAgentStatChartService<>(statDao, ResponseTimeChart::new); - } - - @Bean - public AgentStatService getResponseTimeService(AgentStatDao statDao) { - return new DefaultStatService<>(statDao); - } - - //----------------------- - - @Bean - public AgentStatChartService getTotalThreadCountChartService(SampledAgentStatDao statDao) { - return new DefaultAgentStatChartService<>(statDao, TotalThreadCountChart::new); - } - - @Bean - public AgentStatService getTotalThreadCountService(AgentStatDao statDao) { - return new DefaultStatService<>(statDao); - } - - //----------------------- - -// @Bean - public AgentStatChartService getDataSourceChartService(SampledAgentStatDao statDao, - ServiceTypeRegistryService registry) { - return new DataSourceChartService(statDao, registry); - } - - @Bean - public AgentStatService getDataSourceService(AgentStatDao statDao) { - return new DefaultStatService<>(statDao); - } - - //----------------------- - - @Bean - public AgentStatChartService getTransactionChartService(SampledAgentStatDao statDao) { - return new DefaultAgentStatChartService<>(statDao, TransactionChart::new); - } - - @Bean - public AgentStatService getTransactionService(AgentStatDao statDao) { - return new DefaultStatService<>(statDao); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/ChartTypeSupport.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/ChartTypeSupport.java deleted file mode 100644 index 79381364ee68..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/ChartTypeSupport.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.navercorp.pinpoint.web.service.stat; - -public interface ChartTypeSupport { - String getChartType(); -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/DataSourceChartService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/DataSourceChartService.java deleted file mode 100644 index d98e396ad4ed..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/DataSourceChartService.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2017 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.web.service.stat; - -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; -import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; -import com.navercorp.pinpoint.web.dao.SampledAgentStatDao; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSource; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSourceList; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.DataSourceChart; -import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -/** - * @author Taejin Koo - */ -@Service -public class DataSourceChartService implements AgentStatChartService { - - private final SampledAgentStatDao sampledDataSourceDao; - private final ServiceTypeRegistryService serviceTypeRegistryService; - - public DataSourceChartService(SampledAgentStatDao sampledDataSourceDao, - ServiceTypeRegistryService serviceTypeRegistryService) { - this.sampledDataSourceDao = Objects.requireNonNull(sampledDataSourceDao, "sampledDataSourceDao"); - this.serviceTypeRegistryService = Objects.requireNonNull(serviceTypeRegistryService, "serviceTypeRegistryService"); - } - - @Override - public DataSourceChart selectAgentChart(String agentId, TimeWindow timeWindow) { - Objects.requireNonNull(agentId, "agentId"); - Objects.requireNonNull(timeWindow, "timeWindow"); - - final List sampledAgentStatList = this.sampledDataSourceDao.getSampledAgentStatList(agentId, timeWindow); - if (Boolean.FALSE == CollectionUtils.isEmpty(sampledAgentStatList)) { - final SampledDataSourceList sampledDataSourceList = CollectionUtils.firstElement(sampledAgentStatList); - if (sampledDataSourceList != null) { - final List list = sampledDataSourceList.getSampledDataSourceList(); - return new DataSourceChart(timeWindow, list, serviceTypeRegistryService); - } - } - return new DataSourceChart(timeWindow, Collections.emptyList(), serviceTypeRegistryService); - } - - @Override - public List selectAgentChartList(String agentId, TimeWindow timeWindow) { - Objects.requireNonNull(agentId, "agentId"); - Objects.requireNonNull(timeWindow, "timeWindow"); - - List sampledAgentStatList = this.sampledDataSourceDao.getSampledAgentStatList(agentId, timeWindow); - if (CollectionUtils.isEmpty(sampledAgentStatList)) { - List result = new ArrayList<>(1); - result.add(new DataSourceChart(timeWindow, Collections.emptyList(), serviceTypeRegistryService)); - return result; - } else { - List result = new ArrayList<>(sampledAgentStatList.size()); - for (SampledDataSourceList sampledDataSourceList : sampledAgentStatList) { - result.add(new DataSourceChart(timeWindow, sampledDataSourceList.getSampledDataSourceList(), serviceTypeRegistryService)); - } - return result; - } - } - - @Override - public String getChartType() { - return AgentStatType.DATASOURCE.getChartType(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/DefaultAgentStatChartService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/DefaultAgentStatChartService.java deleted file mode 100644 index d4ec575a7f16..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/DefaultAgentStatChartService.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2016 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.web.service.stat; - -import com.navercorp.pinpoint.web.dao.SampledAgentStatDao; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChart; - -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -//@Service -public class DefaultAgentStatChartService> implements AgentStatChartService { - - private final SampledAgentStatDao statDao; - private final SampledChartFunction chartFunction; - - public DefaultAgentStatChartService(SampledAgentStatDao statDao, SampledChartFunction chartFunction) { - this.statDao = Objects.requireNonNull(statDao, "sampledActiveTraceDao"); - this.chartFunction = Objects.requireNonNull(chartFunction, "chartFunction"); - } - - @Override - public OUT selectAgentChart(String agentId, TimeWindow timeWindow) { - Objects.requireNonNull(agentId, "agentId"); - Objects.requireNonNull(timeWindow, "timeWindow"); - List dataPoint = this.statDao.getSampledAgentStatList(agentId, timeWindow); - return chartFunction.apply(timeWindow, dataPoint); - } - - @Override - public List selectAgentChartList(String agentId, TimeWindow timeWindow) { - OUT agentStatChart = selectAgentChart(agentId, timeWindow); - return Collections.singletonList(agentStatChart); - } - - @Override - public String getChartType() { - return statDao.getChartType(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/DefaultStatService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/DefaultStatService.java deleted file mode 100644 index fec4dcdc3ab6..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/DefaultStatService.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2016 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.web.service.stat; - -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; - -import java.util.List; -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -public class DefaultStatService implements AgentStatService { - - private final AgentStatDao statDao; - - public DefaultStatService(AgentStatDao statDao) { - this.statDao = Objects.requireNonNull(statDao, "activeTraceDao"); - } - - @Override - public List selectAgentStatList(String agentId, Range range) { - Objects.requireNonNull(agentId, "agentId"); - Objects.requireNonNull(range, "range"); - - return this.statDao.getAgentStatList(agentId, range); - } - - @Override - public String getChartType() { - return this.statDao.getChartType(); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/SampledChartFunction.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/SampledChartFunction.java deleted file mode 100644 index a9fa5f4aefae..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/SampledChartFunction.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.navercorp.pinpoint.web.service.stat; - -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChart; - -import java.util.List; - -@FunctionalInterface -public interface SampledChartFunction { - OUT apply(TimeWindow timeWindow, List applicationStatList); -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/view/DoubleApplicationStatSerializer.java b/web/src/main/java/com/navercorp/pinpoint/web/view/DoubleApplicationStatSerializer.java index e0c98672bbcc..438478197869 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/view/DoubleApplicationStatSerializer.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/view/DoubleApplicationStatSerializer.java @@ -27,6 +27,7 @@ /** * @author Taejin Koo */ +@Deprecated public class DoubleApplicationStatSerializer extends JsonSerializer { @Override diff --git a/web/src/main/java/com/navercorp/pinpoint/web/view/StatChartGroupSerializer.java b/web/src/main/java/com/navercorp/pinpoint/web/view/StatChartGroupSerializer.java deleted file mode 100644 index 1060664fc70f..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/view/StatChartGroupSerializer.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2017 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.web.view; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.chart.Chart; -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * @author HyunGil Jeong - */ -public class StatChartGroupSerializer extends JsonSerializer { - - @Override - public void serialize(StatChartGroup statChartGroup, JsonGenerator jgen, SerializerProvider serializers) throws IOException { - jgen.writeStartObject(); - Map> charts = statChartGroup.getCharts(); - writeSchema(jgen, charts.keySet()); - - TimeWindow timeWindow = statChartGroup.getTimeWindow(); - writeTimestamp(jgen, timeWindow); - - writeCharts(jgen, charts); - jgen.writeEndObject(); - } - - private void writeSchema(JsonGenerator jgen, Set chartTypes) throws IOException { - jgen.writeFieldName("schema"); - jgen.writeStartObject(); - jgen.writeStringField("x", "time"); - for (StatChartGroup.ChartType chartType : chartTypes) { - jgen.writeObjectField(chartType.toString(), chartType.getSchema()); - } - - jgen.writeEndObject(); - } - - private void writeTimestamp(JsonGenerator jgen, TimeWindow timeWindow) throws IOException { - List timestamps = new ArrayList<>((int) timeWindow.getWindowRangeCount()); - for (Long timestamp : timeWindow) { - timestamps.add(timestamp); - } - jgen.writeObjectField("x", timestamps); - } - - private void writeCharts(JsonGenerator jgen, Map> charts) throws IOException { - jgen.writeFieldName("y"); - jgen.writeStartObject(); - for (Map.Entry> e : charts.entrySet()) { - StatChartGroup.ChartType chartType = e.getKey(); - Chart chart = e.getValue(); - List points = chart.getPoints(); - jgen.writeObjectField(chartType.toString(), points); - } - jgen.writeEndObject(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/view/TitledAgentStatPointSerializer.java b/web/src/main/java/com/navercorp/pinpoint/web/view/TitledAgentStatPointSerializer.java deleted file mode 100644 index 5c2873caa1cb..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/view/TitledAgentStatPointSerializer.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2017 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.web.view; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.TitledAgentStatPoint; - -import java.io.IOException; - -/** - * @author HyunGil Jeong - */ -public class TitledAgentStatPointSerializer extends JsonSerializer> { - - @Override - public void serialize(TitledAgentStatPoint titledAgentStatPoint, JsonGenerator jgen, SerializerProvider serializers) throws IOException { - jgen.writeStartArray(); - jgen.writeObject(titledAgentStatPoint.getMinYVal()); - jgen.writeObject(titledAgentStatPoint.getMaxYVal()); - jgen.writeObject(titledAgentStatPoint.getAvgYVal()); - jgen.writeObject(titledAgentStatPoint.getSumYVal()); - jgen.writeObject(titledAgentStatPoint.getTitle()); - jgen.writeEndArray(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/AggregationStatData.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/AggregationStatData.java deleted file mode 100644 index c650aa29fa6f..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/AggregationStatData.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat; - -/** - * @author minwoo.jung - */ -public interface AggregationStatData { -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/JvmGc.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/JvmGc.java deleted file mode 100644 index 8b0ba10d43a3..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/JvmGc.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2016 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.web.vo.stat; - -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -public class JvmGc { - - private final String agentId; - private final long timestamp; - - private long heapUsed; - private long heapMax; - private long nonHeapUsed; - private long nonHeapMax; - private long gcOldCount; - private long gcOldTime; - - public JvmGc(String agentId, long timestamp) { - this.agentId = Objects.requireNonNull(agentId, "agentId"); - this.timestamp = timestamp; - } - - public String getAgentId() { - return agentId; - } - - public long getTimestamp() { - return timestamp; - } - - public long getHeapUsed() { - return heapUsed; - } - - public void setHeapUsed(long heapUsed) { - this.heapUsed = heapUsed; - } - - public long getHeapMax() { - return heapMax; - } - - public void setHeapMax(long heapMax) { - this.heapMax = heapMax; - } - - public long getNonHeapUsed() { - return nonHeapUsed; - } - - public void setNonHeapUsed(long nonHeapUsed) { - this.nonHeapUsed = nonHeapUsed; - } - - public long getNonHeapMax() { - return nonHeapMax; - } - - public void setNonHeapMax(long nonHeapMax) { - this.nonHeapMax = nonHeapMax; - } - - public long getGcOldCount() { - return gcOldCount; - } - - public void setGcOldCount(long gcOldCount) { - this.gcOldCount = gcOldCount; - } - - public long getGcOldTime() { - return gcOldTime; - } - - public void setGcOldTime(long gcOldTime) { - this.gcOldTime = gcOldTime; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - JvmGc jvmGc = (JvmGc) o; - - if (timestamp != jvmGc.timestamp) return false; - return agentId.equals(jvmGc.agentId); - - } - - @Override - public int hashCode() { - int result = agentId.hashCode(); - result = 31 * result + (int) (timestamp ^ (timestamp >>> 32)); - return result; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("JvmGc{"); - sb.append("agentId='").append(agentId).append('\''); - sb.append(", timestamp=").append(timestamp); - sb.append(", heapUsed=").append(heapUsed); - sb.append(", heapMax=").append(heapMax); - sb.append(", nonHeapUsed=").append(nonHeapUsed); - sb.append(", nonHeapMax=").append(nonHeapMax); - sb.append(", gcOldCount=").append(gcOldCount); - sb.append(", gcOldTime=").append(gcOldTime); - sb.append('}'); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledActiveTrace.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledActiveTrace.java deleted file mode 100644 index 74258425c062..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledActiveTrace.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2016 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.web.vo.stat; - -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -public class SampledActiveTrace implements SampledAgentStatDataPoint { - - public static final int UNCOLLECTED_COUNT = -1; - public static final Point.UncollectedPointCreator> UNCOLLECTED_POINT_CREATOR = UncollectedPointCreatorFactory.createIntPointCreator(UNCOLLECTED_COUNT); - - private final AgentStatPoint fastCounts; - private final AgentStatPoint normalCounts; - private final AgentStatPoint slowCounts; - private final AgentStatPoint verySlowCounts; - - public SampledActiveTrace(AgentStatPoint fastCounts, AgentStatPoint normalCounts, AgentStatPoint slowCounts, AgentStatPoint verySlowCounts) { - this.fastCounts = Objects.requireNonNull(fastCounts, "fastCounts"); - this.normalCounts = Objects.requireNonNull(normalCounts, "normalCounts"); - this.slowCounts = Objects.requireNonNull(slowCounts, "slowCounts"); - this.verySlowCounts = Objects.requireNonNull(verySlowCounts, "verySlowCounts"); - } - - public AgentStatPoint getFastCounts() { - return fastCounts; - } - - public AgentStatPoint getNormalCounts() { - return normalCounts; - } - - public AgentStatPoint getSlowCounts() { - return slowCounts; - } - - - public AgentStatPoint getVerySlowCounts() { - return verySlowCounts; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SampledActiveTrace that = (SampledActiveTrace) o; - - if (fastCounts != null ? !fastCounts.equals(that.fastCounts) : that.fastCounts != null) return false; - if (normalCounts != null ? !normalCounts.equals(that.normalCounts) : that.normalCounts != null) return false; - if (slowCounts != null ? !slowCounts.equals(that.slowCounts) : that.slowCounts != null) return false; - return verySlowCounts != null ? verySlowCounts.equals(that.verySlowCounts) : that.verySlowCounts == null; - } - - @Override - public int hashCode() { - int result = fastCounts != null ? fastCounts.hashCode() : 0; - result = 31 * result + (normalCounts != null ? normalCounts.hashCode() : 0); - result = 31 * result + (slowCounts != null ? slowCounts.hashCode() : 0); - result = 31 * result + (verySlowCounts != null ? verySlowCounts.hashCode() : 0); - return result; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledActiveTrace{"); - sb.append("fastCounts=").append(fastCounts); - sb.append(", normalCounts=").append(normalCounts); - sb.append(", slowCounts=").append(slowCounts); - sb.append(", verySlowCounts=").append(verySlowCounts); - sb.append('}'); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledCpuLoad.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledCpuLoad.java deleted file mode 100644 index 5a485e4df324..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledCpuLoad.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2016 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.web.vo.stat; - -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -public class SampledCpuLoad implements SampledAgentStatDataPoint { - - public static final Double UNCOLLECTED_PERCENTAGE = -1D; - public static final Point.UncollectedPointCreator> UNCOLLECTED_POINT_CREATOR = UncollectedPointCreatorFactory.createDoublePointCreator(UNCOLLECTED_PERCENTAGE); - - private final AgentStatPoint jvmCpuLoad; - private final AgentStatPoint systemCpuLoad; - - public SampledCpuLoad(AgentStatPoint jvmCpuLoad, AgentStatPoint systemCpuLoad) { - this.jvmCpuLoad = Objects.requireNonNull(jvmCpuLoad, "jvmCpuLoad"); - this.systemCpuLoad = Objects.requireNonNull(systemCpuLoad, "systemCpuLoad"); - } - - public AgentStatPoint getJvmCpuLoad() { - return jvmCpuLoad; - } - - - public AgentStatPoint getSystemCpuLoad() { - return systemCpuLoad; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledCpuLoad{"); - sb.append("jvmCpuLoad=").append(jvmCpuLoad); - sb.append(", systemCpuLoad=").append(systemCpuLoad); - sb.append('}'); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledDataSource.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledDataSource.java deleted file mode 100644 index 08cc3b5bb26e..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledDataSource.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat; - -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -/** - * @author Taejin Koo - */ -public class SampledDataSource implements SampledAgentStatDataPoint { - - public static final Integer UNCOLLECTED_VALUE = -1; - public static final String UNCOLLECTED_STRING = null; - public static final Point.UncollectedPointCreator> UNCOLLECTED_POINT_CREATOR = UncollectedPointCreatorFactory.createIntPointCreator(UNCOLLECTED_VALUE); - - private int id; - private short serviceTypeCode; - private String databaseName; - private String jdbcUrl; - private AgentStatPoint activeConnectionSize; - private AgentStatPoint maxConnectionSize; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public short getServiceTypeCode() { - return serviceTypeCode; - } - - public void setServiceTypeCode(short serviceTypeCode) { - this.serviceTypeCode = serviceTypeCode; - } - - public String getDatabaseName() { - return databaseName; - } - - public void setDatabaseName(String databaseName) { - this.databaseName = databaseName; - } - - public String getJdbcUrl() { - return jdbcUrl; - } - - public void setJdbcUrl(String jdbcUrl) { - this.jdbcUrl = jdbcUrl; - } - - public AgentStatPoint getActiveConnectionSize() { - return activeConnectionSize; - } - - public void setActiveConnectionSize(AgentStatPoint activeConnectionSize) { - this.activeConnectionSize = activeConnectionSize; - } - - public AgentStatPoint getMaxConnectionSize() { - return maxConnectionSize; - } - - public void setMaxConnectionSize(AgentStatPoint maxConnectionSize) { - this.maxConnectionSize = maxConnectionSize; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SampledDataSource that = (SampledDataSource) o; - - if (id != that.id) return false; - if (serviceTypeCode != that.serviceTypeCode) return false; - if (databaseName != null ? !databaseName.equals(that.databaseName) : that.databaseName != null) return false; - if (jdbcUrl != null ? !jdbcUrl.equals(that.jdbcUrl) : that.jdbcUrl != null) return false; - if (activeConnectionSize != null ? !activeConnectionSize.equals(that.activeConnectionSize) : that.activeConnectionSize != null) - return false; - return maxConnectionSize != null ? maxConnectionSize.equals(that.maxConnectionSize) : that.maxConnectionSize == null; - } - - @Override - public int hashCode() { - int result = id; - result = 31 * result + (int) serviceTypeCode; - result = 31 * result + (databaseName != null ? databaseName.hashCode() : 0); - result = 31 * result + (jdbcUrl != null ? jdbcUrl.hashCode() : 0); - result = 31 * result + (activeConnectionSize != null ? activeConnectionSize.hashCode() : 0); - result = 31 * result + (maxConnectionSize != null ? maxConnectionSize.hashCode() : 0); - return result; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledDataSource{"); - sb.append("id=").append(id); - sb.append(", serviceTypeCode=").append(serviceTypeCode); - sb.append(", databaseName='").append(databaseName).append('\''); - sb.append(", jdbcUrl='").append(jdbcUrl).append('\''); - sb.append(", activeConnectionSize=").append(activeConnectionSize); - sb.append(", maxConnectionSize=").append(maxConnectionSize); - sb.append('}'); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledDataSourceList.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledDataSourceList.java deleted file mode 100644 index 541b2811a01c..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledDataSourceList.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Taejin Koo - */ -public class SampledDataSourceList implements SampledAgentStatDataPoint { - - private final List sampledDataSourceList = new ArrayList<>(); - - public void addSampledDataSource(SampledDataSource sampledDataSource) { - sampledDataSourceList.add(sampledDataSource); - } - - public List getSampledDataSourceList() { - return sampledDataSourceList; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SampledDataSourceList that = (SampledDataSourceList) o; - - return sampledDataSourceList != null ? sampledDataSourceList.equals(that.sampledDataSourceList) : that.sampledDataSourceList == null; - - } - - @Override - public int hashCode() { - return sampledDataSourceList != null ? sampledDataSourceList.hashCode() : 0; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledDataSourceList{"); - sb.append("sampledDataSourceList=").append(sampledDataSourceList); - sb.append('}'); - return sb.toString(); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledDeadlock.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledDeadlock.java deleted file mode 100644 index 39476ffa5289..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledDeadlock.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat; - -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import java.util.Objects; - -/** - * @author Taejin Koo - */ -public class SampledDeadlock implements SampledAgentStatDataPoint { - - public static final int UNCOLLECTED_COUNT = -1; - public static final Point.UncollectedPointCreator> UNCOLLECTED_POINT_CREATOR = UncollectedPointCreatorFactory.createIntPointCreator(UNCOLLECTED_COUNT); - - private final AgentStatPoint deadlockedThreadCount; - - public SampledDeadlock(AgentStatPoint deadlockedThreadCount) { - this.deadlockedThreadCount = Objects.requireNonNull(deadlockedThreadCount, "deadlockedThreadCount"); - } - - public AgentStatPoint getDeadlockedThreadCount() { - return deadlockedThreadCount; - } - - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SampledDeadlock that = (SampledDeadlock) o; - - return deadlockedThreadCount != null ? deadlockedThreadCount.equals(that.deadlockedThreadCount) : that.deadlockedThreadCount == null; - } - - @Override - public int hashCode() { - return deadlockedThreadCount != null ? deadlockedThreadCount.hashCode() : 0; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledDeadlock{"); - sb.append("deadlockedThreadCount=").append(deadlockedThreadCount); - sb.append('}'); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledDirectBuffer.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledDirectBuffer.java deleted file mode 100644 index 504e0675d586..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledDirectBuffer.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2018 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.web.vo.stat; - -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import java.util.Objects; - -/** - * @author Roy Kim - */ -public class SampledDirectBuffer implements SampledAgentStatDataPoint { - - public static final Long UNCOLLECTED_VALUE = -1L; - public static final Point.UncollectedPointCreator> UNCOLLECTED_POINT_CREATOR = UncollectedPointCreatorFactory.createLongPointCreator(UNCOLLECTED_VALUE); - - private final AgentStatPoint directCount; - private final AgentStatPoint directMemoryUsed; - private final AgentStatPoint mappedCount; - private final AgentStatPoint mappedMemoryUsed; - - public SampledDirectBuffer(AgentStatPoint directCount, AgentStatPoint directMemoryUsed, AgentStatPoint mappedCount, AgentStatPoint mappedMemoryUsed) { - this.directCount = Objects.requireNonNull(directCount, "directCount"); - this.directMemoryUsed = Objects.requireNonNull(directMemoryUsed, "directMemoryUsed"); - this.mappedCount = Objects.requireNonNull(mappedCount, "mappedCount"); - this.mappedMemoryUsed = Objects.requireNonNull(mappedMemoryUsed, "mappedMemoryUsed"); - } - public AgentStatPoint getDirectCount() { - return directCount; - } - - public AgentStatPoint getDirectMemoryUsed() { - return directMemoryUsed; - } - - public AgentStatPoint getMappedCount() { - return mappedCount; - } - - public AgentStatPoint getMappedMemoryUsed() { - return mappedMemoryUsed; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledDirectBuffer{"); - sb.append("directCount=").append(directCount); - sb.append("directMemoryUsed=").append(directMemoryUsed); - sb.append("mappedCount=").append(mappedCount); - sb.append("mappedMemoryUsed=").append(mappedMemoryUsed); - sb.append('}'); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledFileDescriptor.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledFileDescriptor.java deleted file mode 100644 index 01ccab981396..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledFileDescriptor.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2018 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.web.vo.stat; - -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import java.util.Objects; - -/** - * @author Roy Kim - */ -public class SampledFileDescriptor implements SampledAgentStatDataPoint { - - public static final Long UNCOLLECTED_VALUE = -1L; - public static final Point.UncollectedPointCreator> UNCOLLECTED_POINT_CREATOR = UncollectedPointCreatorFactory.createLongPointCreator(UNCOLLECTED_VALUE); - - private final AgentStatPoint openFileDescriptorCount; - - public SampledFileDescriptor(AgentStatPoint openFileDescriptorCount) { - this.openFileDescriptorCount = Objects.requireNonNull(openFileDescriptorCount, "openFileDescriptorCount"); - } - - public AgentStatPoint getOpenFileDescriptorCount() { - return openFileDescriptorCount; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledFileDescriptor{"); - sb.append("openFileDescriptorCount=").append(openFileDescriptorCount); - sb.append('}'); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGc.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGc.java deleted file mode 100644 index 69f3bf4a56a5..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGc.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2016 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.web.vo.stat; - -import com.navercorp.pinpoint.common.server.bo.JvmGcType; -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -/** - * @author HyunGil Jeong - */ -public class SampledJvmGc implements SampledAgentStatDataPoint { - - public static final Long UNCOLLECTED_VALUE = -1L; - public static final Point.UncollectedPointCreator> UNCOLLECTED_POINT_CREATOR = UncollectedPointCreatorFactory.createLongPointCreator(UNCOLLECTED_VALUE); - - private JvmGcType jvmGcType; - private AgentStatPoint heapUsed; - private AgentStatPoint heapMax; - private AgentStatPoint nonHeapUsed; - private AgentStatPoint nonHeapMax; - private AgentStatPoint gcOldCount; - private AgentStatPoint gcOldTime; - - public JvmGcType getJvmGcType() { - return jvmGcType; - } - - public void setJvmGcType(JvmGcType jvmGcType) { - this.jvmGcType = jvmGcType; - } - - public AgentStatPoint getHeapUsed() { - return heapUsed; - } - - public void setHeapUsed(AgentStatPoint heapUsed) { - this.heapUsed = heapUsed; - } - - public AgentStatPoint getHeapMax() { - return heapMax; - } - - public void setHeapMax(AgentStatPoint heapMax) { - this.heapMax = heapMax; - } - - public AgentStatPoint getNonHeapUsed() { - return nonHeapUsed; - } - - public void setNonHeapUsed(AgentStatPoint nonHeapUsed) { - this.nonHeapUsed = nonHeapUsed; - } - - public AgentStatPoint getNonHeapMax() { - return nonHeapMax; - } - - public void setNonHeapMax(AgentStatPoint nonHeapMax) { - this.nonHeapMax = nonHeapMax; - } - - public AgentStatPoint getGcOldCount() { - return gcOldCount; - } - - public void setGcOldCount(AgentStatPoint gcOldCount) { - this.gcOldCount = gcOldCount; - } - - public AgentStatPoint getGcOldTime() { - return gcOldTime; - } - - public void setGcOldTime(AgentStatPoint gcOldTime) { - this.gcOldTime = gcOldTime; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SampledJvmGc that = (SampledJvmGc) o; - - if (jvmGcType != that.jvmGcType) return false; - if (heapUsed != null ? !heapUsed.equals(that.heapUsed) : that.heapUsed != null) return false; - if (heapMax != null ? !heapMax.equals(that.heapMax) : that.heapMax != null) return false; - if (nonHeapUsed != null ? !nonHeapUsed.equals(that.nonHeapUsed) : that.nonHeapUsed != null) return false; - if (nonHeapMax != null ? !nonHeapMax.equals(that.nonHeapMax) : that.nonHeapMax != null) return false; - if (gcOldCount != null ? !gcOldCount.equals(that.gcOldCount) : that.gcOldCount != null) return false; - return gcOldTime != null ? gcOldTime.equals(that.gcOldTime) : that.gcOldTime == null; - } - - @Override - public int hashCode() { - int result = jvmGcType != null ? jvmGcType.hashCode() : 0; - result = 31 * result + (heapUsed != null ? heapUsed.hashCode() : 0); - result = 31 * result + (heapMax != null ? heapMax.hashCode() : 0); - result = 31 * result + (nonHeapUsed != null ? nonHeapUsed.hashCode() : 0); - result = 31 * result + (nonHeapMax != null ? nonHeapMax.hashCode() : 0); - result = 31 * result + (gcOldCount != null ? gcOldCount.hashCode() : 0); - result = 31 * result + (gcOldTime != null ? gcOldTime.hashCode() : 0); - return result; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledJvmGc{"); - sb.append("jvmGcType=").append(jvmGcType); - sb.append(", heapUsed=").append(heapUsed); - sb.append(", heapMax=").append(heapMax); - sb.append(", nonHeapUsed=").append(nonHeapUsed); - sb.append(", nonHeapMax=").append(nonHeapMax); - sb.append(", gcOldCount=").append(gcOldCount); - sb.append(", gcOldTime=").append(gcOldTime); - sb.append('}'); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGcDetailed.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGcDetailed.java deleted file mode 100644 index d1d6be1f4377..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGcDetailed.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2016 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.web.vo.stat; - -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -public class SampledJvmGcDetailed implements SampledAgentStatDataPoint { - - public static final Long UNCOLLECTED_VALUE = -1L; - public static final Point.UncollectedPointCreator> UNCOLLECTED_VALUE_POINT_CREATOR = UncollectedPointCreatorFactory.createLongPointCreator(UNCOLLECTED_VALUE); - - public static final Double UNCOLLECTED_PERCENTAGE = -1D; - public static final Point.UncollectedPointCreator> UNCOLLECTED_PERCENTAGE_POINT_CREATOR = UncollectedPointCreatorFactory.createDoublePointCreator(UNCOLLECTED_VALUE); - - private final AgentStatPoint gcNewCount; - private final AgentStatPoint gcNewTime; - private final AgentStatPoint codeCacheUsed; - private final AgentStatPoint newGenUsed; - private final AgentStatPoint oldGenUsed; - private final AgentStatPoint survivorSpaceUsed; - private final AgentStatPoint permGenUsed; - private final AgentStatPoint metaspaceUsed; - - public SampledJvmGcDetailed(AgentStatPoint gcNewCount, AgentStatPoint gcNewTime, AgentStatPoint codeCacheUsed, AgentStatPoint newGenUsed, - AgentStatPoint oldGenUsed, AgentStatPoint survivorSpaceUsed, AgentStatPoint permGenUsed, AgentStatPoint metaspaceUsed) { - this.gcNewCount = Objects.requireNonNull(gcNewCount, "gcNewCount"); - this.gcNewTime = Objects.requireNonNull(gcNewTime, "gcNewTime"); - this.codeCacheUsed = Objects.requireNonNull(codeCacheUsed, "codeCacheUsed"); - this.newGenUsed = Objects.requireNonNull(newGenUsed, "newGenUsed"); - this.oldGenUsed = Objects.requireNonNull(oldGenUsed, "oldGenUsed"); - this.survivorSpaceUsed = Objects.requireNonNull(survivorSpaceUsed, "survivorSpaceUsed"); - this.permGenUsed = Objects.requireNonNull(permGenUsed, "permGenUsed"); - this.metaspaceUsed = Objects.requireNonNull(metaspaceUsed, "metaspaceUsed"); - } - - public AgentStatPoint getGcNewCount() { - return gcNewCount; - } - - public AgentStatPoint getGcNewTime() { - return gcNewTime; - } - - public AgentStatPoint getCodeCacheUsed() { - return codeCacheUsed; - } - - public AgentStatPoint getNewGenUsed() { - return newGenUsed; - } - - public AgentStatPoint getOldGenUsed() { - return oldGenUsed; - } - - public AgentStatPoint getSurvivorSpaceUsed() { - return survivorSpaceUsed; - } - - public AgentStatPoint getPermGenUsed() { - return permGenUsed; - } - - public AgentStatPoint getMetaspaceUsed() { - return metaspaceUsed; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SampledJvmGcDetailed that = (SampledJvmGcDetailed) o; - - if (gcNewCount != null ? !gcNewCount.equals(that.gcNewCount) : that.gcNewCount != null) return false; - if (gcNewTime != null ? !gcNewTime.equals(that.gcNewTime) : that.gcNewTime != null) return false; - if (codeCacheUsed != null ? !codeCacheUsed.equals(that.codeCacheUsed) : that.codeCacheUsed != null) - return false; - if (newGenUsed != null ? !newGenUsed.equals(that.newGenUsed) : that.newGenUsed != null) return false; - if (oldGenUsed != null ? !oldGenUsed.equals(that.oldGenUsed) : that.oldGenUsed != null) return false; - if (survivorSpaceUsed != null ? !survivorSpaceUsed.equals(that.survivorSpaceUsed) : that.survivorSpaceUsed != null) - return false; - if (permGenUsed != null ? !permGenUsed.equals(that.permGenUsed) : that.permGenUsed != null) return false; - return metaspaceUsed != null ? metaspaceUsed.equals(that.metaspaceUsed) : that.metaspaceUsed == null; - } - - @Override - public int hashCode() { - int result = gcNewCount != null ? gcNewCount.hashCode() : 0; - result = 31 * result + (gcNewTime != null ? gcNewTime.hashCode() : 0); - result = 31 * result + (codeCacheUsed != null ? codeCacheUsed.hashCode() : 0); - result = 31 * result + (newGenUsed != null ? newGenUsed.hashCode() : 0); - result = 31 * result + (oldGenUsed != null ? oldGenUsed.hashCode() : 0); - result = 31 * result + (survivorSpaceUsed != null ? survivorSpaceUsed.hashCode() : 0); - result = 31 * result + (permGenUsed != null ? permGenUsed.hashCode() : 0); - result = 31 * result + (metaspaceUsed != null ? metaspaceUsed.hashCode() : 0); - return result; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledJvmGcDetailed{"); - sb.append("gcNewCount=").append(gcNewCount); - sb.append(", gcNewTime=").append(gcNewTime); - sb.append(", codeCacheUsed=").append(codeCacheUsed); - sb.append(", newGenUsed=").append(newGenUsed); - sb.append(", oldGenUsed=").append(oldGenUsed); - sb.append(", survivorSpaceUsed=").append(survivorSpaceUsed); - sb.append(", permGenUsed=").append(permGenUsed); - sb.append(", metaspaceUsed=").append(metaspaceUsed); - sb.append('}'); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledLoadedClassCount.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledLoadedClassCount.java deleted file mode 100644 index 7d44dc499b24..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledLoadedClassCount.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2018 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.web.vo.stat; - -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import java.util.Objects; - -public class SampledLoadedClassCount implements SampledAgentStatDataPoint { - - public static final Long UNCOLLECTED_VALUE = -1L; - public static final Point.UncollectedPointCreator> UNCOLLECTED_POINT_CREATOR = UncollectedPointCreatorFactory.createLongPointCreator(UNCOLLECTED_VALUE); - - private final AgentStatPoint loadedClassCount; - private final AgentStatPoint unloadedClassCount; - - public SampledLoadedClassCount(AgentStatPoint loadedClassCount, AgentStatPoint unloadedClassCount) { - this.loadedClassCount = Objects.requireNonNull(loadedClassCount, "directCount"); - this.unloadedClassCount = Objects.requireNonNull(unloadedClassCount, "directMemoryUsed"); - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledLoadedClassCount{"); - sb.append("loadedClassCount=").append(loadedClassCount); - sb.append("unloadedClassCount=").append(unloadedClassCount); - sb.append('}'); - return sb.toString(); - } - - public AgentStatPoint getUnloadedClassCount() { return unloadedClassCount; } - - public AgentStatPoint getLoadedClassCount() { return loadedClassCount; } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledResponseTime.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledResponseTime.java deleted file mode 100644 index 56bbc9ace4f1..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledResponseTime.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat; - -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import java.util.Objects; - -/** - * @author Taejin Koo - */ -public class SampledResponseTime implements SampledAgentStatDataPoint { - - public static final long UNCOLLECTED_RESPONSE_TIME = -1L; - public static final Point.UncollectedPointCreator> UNCOLLECTED_POINT_CREATOR = UncollectedPointCreatorFactory.createLongPointCreator(UNCOLLECTED_RESPONSE_TIME); - - private final AgentStatPoint avg; - private final AgentStatPoint max; - - public SampledResponseTime(AgentStatPoint avg, AgentStatPoint max) { - this.avg = Objects.requireNonNull(avg, "avg"); - this.max = Objects.requireNonNull(max, "max"); - } - - public AgentStatPoint getAvg() { - return avg; - } - - public AgentStatPoint getMax() { - return max; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SampledResponseTime that = (SampledResponseTime) o; - - if (avg != null ? !avg.equals(that.avg) : that.avg != null) return false; - return max != null ? max.equals(that.max) : that.max == null; - - } - - @Override - public int hashCode() { - int result = avg != null ? avg.hashCode() : 0; - result = 31 * result + (max != null ? max.hashCode() : 0); - return result; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledResponseTime{"); - sb.append("avg=").append(avg); - sb.append(", max=").append(max); - sb.append('}'); - return sb.toString(); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledTotalThreadCount.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledTotalThreadCount.java deleted file mode 100644 index df83c5702c3b..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledTotalThreadCount.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2020 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.web.vo.stat; - -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import java.util.Objects; - -public class SampledTotalThreadCount implements SampledAgentStatDataPoint { - public static final Long UNCOLLECTED_VALUE = -1L; - public static final Point.UncollectedPointCreator> UNCOLLECTED_POINT_CREATOR = UncollectedPointCreatorFactory.createLongPointCreator(UNCOLLECTED_VALUE); - - private final AgentStatPoint totalThreadCount; - - public SampledTotalThreadCount(AgentStatPoint totalThreadCount) { - this.totalThreadCount = Objects.requireNonNull(totalThreadCount, "totalThreadCount"); - } - - public AgentStatPoint getTotalThreadCount() { return totalThreadCount; } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledTotalThreadCount {"); - sb.append("totalThreadCount=").append(totalThreadCount); - sb.append('}'); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledTransaction.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledTransaction.java deleted file mode 100644 index df37e94278d7..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledTransaction.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2016 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.web.vo.stat; - -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -public class SampledTransaction implements SampledAgentStatDataPoint { - - public static final double UNCOLLECTED_VALUE = -1D; - public static final Point.UncollectedPointCreator> UNCOLLECTED_POINT_CREATOR = UncollectedPointCreatorFactory.createDoublePointCreator(UNCOLLECTED_VALUE); - - private final AgentStatPoint sampledNew; - private final AgentStatPoint sampledContinuation; - private final AgentStatPoint unsampledNew; - private final AgentStatPoint unsampledContinuation; - private final AgentStatPoint skippedNew; - private final AgentStatPoint skippedContinuation; - private final AgentStatPoint total; - - public SampledTransaction(AgentStatPoint sampledNew, AgentStatPoint sampledContinuation, AgentStatPoint unsampledNew, AgentStatPoint unsampledContinuation, AgentStatPoint skippedNew, AgentStatPoint skippedContinuation, AgentStatPoint total) { - this.sampledNew = Objects.requireNonNull(sampledNew, "sampledNew"); - this.sampledContinuation = Objects.requireNonNull(sampledContinuation, "sampledContinuation"); - this.unsampledNew = Objects.requireNonNull(unsampledNew, "unsampledNew"); - this.unsampledContinuation = Objects.requireNonNull(unsampledContinuation, "unsampledContinuation"); - this.skippedNew = Objects.requireNonNull(skippedNew, "skippedNew"); - this.skippedContinuation = Objects.requireNonNull(skippedContinuation, "skippedContinuation"); - this.total = Objects.requireNonNull(total, "total"); - } - - public AgentStatPoint getSampledNew() { - return sampledNew; - } - - public AgentStatPoint getSampledContinuation() { - return sampledContinuation; - } - - public AgentStatPoint getUnsampledNew() { - return unsampledNew; - } - - public AgentStatPoint getUnsampledContinuation() { - return unsampledContinuation; - } - - public AgentStatPoint getTotal() { - return total; - } - - public AgentStatPoint getSkippedNew() { - return skippedNew; - } - - public AgentStatPoint getSkippedContinuation() { - return skippedContinuation; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SampledTransaction that = (SampledTransaction) o; - - if (sampledNew != null ? !sampledNew.equals(that.sampledNew) : that.sampledNew != null) return false; - if (sampledContinuation != null ? !sampledContinuation.equals(that.sampledContinuation) : that.sampledContinuation != null) - return false; - if (unsampledNew != null ? !unsampledNew.equals(that.unsampledNew) : that.unsampledNew != null) return false; - if (unsampledContinuation != null ? !unsampledContinuation.equals(that.unsampledContinuation) : that.unsampledContinuation != null) - return false; - if (skippedNew != null ? !skippedNew.equals(that.skippedNew) : that.skippedNew != null) return false; - if (skippedContinuation != null ? !skippedContinuation.equals(that.skippedContinuation) : that.skippedContinuation != null) - return false; - - return total != null ? total.equals(that.total) : that.total == null; - } - - @Override - public int hashCode() { - int result = sampledNew != null ? sampledNew.hashCode() : 0; - result = 31 * result + (sampledContinuation != null ? sampledContinuation.hashCode() : 0); - result = 31 * result + (unsampledNew != null ? unsampledNew.hashCode() : 0); - result = 31 * result + (unsampledContinuation != null ? unsampledContinuation.hashCode() : 0); - result = 31 * result + (skippedNew != null ? skippedNew.hashCode() : 0); - result = 31 * result + (skippedContinuation != null ? skippedContinuation.hashCode() : 0); - result = 31 * result + (total != null ? total.hashCode() : 0); - return result; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledTransaction{"); - sb.append("sampledNew=").append(sampledNew); - sb.append(", sampledContinuation=").append(sampledContinuation); - sb.append(", unsampledNew=").append(unsampledNew); - sb.append(", unsampledContinuation=").append(unsampledContinuation); - sb.append(", skippedNew=").append(skippedNew); - sb.append(", skippedContinuation=").append(skippedContinuation); - sb.append(", total=").append(total); - sb.append('}'); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/StatChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/StatChart.java index b8423e315420..6fff09de14f3 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/StatChart.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/StatChart.java @@ -16,8 +16,6 @@ package com.navercorp.pinpoint.web.vo.stat.chart; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.navercorp.pinpoint.web.view.StatChartGroupSerializer; import com.navercorp.pinpoint.web.vo.chart.Point; /** @@ -26,6 +24,5 @@ */ public interface StatChart

{ - @JsonSerialize(using = StatChartGroupSerializer.class) StatChartGroup

getCharts(); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/ActiveTraceChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/ActiveTraceChart.java deleted file mode 100644 index f872ea2a5c81..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/ActiveTraceChart.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; -import com.navercorp.pinpoint.web.vo.stat.chart.ChartGroupBuilder; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -public class ActiveTraceChart extends DefaultAgentChart { - - public enum ActiveTraceChartType implements StatChartGroup.AgentChartType { - ACTIVE_TRACE_VERY_SLOW, - ACTIVE_TRACE_SLOW, - ACTIVE_TRACE_NORMAL, - ACTIVE_TRACE_FAST; - - private static final String[] SCHEMA = {"min", "max", "avg", "sum", "title"}; - - @Override - public String[] getSchema() { - return SCHEMA; - } - } - - private static final ChartGroupBuilder> BUILDER = newChartBuilder(); - - static ChartGroupBuilder> newChartBuilder() { - ChartGroupBuilder> builder = new ChartGroupBuilder<>(SampledActiveTrace.UNCOLLECTED_POINT_CREATOR); - builder.addPointFunction(ActiveTraceChartType.ACTIVE_TRACE_FAST, SampledActiveTrace::getFastCounts); - builder.addPointFunction(ActiveTraceChartType.ACTIVE_TRACE_NORMAL, SampledActiveTrace::getNormalCounts); - builder.addPointFunction(ActiveTraceChartType.ACTIVE_TRACE_SLOW, SampledActiveTrace::getSlowCounts); - builder.addPointFunction(ActiveTraceChartType.ACTIVE_TRACE_VERY_SLOW, SampledActiveTrace::getVerySlowCounts); - return builder; - } - - public ActiveTraceChart(TimeWindow timeWindow, List statList) { - super(timeWindow, statList, BUILDER); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/CpuLoadChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/CpuLoadChart.java deleted file mode 100644 index 9d0ecdfcd341..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/CpuLoadChart.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; -import com.navercorp.pinpoint.web.vo.stat.chart.ChartGroupBuilder; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -public class CpuLoadChart extends DefaultAgentChart { - - public enum CpuLoadChartType implements StatChartGroup.AgentChartType { - CPU_LOAD_JVM, - CPU_LOAD_SYSTEM - } - - private static final ChartGroupBuilder> BUILDER = newChartBuilder(); - - static ChartGroupBuilder> newChartBuilder() { - ChartGroupBuilder> builder = new ChartGroupBuilder<>(SampledCpuLoad.UNCOLLECTED_POINT_CREATOR); - builder.addPointFunction(CpuLoadChartType.CPU_LOAD_JVM, SampledCpuLoad::getJvmCpuLoad); - builder.addPointFunction(CpuLoadChartType.CPU_LOAD_SYSTEM, SampledCpuLoad::getSystemCpuLoad); - return builder; - } - - public CpuLoadChart(TimeWindow timeWindow, List statList) { - super(timeWindow, statList, BUILDER); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DataSourceChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DataSourceChart.java deleted file mode 100644 index 4d717f23686d..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DataSourceChart.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.annotations.VisibleForTesting; -import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.chart.Chart; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSource; -import com.navercorp.pinpoint.web.vo.stat.chart.ChartGroupBuilder; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChart; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; -import org.springframework.util.CollectionUtils; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * @author Taejin Koo - */ -public class DataSourceChart implements StatChart> { - - public enum DataSourceChartType implements StatChartGroup.AgentChartType { - ACTIVE_CONNECTION_SIZE, - MAX_CONNECTION_SIZE - } - - private final DataSourceChartGroup dataSourceChartGroup; - - private static final ChartGroupBuilder> BUILDER = newChartBuilder(); - - static ChartGroupBuilder> newChartBuilder() { - ChartGroupBuilder> builder = new ChartGroupBuilder<>(SampledDataSource.UNCOLLECTED_POINT_CREATOR); - builder.addPointFunction(DataSourceChartType.ACTIVE_CONNECTION_SIZE, SampledDataSource::getActiveConnectionSize); - builder.addPointFunction(DataSourceChartType.MAX_CONNECTION_SIZE, SampledDataSource::getMaxConnectionSize); - return builder; - } - - public DataSourceChart(TimeWindow timeWindow, List sampledDataSources, ServiceTypeRegistryService serviceTypeRegistryService) { - this.dataSourceChartGroup = newDataSourceChartGroup(timeWindow, sampledDataSources, serviceTypeRegistryService); - } - - @VisibleForTesting - static DataSourceChartGroup newDataSourceChartGroup(TimeWindow timeWindow, List sampledDataSources, ServiceTypeRegistryService serviceTypeRegistryService) { - Objects.requireNonNull(timeWindow, "timeWindow"); - - Map>> chartTypeChartMap = newDatasourceChart(timeWindow, sampledDataSources); - if (Boolean.FALSE == CollectionUtils.isEmpty(sampledDataSources)) { - SampledDataSource latestSampledDataSource = CollectionUtils.lastElement(sampledDataSources); - if (latestSampledDataSource != null) { - int id = latestSampledDataSource.getId(); - String serviceTypeName = serviceTypeRegistryService.findServiceType(latestSampledDataSource.getServiceTypeCode()).getName(); - String databaseName = latestSampledDataSource.getDatabaseName(); - String jdbcUrl = latestSampledDataSource.getJdbcUrl(); - return new DataSourceChartGroup(timeWindow, chartTypeChartMap, id, serviceTypeName, databaseName, jdbcUrl); - } - } - final Integer uncollectedValue = SampledDataSource.UNCOLLECTED_VALUE; - // TODO avoid null - final String uncollectedString = SampledDataSource.UNCOLLECTED_STRING; - - return new DataSourceChartGroup(timeWindow, chartTypeChartMap, uncollectedValue, uncollectedString, uncollectedString, uncollectedString); - } - - @Override - public StatChartGroup> getCharts() { - return dataSourceChartGroup; - } - - public int getId() { - return dataSourceChartGroup.getId(); - } - - public String getServiceType() { - return dataSourceChartGroup.getServiceTypeName(); - } - - public String getDatabaseName() { - return dataSourceChartGroup.getDatabaseName(); - } - - public String getJdbcUrl() { - return dataSourceChartGroup.getJdbcUrl(); - } - - @VisibleForTesting - static Map>> newDatasourceChart(TimeWindow timeWindow, List sampledDataSourceList) { - return BUILDER.buildMap(timeWindow, sampledDataSourceList); - } - - public static class DataSourceChartGroup implements StatChartGroup> { - - private final TimeWindow timeWindow; - - private final Map>> dataSourceCharts; - - private final int id; - private final String serviceTypeName; - private final String databaseName; - private final String jdbcUrl; - - public DataSourceChartGroup(TimeWindow timeWindow, Map>> dataSourceCharts, int id, String serviceTypeName, String databaseName, String jdbcUrl) { - this.timeWindow = Objects.requireNonNull(timeWindow, "timeWindow"); - this.dataSourceCharts = dataSourceCharts; - this.id = id; - this.serviceTypeName = serviceTypeName; - this.databaseName = databaseName; - this.jdbcUrl = jdbcUrl; - } - - - @Override - public TimeWindow getTimeWindow() { - return timeWindow; - } - - @Override - public Map>> getCharts() { - return dataSourceCharts; - } - - public int getId() { - return id; - } - - public String getServiceTypeName() { - return serviceTypeName; - } - - public String getDatabaseName() { - return databaseName; - } - - public String getJdbcUrl() { - return jdbcUrl; - } - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DeadlockChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DeadlockChart.java deleted file mode 100644 index 184596bd03ae..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DeadlockChart.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledDeadlock; -import com.navercorp.pinpoint.web.vo.stat.chart.ChartGroupBuilder; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; - -import java.util.List; - -/** - * @author Taejin Koo - */ -public class DeadlockChart extends DefaultAgentChart { - - public enum DeadlockChartType implements StatChartGroup.AgentChartType { - DEADLOCK_COUNT - } - - private static final ChartGroupBuilder> BUILDER = newChartBuilder(); - - static ChartGroupBuilder> newChartBuilder() { - ChartGroupBuilder> builder = new ChartGroupBuilder<>(SampledDeadlock.UNCOLLECTED_POINT_CREATOR); - builder.addPointFunction(DeadlockChartType.DEADLOCK_COUNT, SampledDeadlock::getDeadlockedThreadCount); - return builder; - } - - public DeadlockChart(TimeWindow timeWindow, List statList) { - super(timeWindow, statList, BUILDER); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DirectBufferChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DirectBufferChart.java deleted file mode 100644 index 08ffc7655863..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DirectBufferChart.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2018 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledDirectBuffer; -import com.navercorp.pinpoint.web.vo.stat.chart.ChartGroupBuilder; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; - -import java.util.List; - -/** - * @author Roy Kim - */ -public class DirectBufferChart extends DefaultAgentChart { - - public enum DirectBufferChartType implements StatChartGroup.AgentChartType { - DIRECT_COUNT, - DIRECT_MEMORY_USED, - MAPPED_COUNT, - MAPPED_MEMORY_USED - } - - private static final ChartGroupBuilder> BUILDER = newChartBuilder(); - - static ChartGroupBuilder> newChartBuilder() { - ChartGroupBuilder> builder = new ChartGroupBuilder<>(SampledDirectBuffer.UNCOLLECTED_POINT_CREATOR); - builder.addPointFunction(DirectBufferChartType.DIRECT_COUNT, SampledDirectBuffer::getDirectCount); - builder.addPointFunction(DirectBufferChartType.DIRECT_MEMORY_USED, SampledDirectBuffer::getDirectMemoryUsed); - builder.addPointFunction(DirectBufferChartType.MAPPED_COUNT, SampledDirectBuffer::getMappedCount); - builder.addPointFunction(DirectBufferChartType.MAPPED_MEMORY_USED, SampledDirectBuffer::getMappedMemoryUsed); - return builder; - } - - public DirectBufferChart(TimeWindow timeWindow, List statList) { - super(timeWindow, statList, BUILDER); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/FileDescriptorChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/FileDescriptorChart.java deleted file mode 100644 index d4c3af3b2990..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/FileDescriptorChart.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2018 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledFileDescriptor; -import com.navercorp.pinpoint.web.vo.stat.chart.ChartGroupBuilder; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; - -import java.util.List; - -/** - * @author Roy Kim - */ -public class FileDescriptorChart extends DefaultAgentChart { - - public enum FileDescriptorChartType implements StatChartGroup.AgentChartType { - OPEN_FILE_DESCRIPTOR_COUNT - } - - private static final ChartGroupBuilder> BUILDER = newChartBuilder(); - - static ChartGroupBuilder> newChartBuilder() { - ChartGroupBuilder> builder = new ChartGroupBuilder<>(SampledFileDescriptor.UNCOLLECTED_POINT_CREATOR); - builder.addPointFunction(FileDescriptorChartType.OPEN_FILE_DESCRIPTOR_COUNT, SampledFileDescriptor::getOpenFileDescriptorCount); - return builder; - } - - public FileDescriptorChart(TimeWindow timeWindow, List statList) { - super(timeWindow, statList, BUILDER); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/JvmGcChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/JvmGcChart.java deleted file mode 100644 index 3d44e6878c4c..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/JvmGcChart.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; -import com.navercorp.pinpoint.web.vo.stat.chart.ChartGroupBuilder; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -public class JvmGcChart extends DefaultAgentChart { - - public enum JvmGcChartType implements StatChartGroup.AgentChartType { - JVM_MEMORY_HEAP_USED, - JVM_MEMORY_HEAP_MAX, - JVM_MEMORY_NON_HEAP_USED, - JVM_MEMORY_NON_HEAP_MAX, - JVM_GC_OLD_COUNT, - JVM_GC_OLD_TIME - } - - private static final ChartGroupBuilder> BUILDER = newChartBuilder(); - - static ChartGroupBuilder> newChartBuilder() { - ChartGroupBuilder> builder = new ChartGroupBuilder<>(SampledJvmGc.UNCOLLECTED_POINT_CREATOR); - builder.addPointFunction(JvmGcChartType.JVM_MEMORY_HEAP_USED, SampledJvmGc::getHeapUsed); - builder.addPointFunction(JvmGcChartType.JVM_MEMORY_HEAP_MAX, SampledJvmGc::getHeapMax); - builder.addPointFunction(JvmGcChartType.JVM_MEMORY_NON_HEAP_USED, SampledJvmGc::getNonHeapUsed); - builder.addPointFunction(JvmGcChartType.JVM_MEMORY_NON_HEAP_MAX, SampledJvmGc::getNonHeapMax); - builder.addPointFunction(JvmGcChartType.JVM_GC_OLD_COUNT, SampledJvmGc::getGcOldCount); - builder.addPointFunction(JvmGcChartType.JVM_GC_OLD_TIME, SampledJvmGc::getGcOldTime); - - return builder; - } - - public JvmGcChart(TimeWindow timeWindow, List statList) { - super(timeWindow, statList, BUILDER); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/JvmGcDetailedChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/JvmGcDetailedChart.java deleted file mode 100644 index ac2048be5b3c..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/JvmGcDetailedChart.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.chart.Chart; -import com.navercorp.pinpoint.web.vo.stat.SampledJvmGcDetailed; -import com.navercorp.pinpoint.web.vo.stat.chart.ChartGroupBuilder; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChart; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; -import com.navercorp.pinpoint.web.vo.stat.chart.application.DefaultStatChartGroup; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * @author HyunGil Jeong - */ -public class JvmGcDetailedChart implements StatChart> { - - public enum JvmGcDetailedChartType implements StatChartGroup.AgentChartType { - JVM_DETAILED_GC_NEW_COUNT, - JVM_DETAILED_GC_NEW_TIME, - JVM_DETAILED_CODE_CACHE_USED, - JVM_DETAILED_NEW_GEN_USED, - JVM_DETAILED_OLD_GEN_USED, - JVM_DETAILED_SURVIVOR_SPACE_USED, - JVM_DETAILED_PERM_GEN_USED, - JVM_DETAILED_METASPACE_USED - } - - private static final ChartGroupBuilder> LONG_BUILDER = newLongChartBuilder(); - private static final ChartGroupBuilder> DOUBLE_BUILDER = newDoubleChartBuilder(); - - static ChartGroupBuilder> newLongChartBuilder() { - ChartGroupBuilder> builder = new ChartGroupBuilder<>(SampledJvmGcDetailed.UNCOLLECTED_VALUE_POINT_CREATOR); - builder.addPointFunction(JvmGcDetailedChartType.JVM_DETAILED_GC_NEW_COUNT, SampledJvmGcDetailed::getGcNewCount); - builder.addPointFunction(JvmGcDetailedChartType.JVM_DETAILED_GC_NEW_TIME, SampledJvmGcDetailed::getGcNewTime); - return builder; - } - static ChartGroupBuilder> newDoubleChartBuilder() { - ChartGroupBuilder> builder = new ChartGroupBuilder<>(SampledJvmGcDetailed.UNCOLLECTED_PERCENTAGE_POINT_CREATOR); - builder.addPointFunction(JvmGcDetailedChartType.JVM_DETAILED_CODE_CACHE_USED, SampledJvmGcDetailed::getCodeCacheUsed); - builder.addPointFunction(JvmGcDetailedChartType.JVM_DETAILED_NEW_GEN_USED, SampledJvmGcDetailed::getNewGenUsed); - builder.addPointFunction(JvmGcDetailedChartType.JVM_DETAILED_OLD_GEN_USED, SampledJvmGcDetailed::getOldGenUsed); - builder.addPointFunction(JvmGcDetailedChartType.JVM_DETAILED_SURVIVOR_SPACE_USED, SampledJvmGcDetailed::getSurvivorSpaceUsed); - builder.addPointFunction(JvmGcDetailedChartType.JVM_DETAILED_PERM_GEN_USED, SampledJvmGcDetailed::getPermGenUsed); - builder.addPointFunction(JvmGcDetailedChartType.JVM_DETAILED_METASPACE_USED, SampledJvmGcDetailed::getMetaspaceUsed); - return builder; - } - - private final TimeWindow timeWindow; - private final List statList; - - public JvmGcDetailedChart(TimeWindow timeWindow, List statList) { - this.timeWindow = Objects.requireNonNull(timeWindow, "timeWindow"); - this.statList = Objects.requireNonNull(statList, "statList"); - } - - @Override - public StatChartGroup> getCharts() { - Map>> longMap = LONG_BUILDER.buildMap(timeWindow, statList); - Map>> doubleMap = DOUBLE_BUILDER.buildMap(timeWindow, statList); - - Map>> merge = new HashMap<>(); - merge.putAll((Map>>) (Map) longMap); - merge.putAll((Map>>) (Map) doubleMap); - return new DefaultStatChartGroup<>(timeWindow, merge); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/LoadedClassCountChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/LoadedClassCountChart.java deleted file mode 100644 index a82e6fa629d8..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/LoadedClassCountChart.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2018 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledLoadedClassCount; -import com.navercorp.pinpoint.web.vo.stat.chart.ChartGroupBuilder; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; - -import java.util.List; - -public class LoadedClassCountChart extends DefaultAgentChart { - - public enum LoadedClassCountChartType implements StatChartGroup.AgentChartType { - LOADED_CLASS_COUNT, - UNLOADED_CLASS_COUNT - } - - private static final ChartGroupBuilder> BUILDER = newChartBuilder(); - - static ChartGroupBuilder> newChartBuilder() { - ChartGroupBuilder> builder = new ChartGroupBuilder<>(SampledLoadedClassCount.UNCOLLECTED_POINT_CREATOR); - builder.addPointFunction(LoadedClassCountChartType.LOADED_CLASS_COUNT, SampledLoadedClassCount::getLoadedClassCount); - builder.addPointFunction(LoadedClassCountChartType.UNLOADED_CLASS_COUNT, SampledLoadedClassCount::getUnloadedClassCount); - return builder; - } - - public LoadedClassCountChart(TimeWindow timeWindow, List statList) { - super(timeWindow, statList, BUILDER); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/ResponseTimeChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/ResponseTimeChart.java deleted file mode 100644 index 04f076012050..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/ResponseTimeChart.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledLoadedClassCount; -import com.navercorp.pinpoint.web.vo.stat.SampledResponseTime; -import com.navercorp.pinpoint.web.vo.stat.chart.ChartGroupBuilder; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; - -import java.util.List; - -/** - * @author Taejin Koo - */ -public class ResponseTimeChart extends DefaultAgentChart { - - public enum ResponseTimeChartType implements StatChartGroup.AgentChartType { - AVG, - MAX - } - - private static final ChartGroupBuilder> BUILDER = newChartBuilder(); - - static ChartGroupBuilder> newChartBuilder() { - ChartGroupBuilder> builder = new ChartGroupBuilder<>(SampledLoadedClassCount.UNCOLLECTED_POINT_CREATOR); - builder.addPointFunction(ResponseTimeChartType.AVG, SampledResponseTime::getAvg); - builder.addPointFunction(ResponseTimeChartType.MAX, SampledResponseTime::getMax); - return builder; - } - - public ResponseTimeChart(TimeWindow timeWindow, List statList) { - super(timeWindow, statList, BUILDER); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/TitledAgentStatPoint.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/TitledAgentStatPoint.java deleted file mode 100644 index 68fc5fef2812..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/TitledAgentStatPoint.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat.chart.agent; - -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.navercorp.pinpoint.web.view.TitledAgentStatPointSerializer; - -/** - * @author HyunGil Jeong - */ -@JsonSerialize(using = TitledAgentStatPointSerializer.class) -public class TitledAgentStatPoint extends AgentStatPoint { - - private final String title; - - public TitledAgentStatPoint(String title, long xVal, Y yVal) { - super(xVal, yVal); - this.title = title; - } - - public TitledAgentStatPoint(String title, long xVal, Y minYVal, Y maxYVal, Double avgYVal, Y sumYVal) { - super(xVal, minYVal, maxYVal, avgYVal, sumYVal); - this.title = title; - } - - public String getTitle() { - return title; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - - TitledAgentStatPoint that = (TitledAgentStatPoint) o; - - return title != null ? title.equals(that.title) : that.title == null; - } - - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (title != null ? title.hashCode() : 0); - return result; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("TitledAgentStatPoint{"); - sb.append("title='").append(title).append('\''); - sb.append(", ").append(super.toString()); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/TotalThreadCountChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/TotalThreadCountChart.java deleted file mode 100644 index 5e549b65007a..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/TotalThreadCountChart.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2020 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledTotalThreadCount; -import com.navercorp.pinpoint.web.vo.stat.chart.ChartGroupBuilder; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; - -import java.util.List; - -public class TotalThreadCountChart extends DefaultAgentChart { - - public enum TotalThreadCountChartType implements StatChartGroup.AgentChartType { - TOTAL_THREAD_COUNT - } - - private static final ChartGroupBuilder> BUILDER = newChartBuilder(); - - static ChartGroupBuilder> newChartBuilder() { - ChartGroupBuilder> builder = new ChartGroupBuilder<>(SampledTotalThreadCount.UNCOLLECTED_POINT_CREATOR); - builder.addPointFunction(TotalThreadCountChartType.TOTAL_THREAD_COUNT, SampledTotalThreadCount::getTotalThreadCount); - return builder; - } - - public TotalThreadCountChart(TimeWindow timeWindow, List statList) { - super(timeWindow, statList, BUILDER); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/TransactionChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/TransactionChart.java deleted file mode 100644 index a211cc058e7d..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/TransactionChart.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; -import com.navercorp.pinpoint.web.vo.stat.chart.ChartGroupBuilder; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; - -import java.util.List; - -/** - * @author HyunGil Jeong - */ -public class TransactionChart extends DefaultAgentChart { - - public enum TransactionChartType implements StatChartGroup.AgentChartType { - TPS_SAMPLED_NEW, - TPS_SAMPLED_CONTINUATION, - TPS_UNSAMPLED_NEW, - TPS_UNSAMPLED_CONTINUATION, - TPS_SKIPPED_NEW, - TPS_SKIPPED_CONTINUATION, - TPS_TOTAL - } - - private static final ChartGroupBuilder> BUILDER = newChartBuilder(); - - static ChartGroupBuilder> newChartBuilder() { - ChartGroupBuilder> builder = new ChartGroupBuilder<>(SampledTransaction.UNCOLLECTED_POINT_CREATOR); - builder.addPointFunction(TransactionChartType.TPS_SAMPLED_NEW, SampledTransaction::getSampledNew); - builder.addPointFunction(TransactionChartType.TPS_SAMPLED_CONTINUATION, SampledTransaction::getSampledContinuation); - builder.addPointFunction(TransactionChartType.TPS_UNSAMPLED_NEW, SampledTransaction::getUnsampledNew); - builder.addPointFunction(TransactionChartType.TPS_UNSAMPLED_CONTINUATION, SampledTransaction::getUnsampledContinuation); - builder.addPointFunction(TransactionChartType.TPS_SKIPPED_NEW, SampledTransaction::getSkippedNew); - builder.addPointFunction(TransactionChartType.TPS_SKIPPED_CONTINUATION, SampledTransaction::getSkippedContinuation); - builder.addPointFunction(TransactionChartType.TPS_TOTAL, SampledTransaction::getTotal); - - return builder; - } - - public TransactionChart(TimeWindow timeWindow, List statList) { - super(timeWindow, statList, BUILDER); - } -} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/authorization/controller/ChartTypeMappingBuilderTest.java b/web/src/test/java/com/navercorp/pinpoint/web/authorization/controller/ChartTypeMappingBuilderTest.java deleted file mode 100644 index 79ae86c11bf8..000000000000 --- a/web/src/test/java/com/navercorp/pinpoint/web/authorization/controller/ChartTypeMappingBuilderTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.navercorp.pinpoint.web.authorization.controller; - -import com.navercorp.pinpoint.web.service.stat.ChartTypeSupport; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ChartTypeMappingBuilderTest { - @Test - public void build() { - ChartTypeMappingBuilder builder = new ChartTypeMappingBuilder<>(); - Map map = builder.build(List.of(new TestApplicationStatChartService())); - assertThat(map).hasSize(1); - } - - public static class TestApplicationStatChartService implements ChartTypeSupport { - - @Override - public String getChartType() { - return "test"; - } - } -} \ No newline at end of file diff --git a/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2Test.java b/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2Test.java deleted file mode 100644 index 695079a4fa4c..000000000000 --- a/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2Test.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright 2016 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.web.mapper.stat; - -import com.navercorp.pinpoint.common.buffer.Buffer; -import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; -import com.navercorp.pinpoint.common.hbase.distributor.RangeOneByteSimpleHash; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDecoder; -import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatEncoder; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatHbaseOperationFactory; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatRowKeyDecoder; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatRowKeyEncoder; -import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatSerializer; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; -import com.navercorp.pinpoint.web.mapper.TimestampFilter; -import com.sematext.hbase.wd.AbstractRowKeyDistributor; -import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix; -import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.client.Result; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -/** - * @author HyunGil Jeong - */ -public class AgentStatMapperV2Test { - - private static final int MAX_NUM_TEST_VALUES = 10 + 1; // Random API's upper bound field is exclusive - - private static final String AGENT_ID = "testAgent"; - private static final AgentStatType AGENT_STAT_TYPE = AgentStatType.UNKNOWN; - private static final long COLLECT_INVERVAL = 5000L; - private static final Random RANDOM = new Random(); - private static final TimestampFilter TEST_FILTER = new TimestampFilter() { - @Override - public boolean filter(long timestamp) { - return false; - } - }; - - private final AgentStatRowKeyEncoder rowKeyEncoder = new AgentStatRowKeyEncoder(); - - private final AgentStatRowKeyDecoder rowKeyDecoder = new AgentStatRowKeyDecoder(); - - private final AbstractRowKeyDistributor rowKeyDistributor = new RowKeyDistributorByHashPrefix( - new RangeOneByteSimpleHash(0, 33, 64)); - - private final AgentStatHbaseOperationFactory hbaseOperationFactory = new AgentStatHbaseOperationFactory( - this.rowKeyEncoder, this.rowKeyDecoder, this.rowKeyDistributor); - - private final AgentStatCodec codec = new TestAgentStatCodec(); - - private final AgentStatEncoder encoder = new TestAgentStatEncoder(this.codec); - - private final AgentStatDecoder decoder = new TestAgentStatDecoder(this.codec); - - private final AgentStatSerializer serializer = new TestAgentStatSerializer(this.encoder); - - @Test - public void mapperTest() throws Exception { - // Given - List givenAgentStats = new ArrayList<>(); - List puts = new ArrayList<>(); - long initialTimestamp = System.currentTimeMillis(); - int numBatch = RANDOM.nextInt(1, MAX_NUM_TEST_VALUES); - for (int i = 0; i < numBatch; i++) { - int batchSize = RANDOM.nextInt(1, MAX_NUM_TEST_VALUES); - List agentStatBatch = createAgentStats(initialTimestamp, COLLECT_INVERVAL, batchSize); - givenAgentStats.addAll(agentStatBatch); - puts.addAll(this.hbaseOperationFactory.createPuts(AGENT_ID, AGENT_STAT_TYPE, agentStatBatch, this.serializer)); - initialTimestamp += batchSize * COLLECT_INVERVAL; - } - List cellsToPut = new ArrayList<>(); - for (Put put : puts) { - List cells = put.getFamilyCellMap().get(HbaseColumnFamily.AGENT_STAT_STATISTICS.getName()); - cellsToPut.addAll(cells); - } - Result result = Result.create(cellsToPut); - - // When - AgentStatMapperV2 mapper = new AgentStatMapperV2<>(this.hbaseOperationFactory, this.decoder, TEST_FILTER, HbaseColumnFamily.AGENT_STAT_STATISTICS); - List mappedAgentStats = mapper.mapRow(result, 0); - - // Then - givenAgentStats.sort(AgentStatMapperV2.REVERSE_TIMESTAMP_COMPARATOR); - Assertions.assertEquals(givenAgentStats, mappedAgentStats); - } - - private List createAgentStats(long initialTimestamp, long interval, int batchSize) { - List agentStats = new ArrayList<>(batchSize); - for (int i = 0; i < batchSize; i++) { - long timestamp = initialTimestamp + (interval * i); - TestAgentStat agentStat = new TestAgentStat(); - agentStat.setAgentId(AGENT_ID); - agentStat.setTimestamp(timestamp); - agentStat.setValue(RANDOM.nextLong()); - agentStats.add(agentStat); - } - return agentStats; - } - - private static class TestAgentStatCodec implements AgentStatCodec { - - @Override - public byte getVersion() { - return 0; - } - - @Override - public void encodeValues(Buffer valueBuffer, List agentStats) { - valueBuffer.putInt(agentStats.size()); - for (TestAgentStat agentStat : agentStats) { - valueBuffer.putLong(agentStat.getTimestamp()); - valueBuffer.putLong(agentStat.getValue()); - } - } - - @Override - public List decodeValues(Buffer valueBuffer, AgentStatDecodingContext decodingContext) { - int size = valueBuffer.readInt(); - List agentStats = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - TestAgentStat agentStat = new TestAgentStat(); - agentStat.setAgentId(decodingContext.getAgentId()); - agentStat.setTimestamp(valueBuffer.readLong()); - agentStat.setValue(valueBuffer.readLong()); - agentStats.add(agentStat); - } - return agentStats; - } - } - - private static class TestAgentStatEncoder extends AgentStatEncoder { - protected TestAgentStatEncoder(AgentStatCodec codec) { - super(codec); - } - } - - private static class TestAgentStatDecoder extends AgentStatDecoder { - protected TestAgentStatDecoder(AgentStatCodec codec) { - super(List.of(codec)); - } - } - - private static class TestAgentStatSerializer extends AgentStatSerializer { - protected TestAgentStatSerializer(AgentStatEncoder encoder) { - super(encoder); - } - } - - private static class TestAgentStat implements AgentStatDataPoint { - - private String applicationName; - private String agentId; - private long startTimestamp; - private long timestamp; - private long value; - - @Override - public String getAgentId() { - return this.agentId; - } - - @Override - public void setAgentId(String agentId) { - this.agentId = agentId; - } - - @Override - public long getStartTimestamp() { - return startTimestamp; - } - - @Override - public void setStartTimestamp(long startTimestamp) { - this.startTimestamp = startTimestamp; - } - - @Override - public long getTimestamp() { - return this.timestamp; - } - - @Override - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - - public long getValue() { - return this.value; - } - - public void setValue(long value) { - this.value = value; - } - - @Override - public AgentStatType getAgentStatType() { - return AGENT_STAT_TYPE; - } - - @Override - public String getApplicationName() { - return this.applicationName; - } - - @Override - public void setApplicationName(String applicationName) { - this.applicationName = applicationName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - TestAgentStat that = (TestAgentStat) o; - - if (startTimestamp != that.startTimestamp) return false; - if (timestamp != that.timestamp) return false; - if (value != that.value) return false; - return agentId != null ? agentId.equals(that.agentId) : that.agentId == null; - - } - - @Override - public int hashCode() { - int result = agentId != null ? agentId.hashCode() : 0; - result = 31 * result + (int) (startTimestamp ^ (startTimestamp >>> 32)); - result = 31 * result + (int) (timestamp ^ (timestamp >>> 32)); - result = 31 * result + (int) (value ^ (value >>> 32)); - return result; - } - - @Override - public String toString() { - return "TestAgentStat{" + - "agentId='" + agentId + '\'' + - ", startTimestamp=" + startTimestamp + - ", timestamp=" + timestamp + - ", value=" + value + - '}'; - } - } -} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/DataSourceSamplerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/DataSourceSamplerTest.java deleted file mode 100644 index 156030a4452b..000000000000 --- a/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/DataSourceSamplerTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2017 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.web.mapper.stat; - -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceBo; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.DataSourceSampler; -import com.navercorp.pinpoint.web.test.util.DataSourceTestUtils; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSource; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.Random; - -/** - * @author Taejin Koo - */ -public class DataSourceSamplerTest { - - private static final int MIN_VALUE_OF_MAX_CONNECTION_SIZE = 20; - private static final int CREATE_TEST_OBJECT_MAX_SIZE = 10; - - private final DataSourceSampler sampler = new DataSourceSampler(); - private final Random random = new Random(); - - @Test - public void sampleDataPointsTest1() { - int testObjectSize = random.nextInt(1, CREATE_TEST_OBJECT_MAX_SIZE); - int maxConnectionSize = random.nextInt(MIN_VALUE_OF_MAX_CONNECTION_SIZE, MIN_VALUE_OF_MAX_CONNECTION_SIZE * 2); - List dataSourceBoList = DataSourceTestUtils.createDataSourceBoList(1, testObjectSize, maxConnectionSize); - - SampledDataSource sampledDataSource = sampler.sampleDataPoints(0, System.currentTimeMillis(), dataSourceBoList, null); - - assertEquals(sampledDataSource, dataSourceBoList); - } - - private void assertEquals(SampledDataSource sampledDataSource, List dataSourceBoList) { - int minActiveConnectionSize = Integer.MAX_VALUE; - int maxActiveConnectionSize = Integer.MIN_VALUE; - int sumActiveConnectionSize = 0; - - int minMaxConnectionSize = Integer.MAX_VALUE; - int maxMaxConnectionSize = Integer.MIN_VALUE; - int sumMaxConnectionSize = 0; - - for (DataSourceBo dataSourceBo : dataSourceBoList) { - int activeConnectionSize = dataSourceBo.getActiveConnectionSize(); - minActiveConnectionSize = Math.min(activeConnectionSize, minActiveConnectionSize); - maxActiveConnectionSize = Math.max(activeConnectionSize, maxActiveConnectionSize); - sumActiveConnectionSize += activeConnectionSize; - - int maxConnectionSize = dataSourceBo.getMaxConnectionSize(); - minMaxConnectionSize = Math.min(maxConnectionSize, minMaxConnectionSize); - maxMaxConnectionSize = Math.max(maxConnectionSize, maxMaxConnectionSize); - sumMaxConnectionSize += maxConnectionSize; - } - - Assertions.assertEquals((int) sampledDataSource.getActiveConnectionSize().getMinYVal(), minActiveConnectionSize); - Assertions.assertEquals((int) sampledDataSource.getActiveConnectionSize().getMaxYVal(), maxActiveConnectionSize); - Assertions.assertEquals((int) sampledDataSource.getActiveConnectionSize().getSumYVal(), sumActiveConnectionSize); - - Assertions.assertEquals((int) sampledDataSource.getMaxConnectionSize().getMinYVal(), minMaxConnectionSize); - Assertions.assertEquals((int) sampledDataSource.getMaxConnectionSize().getMaxYVal(), maxMaxConnectionSize); - Assertions.assertEquals((int) sampledDataSource.getMaxConnectionSize().getSumYVal(), sumMaxConnectionSize); - } - -} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/JvmGcSamplerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/JvmGcSamplerTest.java deleted file mode 100644 index 84960bfb8d57..000000000000 --- a/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/JvmGcSamplerTest.java +++ /dev/null @@ -1,479 +0,0 @@ -/* - * Copyright 2016 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.web.mapper.stat; - -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.JvmGcSampler; -import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.List; -import java.util.Random; - -/** - * @author HyunGil Jeong - */ -@ExtendWith(MockitoExtension.class) -public class JvmGcSamplerTest { - - private static final Random RANDOM = new Random(); - - private final JvmGcSampler sampler = new JvmGcSampler(); - - @Test - public void gcCalculation_singleDataPoint() { - // Given - long previousGcCount = randomGcCount(); - long previousGcTime = randomGcTime(); - JvmGcBo previousJvmGcBo = createJvmGcBoForGcTest(previousGcCount, previousGcTime); - - long gcCount = randomGcCount() + previousGcCount; - long gcTime = randomGcTime() + previousGcTime; - JvmGcBo jvmGcBo = createJvmGcBoForGcTest(gcCount, gcTime); - - List jvmGcBos = List.of(jvmGcBo); - - // When - SampledJvmGc sampledJvmGc = sampler.sampleDataPoints(0, System.currentTimeMillis(), jvmGcBos, previousJvmGcBo); - - // Then - long expectedGcCount = gcCount - previousGcCount; - long expectedGcTime = gcTime - previousGcTime; - long actualGcCount = sampledJvmGc.getGcOldCount().getSumYVal(); - long actualGcTime = sampledJvmGc.getGcOldTime().getSumYVal(); - Assertions.assertEquals(expectedGcCount, actualGcCount); - Assertions.assertEquals(expectedGcTime, actualGcTime); - } - - @Test - public void gcCalculation_singleDataPoint_noPrevious() { - // Given - long gcCount = randomGcCount(); - long gcTime = randomGcTime(); - JvmGcBo jvmGcBo = createJvmGcBoForGcTest(gcCount, gcTime); - - List jvmGcBos = List.of(jvmGcBo); - - // When - SampledJvmGc sampledJvmGc = sampler.sampleDataPoints(0, System.currentTimeMillis(), jvmGcBos, null); - - // Then - long expectedGcCount = 0L; - long expectedGcTime = 0L; - long actualGcCount = sampledJvmGc.getGcOldCount().getSumYVal(); - long actualGcTime = sampledJvmGc.getGcOldTime().getSumYVal(); - Assertions.assertEquals(expectedGcCount, actualGcCount); - Assertions.assertEquals(expectedGcTime, actualGcTime); - } - - @Test - public void gcCalculation_multipleDataPoints() { - // Given - long previousGcCount = randomGcCount(); - long previousGcTime = randomGcTime(); - JvmGcBo previousJvmGcBo = createJvmGcBoForGcTest(previousGcCount, previousGcTime); - - long firstGcCount = randomGcCount() + previousGcCount; - long firstGcTime = randomGcTime() + previousGcTime; - JvmGcBo firstJvmGcBo = createJvmGcBoForGcTest(firstGcCount, firstGcTime); - long secondGcCount = randomGcCount() + firstGcCount; - long secondGcTime = randomGcTime() + firstGcTime; - JvmGcBo secondJvmGcBo = createJvmGcBoForGcTest(secondGcCount, secondGcTime); - - // must be in descending order - List jvmGcBos = List.of(secondJvmGcBo, firstJvmGcBo); - - // When - SampledJvmGc sampledJvmGc = sampler.sampleDataPoints(0, System.currentTimeMillis(), jvmGcBos, previousJvmGcBo); - - // Then - long expectedGcCount = secondGcCount - previousGcCount; - long expectedGcTime = secondGcTime - previousGcTime; - long actualGcCount = sampledJvmGc.getGcOldCount().getSumYVal(); - long actualGcTime = sampledJvmGc.getGcOldTime().getSumYVal(); - Assertions.assertEquals(expectedGcCount, actualGcCount); - Assertions.assertEquals(expectedGcTime, actualGcTime); - } - - @Test - public void gcCalculation_multipleDataPoints_noPrevious() { - // Given - long firstGcCount = randomGcCount(); - long firstGcTime = randomGcTime(); - JvmGcBo firstJvmGcBo = createJvmGcBoForGcTest(firstGcCount, firstGcTime); - long secondGcCount = randomGcCount() + firstGcCount; - long secondGcTime = randomGcTime() + firstGcTime; - JvmGcBo secondJvmGcBo = createJvmGcBoForGcTest(secondGcCount, secondGcTime); - - // must be in descending order - List jvmGcBos = List.of(secondJvmGcBo, firstJvmGcBo); - - // When - SampledJvmGc sampledJvmGc = sampler.sampleDataPoints(0, System.currentTimeMillis(), jvmGcBos, null); - - // Then - long expectedGcCount = secondGcCount - firstGcCount; - long expectedGcTime = secondGcTime - firstGcTime; - long actualGcCount = sampledJvmGc.getGcOldCount().getSumYVal(); - long actualGcTime = sampledJvmGc.getGcOldTime().getSumYVal(); - Assertions.assertEquals(expectedGcCount, actualGcCount); - Assertions.assertEquals(expectedGcTime, actualGcTime); - } - - @Test - public void gcCalculation_jvmRestarts() { - // Given - long firstAgentStartTimestamp = 10L; - long secondAgentStartTimestamp = 1000L; - - long previousGcCount = randomGcCount(); - long previousGcTime = randomGcTime(); - JvmGcBo previousJvmGcBo = createJvmGcBoForGcTest(firstAgentStartTimestamp, previousGcCount, previousGcTime); - - long firstGcCount_1 = randomGcCount() + previousGcCount; - long firstGcTime_1 = randomGcTime() + previousGcTime; - JvmGcBo firstJvmGcBo_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, firstGcCount_1, firstGcTime_1); - long secondGcCount_1 = randomGcCount() + firstGcCount_1; - long secondGcTime_1 = randomGcTime() + firstGcTime_1; - JvmGcBo secondJvmGcBo_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, secondGcCount_1, secondGcTime_1); - - long firstGcCount_2 = randomGcCount(); - long firstGcTime_2 = randomGcTime(); - JvmGcBo firstJvmGcBo_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, firstGcCount_2, firstGcTime_2); - long secondGcCount_2 = randomGcCount() + firstGcCount_2; - long secondGcTime_2 = randomGcTime() + firstGcTime_2; - JvmGcBo secondJvmGcBo_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, secondGcCount_2, secondGcTime_2); - - // must be in descending order - List jvmGcBos = List.of(secondJvmGcBo_2, firstJvmGcBo_2, secondJvmGcBo_1, firstJvmGcBo_1); - - // When - SampledJvmGc sampledJvmGc = sampler.sampleDataPoints(0, System.currentTimeMillis(), jvmGcBos, previousJvmGcBo); - - // Then - long gcCountsBeforeJvmRestart = secondGcCount_1 - previousGcCount; - long gcCountsAfterJvmRestart = secondGcCount_2; - long gcTimesBeforeJvmRestart = secondGcTime_1 - previousGcTime; - long gcTimesAfterJvmRestart = secondGcTime_2; - long expectedGcCount = gcCountsBeforeJvmRestart + gcCountsAfterJvmRestart; - long expectedGcTime = gcTimesBeforeJvmRestart + gcTimesAfterJvmRestart; - long actualGcCount = sampledJvmGc.getGcOldCount().getSumYVal(); - long actualGcTime = sampledJvmGc.getGcOldTime().getSumYVal(); - Assertions.assertEquals(expectedGcCount, actualGcCount); - Assertions.assertEquals(expectedGcTime, actualGcTime); - } - - @Test - public void gcCalculation_jvmRestarts_noPrevious() { - // Given - long firstAgentStartTimestamp = 10L; - long secondAgentStartTimestamp = 1000L; - - long firstGcCount_1 = randomGcCount(); - long firstGcTime_1 = randomGcTime(); - JvmGcBo firstJvmGcBo_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, firstGcCount_1, firstGcTime_1); - long secondGcCount_1 = randomGcCount() + firstGcCount_1; - long secondGcTime_1 = randomGcTime() + firstGcTime_1; - JvmGcBo secondJvmGcBo_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, secondGcCount_1, secondGcTime_1); - - long firstGcCount_2 = randomGcCount(); - long firstGcTime_2 = randomGcTime(); - JvmGcBo firstJvmGcBo_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, firstGcCount_2, firstGcTime_2); - long secondGcCount_2 = randomGcCount() + firstGcCount_2; - long secondGcTime_2 = randomGcTime() + firstGcTime_2; - JvmGcBo secondJvmGcBo_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, secondGcCount_2, secondGcTime_2); - - // must be in descending order - List jvmGcBos = List.of(secondJvmGcBo_2, firstJvmGcBo_2, secondJvmGcBo_1, firstJvmGcBo_1); - - // When - SampledJvmGc sampledJvmGc = sampler.sampleDataPoints(0, System.currentTimeMillis(), jvmGcBos, null); - - // Then - long gcCountsBeforeJvmRestart = secondGcCount_1 - firstGcCount_1; - long gcCountsAfterJvmRestart = secondGcCount_2; - long gcTimesBeforeJvmRestart = secondGcTime_1 - firstGcTime_1; - long gcTimesAfterJvmRestart = secondGcTime_2; - long expectedGcCount = gcCountsBeforeJvmRestart + gcCountsAfterJvmRestart; - long expectedGcTime = gcTimesBeforeJvmRestart + gcTimesAfterJvmRestart; - long actualGcCount = sampledJvmGc.getGcOldCount().getSumYVal(); - long actualGcTime = sampledJvmGc.getGcOldTime().getSumYVal(); - Assertions.assertEquals(expectedGcCount, actualGcCount); - Assertions.assertEquals(expectedGcTime, actualGcTime); - } - - @Test - public void gcCalculation_uncollectedValues() { - // Given - long previousGcCount = randomGcCount(); - long previousGcTime = randomGcTime(); - JvmGcBo previousJvmGcBo = createJvmGcBoForGcTest(previousGcCount, previousGcTime); - - JvmGcBo uncollectedJvmGcBo1 = createJvmGcBoForGcTest(JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - long firstGcCount = randomGcCount() + previousGcCount; - long firstGcTime = randomGcTime() + previousGcTime; - JvmGcBo firstJvmGcBo = createJvmGcBoForGcTest(firstGcCount, firstGcTime); - JvmGcBo uncollectedJvmGcBo2 = createJvmGcBoForGcTest(JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - JvmGcBo uncollectedJvmGcBo3 = createJvmGcBoForGcTest(JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - long secondGcCount = randomGcCount() + firstGcCount; - long secondGcTime = randomGcTime() + firstGcTime; - JvmGcBo secondJvmGcBo = createJvmGcBoForGcTest(secondGcCount, secondGcTime); - - // must be in descending order - List jvmGcBos = List.of(secondJvmGcBo, uncollectedJvmGcBo3, uncollectedJvmGcBo2, firstJvmGcBo, uncollectedJvmGcBo1); - - // When - SampledJvmGc sampledJvmGc = sampler.sampleDataPoints(0, System.currentTimeMillis(), jvmGcBos, previousJvmGcBo); - - // Then - long expectedGcCount = secondGcCount - previousGcCount; - long expectedGcTime = secondGcTime - previousGcTime; - long actualGcCount = sampledJvmGc.getGcOldCount().getSumYVal(); - long actualGcTime = sampledJvmGc.getGcOldTime().getSumYVal(); - Assertions.assertEquals(expectedGcCount, actualGcCount); - Assertions.assertEquals(expectedGcTime, actualGcTime); - } - - @Test - public void gcCalculation_uncollectedValues_noPrevious() { - // Given - long firstGcCount = randomGcCount(); - long firstGcTime = randomGcTime(); - JvmGcBo firstJvmGcBo = createJvmGcBoForGcTest(firstGcCount, firstGcTime); - JvmGcBo uncollectedJvmGcBo1 = createJvmGcBoForGcTest(JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - JvmGcBo uncollectedJvmGcBo2 = createJvmGcBoForGcTest(JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - long secondGcCount = randomGcCount() + firstGcCount; - long secondGcTime = randomGcTime() + firstGcTime; - JvmGcBo secondJvmGcBo = createJvmGcBoForGcTest(secondGcCount, secondGcTime); - JvmGcBo uncollectedJvmGcBo3 = createJvmGcBoForGcTest(JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - // must be in descending order - List jvmGcBos = List.of(uncollectedJvmGcBo3, secondJvmGcBo, uncollectedJvmGcBo2, uncollectedJvmGcBo1, firstJvmGcBo); - - // When - SampledJvmGc sampledJvmGc = sampler.sampleDataPoints(0, System.currentTimeMillis(), jvmGcBos, null); - - // Then - long expectedGcCount = secondGcCount - firstGcCount; - long expectedGcTime = secondGcTime - firstGcTime; - long actualGcCount = sampledJvmGc.getGcOldCount().getSumYVal(); - long actualGcTime = sampledJvmGc.getGcOldTime().getSumYVal(); - Assertions.assertEquals(expectedGcCount, actualGcCount); - Assertions.assertEquals(expectedGcTime, actualGcTime); - - } - - @Test - public void gcCalculation_uncollectedValues_previousUncollectedValue() { - // Given - JvmGcBo previousJvmGcBo = createJvmGcBoForGcTest(JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - - JvmGcBo uncollectedJvmGcBo1 = createJvmGcBoForGcTest(JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - long firstGcCount = randomGcCount(); - long firstGcTime = randomGcTime(); - JvmGcBo firstJvmGcBo = createJvmGcBoForGcTest(firstGcCount, firstGcTime); - JvmGcBo uncollectedJvmGcBo2 = createJvmGcBoForGcTest(JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - long secondGcCount = randomGcCount() + firstGcCount; - long secondGcTime = randomGcTime() + firstGcTime; - JvmGcBo secondJvmGcBo = createJvmGcBoForGcTest(secondGcCount, secondGcTime); - - // must be in descending order - List jvmGcBos = List.of(secondJvmGcBo, uncollectedJvmGcBo2, firstJvmGcBo, uncollectedJvmGcBo1); - - // When - SampledJvmGc sampledJvmGc = sampler.sampleDataPoints(0, System.currentTimeMillis(), jvmGcBos, previousJvmGcBo); - - // Then - long expectedGcCount = secondGcCount - firstGcCount; - long expectedGcTime = secondGcTime - firstGcTime; - long actualGcCount = sampledJvmGc.getGcOldCount().getSumYVal(); - long actualGcTime = sampledJvmGc.getGcOldTime().getSumYVal(); - Assertions.assertEquals(expectedGcCount, actualGcCount); - Assertions.assertEquals(expectedGcTime, actualGcTime); - } - - @Test - public void gcCalculation_jvmRestarts_uncollectedValues() { - // Given - long firstAgentStartTimestamp = 10L; - long secondAgentStartTimestamp = 1000L; - - long previousGcCount = randomGcCount(); - long previousGcTime = randomGcTime(); - JvmGcBo previousJvmGcBo = createJvmGcBoForGcTest(firstAgentStartTimestamp, previousGcCount, previousGcTime); - - JvmGcBo uncollectedJvmGcBo1_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - long firstGcCount_1 = randomGcCount() + previousGcCount; - long firstGcTime_1 = randomGcTime() + previousGcTime; - JvmGcBo firstJvmGcBo_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, firstGcCount_1, firstGcTime_1); - JvmGcBo uncollectedJvmGcBo2_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - - JvmGcBo uncollectedJvmGcBo1_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - long firstGcCount_2 = randomGcCount(); - long firstGcTime_2 = randomGcTime(); - JvmGcBo firstJvmGcBo_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, firstGcCount_2, firstGcTime_2); - long secondGcCount_2 = randomGcCount() + firstGcCount_2; - long secondGcTime_2 = randomGcTime() + firstGcTime_2; - JvmGcBo secondJvmGcBo_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, secondGcCount_2, secondGcTime_2); - long thirdGcCount_2 = randomGcCount() + secondGcCount_2; - long thirdGcTime_2 = randomGcCount() + secondGcTime_2; - JvmGcBo thirdJvmGcBo_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, thirdGcCount_2, thirdGcTime_2); - JvmGcBo uncollectedJvmGcBo2_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - - // must be in descending order - List jvmGcBos = List.of( - uncollectedJvmGcBo2_2, thirdJvmGcBo_2, secondJvmGcBo_2, firstJvmGcBo_2, uncollectedJvmGcBo1_2, - uncollectedJvmGcBo2_1, firstJvmGcBo_1, uncollectedJvmGcBo1_1 - ); - - // When - SampledJvmGc sampledJvmGc = sampler.sampleDataPoints(0, System.currentTimeMillis(), jvmGcBos, previousJvmGcBo); - - // Then - long gcCountsBeforeJvmRestart = firstGcCount_1 - previousGcCount; - long gcCountsAfterJvmRestart = thirdGcCount_2; - long gcTimesBeforeJvmRestart = firstGcTime_1 - previousGcTime; - long gcTimesAfterJvmRestart = thirdGcTime_2; - long expectedGcCount = gcCountsBeforeJvmRestart + gcCountsAfterJvmRestart; - long expectedGcTime = gcTimesBeforeJvmRestart + gcTimesAfterJvmRestart; - long actualGcCount = sampledJvmGc.getGcOldCount().getSumYVal(); - long actualGcTime = sampledJvmGc.getGcOldTime().getSumYVal(); - Assertions.assertEquals(expectedGcCount, actualGcCount); - Assertions.assertEquals(expectedGcTime, actualGcTime); - } - - @Test - public void gcCalculation_jvmRestarts_uncollectedValues_noPrevious() { - // Given - long firstAgentStartTimestamp = 10L; - long secondAgentStartTimestamp = 1000L; - - JvmGcBo uncollectedJvmGcBo1_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - long firstGcCount_1 = randomGcCount(); - long firstGcTime_1 = randomGcTime(); - JvmGcBo firstJvmGcBo_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, firstGcCount_1, firstGcTime_1); - JvmGcBo uncollectedJvmGcBo2_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - - long firstGcCount_2 = randomGcCount(); - long firstGcTime_2 = randomGcTime(); - JvmGcBo firstJvmGcBo_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, firstGcCount_2, firstGcTime_2); - JvmGcBo uncollectedJvmGcBo1_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - long secondGcCount_2 = randomGcCount() + firstGcCount_2; - long secondGcTime_2 = randomGcTime() + firstGcTime_2; - JvmGcBo secondJvmGcBo_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, secondGcCount_2, secondGcTime_2); - long thirdGcCount_2 = randomGcCount() + secondGcCount_2; - long thirdGcTime_2 = randomGcCount() + secondGcTime_2; - JvmGcBo thirdJvmGcBo_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, thirdGcCount_2, thirdGcTime_2); - JvmGcBo uncollectedJvmGcBo2_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - - // must be in descending order - List jvmGcBos = List.of( - uncollectedJvmGcBo2_2, thirdJvmGcBo_2, secondJvmGcBo_2, uncollectedJvmGcBo1_2, firstJvmGcBo_2, - uncollectedJvmGcBo2_1, firstJvmGcBo_1, uncollectedJvmGcBo1_1 - ); - - // When - SampledJvmGc sampledJvmGc = sampler.sampleDataPoints(0, System.currentTimeMillis(), jvmGcBos, null); - - // Then - long gcCountsBeforeJvmRestart = 0L; - long gcCountsAfterJvmRestart = thirdGcCount_2; - long gcTimesBeforeJvmRestart = 0L; - long gcTimesAfterJvmRestart = thirdGcTime_2; - long expectedGcCount = gcCountsBeforeJvmRestart + gcCountsAfterJvmRestart; - long expectedGcTime = gcTimesBeforeJvmRestart + gcTimesAfterJvmRestart; - long actualGcCount = sampledJvmGc.getGcOldCount().getSumYVal(); - long actualGcTime = sampledJvmGc.getGcOldTime().getSumYVal(); - Assertions.assertEquals(expectedGcCount, actualGcCount); - Assertions.assertEquals(expectedGcTime, actualGcTime); - } - - @Test - public void gcCalculation_jvmRestarts_uncollectedValues_previousUncollectedValue() { - // Given - long firstAgentStartTimestamp = 10L; - long secondAgentStartTimestamp = 1000L; - - JvmGcBo previousJvmGcBo = createJvmGcBoForGcTest(firstAgentStartTimestamp, JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - - JvmGcBo uncollectedJvmGcBo1_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - long firstGcCount_1 = randomGcCount(); - long firstGcTime_1 = randomGcTime(); - JvmGcBo firstJvmGcBo_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, firstGcCount_1, firstGcTime_1); - long secondGcCount_1 = randomGcCount() + firstGcCount_1; - long secondGcTime_1 = randomGcTime() + firstGcTime_1; - JvmGcBo secondJvmGcBo_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, secondGcCount_1, secondGcTime_1); - JvmGcBo uncollectedJvmGcBo2_1 = createJvmGcBoForGcTest(firstAgentStartTimestamp, JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - - long firstGcCount_2 = randomGcCount(); - long firstGcTime_2 = randomGcTime(); - JvmGcBo firstJvmGcBo_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, firstGcCount_2, firstGcTime_2); - JvmGcBo uncollectedJvmGcBo1_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - long secondGcCount_2 = randomGcCount() + firstGcCount_2; - long secondGcTime_2 = randomGcTime() + firstGcTime_2; - JvmGcBo secondJvmGcBo_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, secondGcCount_2, secondGcTime_2); - long thirdGcCount_2 = randomGcCount() + secondGcCount_2; - long thirdGcTime_2 = randomGcCount() + secondGcTime_2; - JvmGcBo thirdJvmGcBo_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, thirdGcCount_2, thirdGcTime_2); - JvmGcBo uncollectedJvmGcBo2_2 = createJvmGcBoForGcTest(secondAgentStartTimestamp, JvmGcBo.UNCOLLECTED_VALUE, JvmGcBo.UNCOLLECTED_VALUE); - - // must be in descending order - List jvmGcBos = List.of( - uncollectedJvmGcBo2_2, thirdJvmGcBo_2, secondJvmGcBo_2, uncollectedJvmGcBo1_2, firstJvmGcBo_2, - uncollectedJvmGcBo2_1, secondJvmGcBo_1, firstJvmGcBo_1, uncollectedJvmGcBo1_1 - ); - - // When - SampledJvmGc sampledJvmGc = sampler.sampleDataPoints(0, System.currentTimeMillis(), jvmGcBos, previousJvmGcBo); - - // Then - long gcCountsBeforeJvmRestart = secondGcCount_1 - firstGcCount_1; - long gcCountsAfterJvmRestart = thirdGcCount_2; - long gcTimesBeforeJvmRestart = secondGcTime_1 - firstGcTime_1; - long gcTimesAfterJvmRestart = thirdGcTime_2; - long expectedGcCount = gcCountsBeforeJvmRestart + gcCountsAfterJvmRestart; - long expectedGcTime = gcTimesBeforeJvmRestart + gcTimesAfterJvmRestart; - long actualGcCount = sampledJvmGc.getGcOldCount().getSumYVal(); - long actualGcTime = sampledJvmGc.getGcOldTime().getSumYVal(); - Assertions.assertEquals(expectedGcCount, actualGcCount); - Assertions.assertEquals(expectedGcTime, actualGcTime); - - } - - private JvmGcBo createJvmGcBoForGcTest(long gcOldCount, long gcOldTime) { - JvmGcBo jvmGcBo = new JvmGcBo(); - jvmGcBo.setGcOldCount(gcOldCount); - jvmGcBo.setGcOldTime(gcOldTime); - return jvmGcBo; - } - - private JvmGcBo createJvmGcBoForGcTest(long startTimestamp, long gcOldCount, long gcOldTime) { - JvmGcBo jvmGcBo = createJvmGcBoForGcTest(gcOldCount, gcOldTime); - jvmGcBo.setStartTimestamp(startTimestamp); - return jvmGcBo; - } - - private int randomGcCount() { - return RANDOM.nextInt(10); - } - - private int randomGcTime() { - return RANDOM.nextInt(10000); - } -} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractorTest.java b/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractorTest.java deleted file mode 100644 index 2b7f1d7c8930..000000000000 --- a/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractorTest.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright 2016 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.web.mapper.stat; - -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; -import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.AgentStatSampler; -import com.navercorp.pinpoint.common.server.util.timewindow.FixedTimeWindowSampler; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindowSampler; -import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; -import org.apache.hadoop.hbase.client.Result; -import org.apache.hadoop.hbase.client.ResultScanner; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.mockito.Mockito.when; - -/** - * @author HyunGil Jeong - */ -@ExtendWith(MockitoExtension.class) -public class SampledAgentStatResultExtractorTest { - - private static final long DEFAULT_TIME_INTERVAL = 5 * 1000L; - - private static final TimeWindowSampler ONE_TO_ONE_SAMPLER = new FixedTimeWindowSampler(DEFAULT_TIME_INTERVAL); - private static final TimeWindowSampler TWO_TO_ONE_SAMPLER = new FixedTimeWindowSampler(DEFAULT_TIME_INTERVAL * 2); - private static final TimeWindowSampler TEN_TO_ONE_SAMPLER = new FixedTimeWindowSampler(DEFAULT_TIME_INTERVAL * 10); - - @Mock - private ResultScanner resultScanner; - - @Mock - private Result result; - - @Mock - private AgentStatMapperV2 rowMapper; - - @BeforeEach - public void beforeEach() { - when(this.resultScanner.iterator()).thenReturn(List.of(this.result).iterator()); - } - - @Test - public void one_to_one_sampler_should_not_down_sample_data_points() throws Exception { - // Given - final int numValues = 10; - final long initialTimestamp = System.currentTimeMillis(); - final long finalTimestamp = initialTimestamp + (DEFAULT_TIME_INTERVAL * numValues); - final TimeWindow timeWindow = new TimeWindow(Range.between(initialTimestamp, finalTimestamp), ONE_TO_ONE_SAMPLER); - final List dataPoints = createDataPoints(finalTimestamp, DEFAULT_TIME_INTERVAL, numValues); - final Map> expectedDataPointSlotMap = getExpectedDataPointSlotMap(timeWindow, dataPoints); - when(this.rowMapper.mapRow(this.result, 0)).thenReturn(dataPoints); - - TestAgentStatSampler testAgentStatSampler = new TestAgentStatSampler(); - SampledAgentStatResultExtractor resultExtractor - = new SampledAgentStatResultExtractor<>(timeWindow, this.rowMapper, testAgentStatSampler); - // When - List sampledDataPoints = resultExtractor.extractData(this.resultScanner); - // Then - for (TestSampledAgentStatDataPoint sampledDataPoint : sampledDataPoints) { - List expectedSampledDataPoints = expectedDataPointSlotMap.get(sampledDataPoint.getBaseTimestamp()); - Assertions.assertEquals(expectedSampledDataPoints, sampledDataPoint.getDataPointsToSample()); - } - } - - @Test - public void two_to_one_sample_should_down_sample_correctly() throws Exception { - // Given - final int numValues = 20; - final long initialTimestamp = System.currentTimeMillis(); - final long finalTimestamp = initialTimestamp + (DEFAULT_TIME_INTERVAL * numValues); - final TimeWindow timeWindow = new TimeWindow(Range.between(initialTimestamp, finalTimestamp), TWO_TO_ONE_SAMPLER); - final List dataPoints = createDataPoints(finalTimestamp, DEFAULT_TIME_INTERVAL, numValues); - final Map> expectedDataPointSlotMap = getExpectedDataPointSlotMap(timeWindow, dataPoints); - when(this.rowMapper.mapRow(this.result, 0)).thenReturn(dataPoints); - - TestAgentStatSampler testAgentStatSampler = new TestAgentStatSampler(); - SampledAgentStatResultExtractor resultExtractor - = new SampledAgentStatResultExtractor<>(timeWindow, this.rowMapper, testAgentStatSampler); - // When - List sampledDataPoints = resultExtractor.extractData(this.resultScanner); - // Then - for (TestSampledAgentStatDataPoint sampledDataPoint : sampledDataPoints) { - List expectedSampledDataPoints = expectedDataPointSlotMap.get(sampledDataPoint.getBaseTimestamp()); - Assertions.assertEquals(expectedSampledDataPoints, sampledDataPoint.getDataPointsToSample()); - } - } - - @Test - public void ten_to_one_sample_should_down_sample_correctly() throws Exception { - // Given - final int numValues = 100; - final long initialTimestamp = System.currentTimeMillis(); - final long finalTimestamp = initialTimestamp + (DEFAULT_TIME_INTERVAL * numValues); - final TimeWindow timeWindow = new TimeWindow(Range.between(initialTimestamp, finalTimestamp), TEN_TO_ONE_SAMPLER); - final List dataPoints = createDataPoints(finalTimestamp, DEFAULT_TIME_INTERVAL, numValues); - final Map> expectedDataPointSlotMap = getExpectedDataPointSlotMap(timeWindow, dataPoints); - when(this.rowMapper.mapRow(this.result, 0)).thenReturn(dataPoints); - - TestAgentStatSampler testAgentStatSampler = new TestAgentStatSampler(); - SampledAgentStatResultExtractor resultExtractor - = new SampledAgentStatResultExtractor<>(timeWindow, this.rowMapper, testAgentStatSampler); - // When - List sampledDataPoints = resultExtractor.extractData(this.resultScanner); - // Then - for (TestSampledAgentStatDataPoint sampledDataPoint : sampledDataPoints) { - List expectedSampledDataPoints = expectedDataPointSlotMap.get(sampledDataPoint.getBaseTimestamp()); - Assertions.assertEquals(expectedSampledDataPoints, sampledDataPoint.getDataPointsToSample()); - } - } - - private Map> getExpectedDataPointSlotMap(TimeWindow timeWindow, List dataPoints) { - Map> slotMap = new HashMap<>(); - for (long timeslotTimestamp : timeWindow) { - slotMap.put(timeslotTimestamp, new ArrayList()); - } - for (TestAgentStatDataPoint dataPoint : dataPoints) { - slotMap.get(timeWindow.refineTimestamp(dataPoint.getTimestamp())).add(dataPoint); - } - return slotMap; - } - - private List createDataPoints(long finalTimestamp, long timeInterval, int numDataPoints) { - List dataPoints = new ArrayList<>(numDataPoints); - for (int i = 0; i < numDataPoints; i++) { - TestAgentStatDataPoint dataPoint = new TestAgentStatDataPoint(); - dataPoint.setTimestamp(finalTimestamp - (timeInterval * i)); - dataPoint.setValue(i); - dataPoints.add(dataPoint); - } - return dataPoints; - } - - private static class TestAgentStatSampler implements AgentStatSampler { - - @Override - public TestSampledAgentStatDataPoint sampleDataPoints(int timeWindowIndex, long timestamp, List dataPoints, TestAgentStatDataPoint previousDataPoint) { - return new TestSampledAgentStatDataPoint(timestamp, dataPoints); - } - } - - private static class TestAgentStatDataPoint implements AgentStatDataPoint { - - private String applicationName; - private String agentId; - private long startTimestamp; - private long timestamp; - private int value; - - @Override - public String getAgentId() { - return agentId; - } - - @Override - public void setAgentId(String agentId) { - this.agentId = agentId; - } - - @Override - public long getStartTimestamp() { - return startTimestamp; - } - - @Override - public void setStartTimestamp(long startTimestamp) { - this.startTimestamp = startTimestamp; - } - - @Override - public long getTimestamp() { - return timestamp; - } - - @Override - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - - @Override - public AgentStatType getAgentStatType() { - return AgentStatType.UNKNOWN; - } - - @Override - public String getApplicationName() { - return applicationName; - } - - @Override - public void setApplicationName(String applicationName) { - this.applicationName = applicationName; - } - - public int getValue() { - return value; - } - - public void setValue(int value) { - this.value = value; - } - - @Override - public String toString() { - return "TestAgentStatDataPoint{" + - "agentId='" + agentId + '\'' + - ", startTimestamp=" + startTimestamp + - ", timestamp=" + timestamp + - ", value=" + value + - '}'; - } - } - - private static class TestSampledAgentStatDataPoint implements SampledAgentStatDataPoint { - private final long baseTimestamp; - private final List dataPointsToSample; - - private TestSampledAgentStatDataPoint(long baseTimestamp, List dataPointsToSample) { - this.baseTimestamp = baseTimestamp; - this.dataPointsToSample = dataPointsToSample; - } - - public long getBaseTimestamp() { - return baseTimestamp; - } - - public List getDataPointsToSample() { - return dataPointsToSample; - } - - @Override - public String toString() { - return "TestSampledAgentStatDataPoint{" + - "baseTimestamp=" + baseTimestamp + - ", dataPointsToSample=" + dataPointsToSample + - '}'; - } - } -} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/service/ApplicationAgentListServiceImplTest.java b/web/src/test/java/com/navercorp/pinpoint/web/service/ApplicationAgentListServiceImplTest.java index 68efd28fa915..6bba088abd12 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/service/ApplicationAgentListServiceImplTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/service/ApplicationAgentListServiceImplTest.java @@ -82,7 +82,6 @@ public void setup() { LegacyAgentCompatibility legacyAgentCompatibility = mock(LegacyAgentCompatibility.class); lenient().when(legacyAgentCompatibility.isLegacyAgent(ArgumentMatchers.anyShort(), ArgumentMatchers.any())).thenReturn(false); - lenient().when(legacyAgentCompatibility.isActiveAgent(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(false); applicationAgentListService = new ApplicationAgentListServiceImpl(applicationIndexDao, agentInfoDao, agentLifeCycleDao, legacyAgentCompatibility, mapResponseDao); } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/service/component/DefaultActiveAgentValidatorTest.java b/web/src/test/java/com/navercorp/pinpoint/web/service/component/DefaultActiveAgentValidatorTest.java index 3918242632b2..38234fbf2b73 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/service/component/DefaultActiveAgentValidatorTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/service/component/DefaultActiveAgentValidatorTest.java @@ -1,10 +1,8 @@ package com.navercorp.pinpoint.web.service.component; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; import com.navercorp.pinpoint.common.server.util.AgentEventType; import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.common.trace.ServiceTypeFactory; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; import com.navercorp.pinpoint.web.service.AgentEventService; import com.navercorp.pinpoint.web.vo.AgentEvent; import com.navercorp.pinpoint.web.vo.Application; @@ -17,7 +15,6 @@ import java.util.List; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -26,37 +23,32 @@ class DefaultActiveAgentValidatorTest { @Mock AgentEventService agentEventService; - @Mock - AgentStatDao jvmGcDao; Application node = new Application("testNodeApp", ServiceTypeFactory.of(1400, "node")); // Application java = new Application("testJavaApp", ServiceTypeFactory.of(1010, "java")); @Test void isActiveAgent_legacy_node() { - LegacyAgentCompatibility agentCompatibility = new DefaultLegacyAgentCompatibility(jvmGcDao); + LegacyAgentCompatibility agentCompatibility = new DefaultLegacyAgentCompatibility(); ActiveAgentValidator validator = new DefaultActiveAgentValidator(agentEventService, agentCompatibility); Assertions.assertFalse(validator.isActiveAgent(node, "0.7.0", Range.between(0, 1))); - - verify(jvmGcDao).agentStatExists(any(), any()); } @Test void isActiveAgent_legacy_node_with_gc() { - when(jvmGcDao.agentStatExists(any(), any())).thenReturn(true); - - LegacyAgentCompatibility agentCompatibility = new DefaultLegacyAgentCompatibility(jvmGcDao); + LegacyAgentCompatibility agentCompatibility = new DefaultLegacyAgentCompatibility(); ActiveAgentValidator validator = new DefaultActiveAgentValidator(agentEventService, agentCompatibility); - Assertions.assertTrue(validator.isActiveAgent(node, "0.7.0", Range.between(0, 1))); + AgentEvent gc = new AgentEvent("test", 1, 1, AgentEventType.AGENT_PING); + when(agentEventService.getAgentEvents(any(), any(), any())).thenReturn(List.of(gc)); - verify(jvmGcDao).agentStatExists(any(), any()); + Assertions.assertTrue(validator.isActiveAgent(node, "5.0.0", Range.between(0, 1))); } @Test void isActiveAgent_new_node_without_ping() { - LegacyAgentCompatibility agentCompatibility = new DefaultLegacyAgentCompatibility(jvmGcDao); + LegacyAgentCompatibility agentCompatibility = new DefaultLegacyAgentCompatibility(); ActiveAgentValidator validator = new DefaultActiveAgentValidator(agentEventService, agentCompatibility); Assertions.assertFalse(validator.isActiveAgent(node, "0.8.0", Range.between(0, 1))); @@ -69,11 +61,9 @@ void isActiveAgent_new_node_with_event() { AgentEvent ping = new AgentEvent("test", 1, 1, AgentEventType.AGENT_PING); when(agentEventService.getAgentEvents(any(), any(), any())).thenReturn(List.of(ping)); - LegacyAgentCompatibility agentCompatibility = new DefaultLegacyAgentCompatibility(jvmGcDao); + LegacyAgentCompatibility agentCompatibility = new DefaultLegacyAgentCompatibility(); ActiveAgentValidator validator = new DefaultActiveAgentValidator(agentEventService, agentCompatibility); Assertions.assertTrue(validator.isActiveAgent(node, "0.8.0", Range.between(0, 1))); - - verify(jvmGcDao, never()).agentStatExists(any(), any()); } } \ No newline at end of file diff --git a/web/src/test/java/com/navercorp/pinpoint/web/service/component/DefaultLegacyAgentCompatibilityTest.java b/web/src/test/java/com/navercorp/pinpoint/web/service/component/DefaultLegacyAgentCompatibilityTest.java index 5d079c038db4..9779a6b793f1 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/service/component/DefaultLegacyAgentCompatibilityTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/service/component/DefaultLegacyAgentCompatibilityTest.java @@ -1,7 +1,5 @@ package com.navercorp.pinpoint.web.service.component; -import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; -import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -11,9 +9,6 @@ @ExtendWith(MockitoExtension.class) class DefaultLegacyAgentCompatibilityTest { - @Mock - AgentStatDao jvmGcDao; - @Test void semver() { Semver version = Semver.parse("0.7.0"); @@ -25,7 +20,7 @@ void semver() { @Test void legacy_serviceType() { - LegacyAgentCompatibility compatibility = new DefaultLegacyAgentCompatibility(jvmGcDao); + LegacyAgentCompatibility compatibility = new DefaultLegacyAgentCompatibility(); Assertions.assertTrue(compatibility.isLegacyAgent(node)); @@ -35,7 +30,7 @@ void legacy_serviceType() { @Test void legacy_semver() { - LegacyAgentCompatibility compatibility = new DefaultLegacyAgentCompatibility(jvmGcDao); + LegacyAgentCompatibility compatibility = new DefaultLegacyAgentCompatibility(); Assertions.assertTrue(compatibility.isLegacyAgent(node, "0.7.0")); Assertions.assertTrue(compatibility.isLegacyAgent(node, "0.7.1")); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/view/DataSourceChartSerializerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/view/DataSourceChartSerializerTest.java deleted file mode 100644 index d1a9995eaf1c..000000000000 --- a/web/src/test/java/com/navercorp/pinpoint/web/view/DataSourceChartSerializerTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2018 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.web.view; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceBo; -import com.navercorp.pinpoint.common.server.util.json.Jackson; -import com.navercorp.pinpoint.common.server.util.json.TypeRef; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.DataSourceSampler; -import com.navercorp.pinpoint.web.test.util.DataSourceTestUtils; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSource; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.DataSourceChart; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -/** - * @author Taejin Koo - */ -@ExtendWith(MockitoExtension.class) -public class DataSourceChartSerializerTest { - - private static final int MIN_VALUE_OF_MAX_CONNECTION_SIZE = 20; - private static final int CREATE_TEST_OBJECT_MAX_SIZE = 10; - - private final DataSourceSampler sampler = new DataSourceSampler(); - - private final ObjectMapper mapper = Jackson.newMapper(); - private final Random random = new Random(); - - @Mock - private ServiceTypeRegistryService serviceTypeRegistryService; - - @BeforeEach - public void setUp() throws Exception { - when(serviceTypeRegistryService.findServiceType(any(Short.class))).thenReturn(ServiceType.UNKNOWN); - } - - @Test - public void serializeTest() throws Exception { - long currentTimeMillis = System.currentTimeMillis(); - TimeWindow timeWindow = new TimeWindow(Range.between(currentTimeMillis - 300000, currentTimeMillis)); - - List sampledDataSourceList = createSampledDataSourceList(timeWindow); - DataSourceChart dataSourceChartGroup = new DataSourceChart(timeWindow, sampledDataSourceList, serviceTypeRegistryService); - - String jsonValue = mapper.writeValueAsString(dataSourceChartGroup); - Map map = mapper.readValue(jsonValue, TypeRef.map()); - - org.assertj.core.api.Assertions.assertThat(map) - .containsKey("id") - .containsKey("jdbcUrl") - .containsKey("databaseName") - .containsKey("serviceType") - .containsKey("charts"); - - } - - private List createSampledDataSourceList(TimeWindow timeWindow) { - List sampledDataSourceList = new ArrayList<>(); - - int maxConnectionSize = random.nextInt(MIN_VALUE_OF_MAX_CONNECTION_SIZE, MIN_VALUE_OF_MAX_CONNECTION_SIZE * 2); - - long from = timeWindow.getWindowRange().getFrom(); - long to = timeWindow.getWindowRange().getTo(); - - for (long i = from; i < to; i += timeWindow.getWindowSlotSize()) { - sampledDataSourceList.add(createSampledDataSource(i, maxConnectionSize)); - } - - return sampledDataSourceList; - } - - private SampledDataSource createSampledDataSource(long timestamp, int maxConnectionSize) { - int testObjectSize = random.nextInt(1, CREATE_TEST_OBJECT_MAX_SIZE); - List dataSourceBoList = DataSourceTestUtils.createDataSourceBoList(1, testObjectSize, maxConnectionSize); - return sampler.sampleDataPoints(0, timestamp, dataSourceBoList, null); - } - -} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DataSourceChartGroupTest.java b/web/src/test/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DataSourceChartGroupTest.java deleted file mode 100644 index cc611cf42a13..000000000000 --- a/web/src/test/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DataSourceChartGroupTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2018 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.bo.stat.DataSourceBo; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.DataSourceSampler; -import com.navercorp.pinpoint.web.test.util.DataSourceTestUtils; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.vo.chart.Chart; -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.stat.SampledDataSource; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ThreadLocalRandom; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.lenient; - -/** - * @author Taejin Koo - */ -@ExtendWith(MockitoExtension.class) -public class DataSourceChartGroupTest { - - private static final int MIN_VALUE_OF_MAX_CONNECTION_SIZE = 20; - private static final int CREATE_TEST_OBJECT_MAX_SIZE = 10; - - private final DataSourceSampler sampler = new DataSourceSampler(); - - @Mock - private ServiceTypeRegistryService serviceTypeRegistryService; - - @BeforeEach - public void beforeEach() { - lenient().when(serviceTypeRegistryService.findServiceType(any(Short.class))) - .thenReturn(ServiceType.UNKNOWN); - } - - - @Test - public void basicFunctionTest1() { - long currentTimeMillis = System.currentTimeMillis(); - TimeWindow timeWindow = new TimeWindow(Range.between(currentTimeMillis - 300000, currentTimeMillis)); - - List sampledDataSourceList = createSampledDataSourceList(timeWindow); - StatChartGroup> dataSourceChartGroup = DataSourceChart.newDataSourceChartGroup(timeWindow, sampledDataSourceList, serviceTypeRegistryService); - - assertEquals(sampledDataSourceList, dataSourceChartGroup); - } - - @Test - public void basicFunctionTest2() { - long currentTimeMillis = System.currentTimeMillis(); - TimeWindow timeWindow = new TimeWindow(Range.between(currentTimeMillis - 300000, currentTimeMillis)); - - List sampledDataSourceList = List.of(); - DataSourceChart dataSourceChartGroup = new DataSourceChart(timeWindow, sampledDataSourceList, serviceTypeRegistryService); - - Assertions.assertEquals(-1, dataSourceChartGroup.getId()); - Assertions.assertNull(dataSourceChartGroup.getJdbcUrl()); - Assertions.assertNull(dataSourceChartGroup.getDatabaseName()); - Assertions.assertNull(dataSourceChartGroup.getServiceType()); - - Map>> charts = dataSourceChartGroup.getCharts().getCharts(); - assertThat(charts) - .hasSize(2) - .allSatisfy((chartType, chart) -> assertThat(chart.getPoints()).isEmpty()); - } - - private List createSampledDataSourceList(TimeWindow timeWindow) { - List sampledDataSourceList = new ArrayList<>(); - - int maxConnectionSize = ThreadLocalRandom.current().nextInt(MIN_VALUE_OF_MAX_CONNECTION_SIZE) + MIN_VALUE_OF_MAX_CONNECTION_SIZE; - - long from = timeWindow.getWindowRange().getFrom(); - long to = timeWindow.getWindowRange().getTo(); - - for (long i = from; i < to; i += timeWindow.getWindowSlotSize()) { - sampledDataSourceList.add(createSampledDataSource(i, maxConnectionSize)); - } - - return sampledDataSourceList; - } - - private SampledDataSource createSampledDataSource(long timestamp, int maxConnectionSize) { - int testObjectSize = ThreadLocalRandom.current().nextInt(CREATE_TEST_OBJECT_MAX_SIZE) + 1; - List dataSourceBoList = DataSourceTestUtils.createDataSourceBoList(1, testObjectSize, maxConnectionSize); - return sampler.sampleDataPoints(0, timestamp, dataSourceBoList, null); - } - - private void assertEquals(List sampledDataSourceList, StatChartGroup> dataSourceChartGroup) { - Map>> charts = dataSourceChartGroup.getCharts(); - - Chart activeConnectionSizeChart = charts.get(DataSourceChart.DataSourceChartType.ACTIVE_CONNECTION_SIZE); - List activeConnectionSizeChartPointList = activeConnectionSizeChart.getPoints(); - - for (int i = 0; i < sampledDataSourceList.size(); i++) { - SampledDataSource sampledDataSource = sampledDataSourceList.get(i); - Point point = sampledDataSource.getActiveConnectionSize(); - - Assertions.assertEquals(activeConnectionSizeChartPointList.get(i), point); - } - - Chart> maxConnectionSizeChart = charts.get(DataSourceChart.DataSourceChartType.MAX_CONNECTION_SIZE); - List> maxConnectionSizeChartPointList = maxConnectionSizeChart.getPoints(); - for (int i = 0; i < sampledDataSourceList.size(); i++) { - SampledDataSource sampledDataSource = sampledDataSourceList.get(i); - AgentStatPoint point = sampledDataSource.getMaxConnectionSize(); - - Assertions.assertEquals(maxConnectionSizeChartPointList.get(i), point); - } - } - -} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DeadlockChartGroupTest.java b/web/src/test/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DeadlockChartGroupTest.java deleted file mode 100644 index eadc5717aeaa..000000000000 --- a/web/src/test/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/DeadlockChartGroupTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.bo.stat.DeadlockThreadCountBo; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.DeadlockSampler; -import com.navercorp.pinpoint.web.vo.chart.Chart; -import com.navercorp.pinpoint.web.vo.stat.SampledDeadlock; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChart; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Random; - -/** - * @author Taejin Koo - */ -public class DeadlockChartGroupTest { - - private static final int RANDOM_LIST_MAX_SIZE = 11; // Random API's upper bound field is exclusive - private static final int RANDOM_MAX_DEADLOCKED_SIZE = 301; // Random API's upper bound field is exclusive - private final Random random = new Random(); - private final DeadlockSampler sampler = new DeadlockSampler(); - - @Test - public void basicFunctionTest1() { - long currentTimeMillis = System.currentTimeMillis(); - TimeWindow timeWindow = new TimeWindow(Range.between(currentTimeMillis - 300000, currentTimeMillis)); - - List sampledDeadlockList = createSampledResponseTimeList(timeWindow); - StatChart> deadlockChartGroup = new DeadlockChart(timeWindow, sampledDeadlockList); - - assertEquals(sampledDeadlockList, deadlockChartGroup.getCharts()); - } - - private List createSampledResponseTimeList(TimeWindow timeWindow) { - List sampledDeadlockList = new ArrayList<>(); - - long from = timeWindow.getWindowRange().getFrom(); - long to = timeWindow.getWindowRange().getTo(); - - for (long i = from; i < to; i += timeWindow.getWindowSlotSize()) { - sampledDeadlockList.add(createDeadlock(i)); - } - - return sampledDeadlockList; - } - - - private SampledDeadlock createDeadlock(long timestamp) { - int listSize = random.nextInt(1, RANDOM_LIST_MAX_SIZE); - - int deadlockedSize = random.nextInt(1, RANDOM_MAX_DEADLOCKED_SIZE); - - List deadlockThreadCountBoList = new ArrayList<>(listSize); - for (int i = 0; i < listSize; i++) { - DeadlockThreadCountBo deadlockThreadCountBo = new DeadlockThreadCountBo(); - deadlockThreadCountBo.setDeadlockedThreadCount(deadlockedSize + i); - deadlockThreadCountBoList.add(deadlockThreadCountBo); - } - - return sampler.sampleDataPoints(0, timestamp, deadlockThreadCountBoList, null); - } - - private void assertEquals(List sampledDeadlockList, StatChartGroup> deadlockChartGroup) { - Map>> charts = deadlockChartGroup.getCharts(); - - Chart> deadlockCountChart = charts.get(DeadlockChart.DeadlockChartType.DEADLOCK_COUNT); - List> deadlockCountChartPointList = deadlockCountChart.getPoints(); - - for (int i = 0; i < sampledDeadlockList.size(); i++) { - SampledDeadlock sampledDeadlock = sampledDeadlockList.get(i); - AgentStatPoint point = sampledDeadlock.getDeadlockedThreadCount(); - - Assertions.assertEquals(deadlockCountChartPointList.get(i), point); - } - } - -} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/ResponseTimeChartGroupTest.java b/web/src/test/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/ResponseTimeChartGroupTest.java deleted file mode 100644 index 9d45bb52ffe3..000000000000 --- a/web/src/test/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/ResponseTimeChartGroupTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2017 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.web.vo.stat.chart.agent; - -import com.navercorp.pinpoint.common.server.bo.stat.ResponseTimeBo; -import com.navercorp.pinpoint.common.server.util.time.Range; -import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.ResponseTimeSampler; -import com.navercorp.pinpoint.web.vo.chart.Chart; -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.stat.SampledResponseTime; -import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.concurrent.ThreadLocalRandom; - -/** - * @author Taejin Koo - */ -public class ResponseTimeChartGroupTest { - - private static final int MIN_VALUE_OF_MAX_CONNECTION_SIZE = 20; - private static final int RANDOM_LIST_MAX_SIZE = 10; - private static final int RANDOM_AVG_MAX_SIZE = 300000; - private final Random random = new Random(); - - private final ResponseTimeSampler sampler = new ResponseTimeSampler(); - - @Test - public void basicFunctionTest1() { - long currentTimeMillis = System.currentTimeMillis(); - TimeWindow timeWindow = new TimeWindow(Range.between(currentTimeMillis - 300000, currentTimeMillis)); - - List sampledResponseTimeList = createSampledResponseTimeList(timeWindow); - - ResponseTimeChart responseTimeChart = new ResponseTimeChart(timeWindow, sampledResponseTimeList); - StatChartGroup> responseTimeChartGroup = responseTimeChart.getCharts(); - - assertEquals(sampledResponseTimeList, responseTimeChartGroup); - } - - private List createSampledResponseTimeList(TimeWindow timeWindow) { - List sampledResponseTimeList = new ArrayList<>(); - - int maxConnectionSize = ThreadLocalRandom.current().nextInt(MIN_VALUE_OF_MAX_CONNECTION_SIZE) + MIN_VALUE_OF_MAX_CONNECTION_SIZE; - - long from = timeWindow.getWindowRange().getFrom(); - long to = timeWindow.getWindowRange().getTo(); - - for (long i = from; i < to; i += timeWindow.getWindowSlotSize()) { - sampledResponseTimeList.add(createSampledResponseTime(i, maxConnectionSize)); - } - - return sampledResponseTimeList; - } - - private SampledResponseTime createSampledResponseTime(long timestamp, int maxConnectionSize) { - int listSize = random.nextInt(1, RANDOM_LIST_MAX_SIZE); - - List responseTimeBoList = new ArrayList<>(listSize); - for (int i = 0; i < listSize; i++) { - ResponseTimeBo responseTimeBo = new ResponseTimeBo(); - long avg = ThreadLocalRandom.current().nextLong(RANDOM_AVG_MAX_SIZE); - responseTimeBo.setAvg(avg); - responseTimeBo.setMax(avg + 100); - responseTimeBoList.add(responseTimeBo); - } - - return sampler.sampleDataPoints(0, timestamp, responseTimeBoList, null); - } - - private void assertEquals(List sampledResponseTimeList, StatChartGroup> responseTimeChartGroup) { - Map>> charts = responseTimeChartGroup.getCharts(); - - Chart> avgChart = charts.get(ResponseTimeChart.ResponseTimeChartType.AVG); - List> avgChartPointList = avgChart.getPoints(); - for (int i = 0; i < sampledResponseTimeList.size(); i++) { - SampledResponseTime sampledResponseTime = sampledResponseTimeList.get(i); - Point point = sampledResponseTime.getAvg(); - - Assertions.assertEquals(avgChartPointList.get(i), point); - } - - Chart> maxChart = charts.get(ResponseTimeChart.ResponseTimeChartType.MAX); - List> maxChartPointList = maxChart.getPoints(); - for (int i = 0; i < sampledResponseTimeList.size(); i++) { - SampledResponseTime sampledResponseTime = sampledResponseTimeList.get(i); - AgentStatPoint point = sampledResponseTime.getMax(); - - Assertions.assertEquals(maxChartPointList.get(i), point); - } - - } - -}