diff --git a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/Trace.java b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/Trace.java index 75e3de8d94fc3..80e9b946fbc52 100644 --- a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/Trace.java +++ b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/Trace.java @@ -34,6 +34,8 @@ public interface Trace extends StackOperation { @InterfaceAudience.Private long getStartTime(); + @InterfaceAudience.Private + long getEndTime(); //------------------------------------------------ TraceId getTraceId(); diff --git a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/pair/NameValuePair.java b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/pair/NameValuePair.java index 149a5619f17c7..2574e18202857 100644 --- a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/pair/NameValuePair.java +++ b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/pair/NameValuePair.java @@ -45,4 +45,21 @@ public V getValue() { public void setValue(V value) { this.value = value; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NameValuePair pair = (NameValuePair) o; + if (!name.equals(pair.getName())) return false; + return value.equals(pair.getValue()); + } + + @Override + public int hashCode() { + int result = name.hashCode(); + result = 31 * result + value.hashCode(); + return result; + } } diff --git a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListener.java b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListener.java index b3d16855a2060..3bfacc5d96bd4 100644 --- a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListener.java +++ b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/ServletRequestListener.java @@ -179,7 +179,7 @@ public void destroyed(REQ request, final Throwable throwable, final int statusCo this.traceContext.removeTraceObject(); trace.close(); boolean status = isNotFailedStatus(statusCode); - uriStatRecorder.record(request, rpcName, status, trace.getStartTime(), System.currentTimeMillis()); + uriStatRecorder.record(request, rpcName, status, trace.getStartTime(), trace.getEndTime()); } } 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 index 67b11247b6ec2..ad5a3b5835a42 100644 --- 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 @@ -50,5 +50,4 @@ public long getTimestampDelta() { public void setTimestampDelta(long timestampDelta) { this.timestampDelta = timestampDelta; } - } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncChildTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncChildTrace.java index 8a9f90921ff4f..de4cac5f59634 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncChildTrace.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncChildTrace.java @@ -53,6 +53,8 @@ public class AsyncChildTrace implements Trace { private final TraceRoot traceRoot; private final LocalAsyncId localAsyncId; + private long endTime = 0L; + public AsyncChildTrace(final TraceRoot traceRoot, CallStack callStack, Storage storage, boolean sampling, SpanRecorder spanRecorder, WrappedSpanEventRecorder wrappedSpanEventRecorder, final LocalAsyncId localAsyncId) { @@ -147,6 +149,7 @@ public void traceBlockEnd(int stackId) { if (spanEvent.isTimeRecording()) { spanEvent.markAfterTime(); + endTime = spanEvent.getAfterTime(); } logSpan(spanEvent); // state restore @@ -203,6 +206,11 @@ public long getStartTime() { return getTraceRoot().getTraceStartTime(); } + @Override + public long getEndTime() { + return endTime; + } + @Override public boolean canSampled() { return true; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncTrace.java index dc2b8079b040d..f6465566878b2 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncTrace.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncTrace.java @@ -49,6 +49,11 @@ public long getStartTime() { return this.traceRoot.getTraceStartTime(); } + @Override + public long getEndTime() { + return this.trace.getEndTime(); + } + @Override public TraceId getTraceId() { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java index bd8a4cd662f44..c41ce5728ca3e 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java @@ -56,6 +56,8 @@ public final class DefaultTrace implements Trace { private final Span span; private final ActiveTraceHandle activeTraceHandle; + private long endTime = 0L; + public DefaultTrace(Span span, CallStack callStack, Storage storage, boolean sampling, SpanRecorder spanRecorder, WrappedSpanEventRecorder wrappedSpanEventRecorder, ActiveTraceHandle activeTraceHandle) { @@ -69,6 +71,7 @@ public DefaultTrace(Span span, CallStack callStack, Storage storage, this.wrappedSpanEventRecorder = Objects.requireNonNull(wrappedSpanEventRecorder, "wrappedSpanEventRecorder"); this.activeTraceHandle = Objects.requireNonNull(activeTraceHandle, "activeTraceHandle"); + setCurrentThread(); } @@ -189,6 +192,7 @@ public void close() { } this.storage.close(); + endTime = afterTime; purgeActiveTrace(afterTime); } @@ -225,6 +229,11 @@ public long getStartTime() { return getTraceRoot().getTraceStartTime(); } + @Override + public long getEndTime() { + return endTime; + } + @Override public boolean canSampled() { return true; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DisableAsyncChildTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DisableAsyncChildTrace.java index 9c03b4ce8525a..917fb13284d97 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DisableAsyncChildTrace.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DisableAsyncChildTrace.java @@ -86,6 +86,11 @@ public long getStartTime() { return getTraceRoot().getTraceStartTime(); } + @Override + public long getEndTime() { + return 0L; + } + @Override public TraceId getTraceId() { return getTraceRoot().getTraceId(); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DisableTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DisableTrace.java index 0caf99cd9594a..55a69a698d17f 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DisableTrace.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DisableTrace.java @@ -54,6 +54,11 @@ public long getStartTime() { return startTime; } + @Override + public long getEndTime() { + return 0L; + } + @Override public SpanEventRecorder traceBlockBegin() { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcUriStatMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcUriStatMessageConverter.java index 3f60c661aee7c..25014b325ceb7 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcUriStatMessageConverter.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcUriStatMessageConverter.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.profiler.context.grpc; +import com.navercorp.pinpoint.bootstrap.pair.NameValuePair; import com.navercorp.pinpoint.common.trace.UriStatHistogramBucket; import com.navercorp.pinpoint.grpc.trace.PAgentUriStat; import com.navercorp.pinpoint.grpc.trace.PEachUriStat; @@ -27,6 +28,8 @@ import com.navercorp.pinpoint.profiler.monitor.metric.uri.UriStatHistogram; import java.util.Collection; +import java.util.Map; +import java.util.Set; /** * @author Taejin Koo @@ -46,15 +49,14 @@ public PAgentUriStat toMessage(MetricType message) { } private PAgentUriStat createPAgentUriStat(AgentUriStatData agentUriStatData) { - long baseTimestamp = agentUriStatData.getBaseTimestamp(); - PAgentUriStat.Builder builder = PAgentUriStat.newBuilder(); - builder.setTimestamp(baseTimestamp); builder.setBucketVersion(layout.getBucketVersion()); - Collection allUriStatData = agentUriStatData.getAllUriStatData(); - for (EachUriStatData eachUriStatData : allUriStatData) { - PEachUriStat pEachUriStat = createPEachUriStat(eachUriStatData); + Set, EachUriStatData>> allUriStatData = agentUriStatData.getAllUriStatData(); + + for (Map.Entry, EachUriStatData> eachUriStatData : allUriStatData) { + builder.setTimestamp(eachUriStatData.getKey().getValue()); + PEachUriStat pEachUriStat = createPEachUriStat(eachUriStatData.getValue()); builder.addEachUriStat(pEachUriStat); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/monitor/config/DefaultMonitorConfig.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/monitor/config/DefaultMonitorConfig.java index 2ba2abda3715c..8b3d0a3cf2f63 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/monitor/config/DefaultMonitorConfig.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/monitor/config/DefaultMonitorConfig.java @@ -31,7 +31,7 @@ public class DefaultMonitorConfig implements MonitorConfig { @Value("${profiler.uri.stat.enable}") private boolean uriStatEnable = false; @Value("${profiler.uri.stat.completed.data.limit.size}") - private int completedUriStatDataLimitSize = 3; + private int completedUriStatDataLimitSize = 1000; @Value("${profiler.jvm.stat.collect.interval}") private int profileJvmStatCollectIntervalMs = DEFAULT_AGENT_STAT_COLLECTION_INTERVAL_MS; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultUriStatRecorder.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultUriStatRecorder.java index 6c008fa29b3c6..6c0aafe736254 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultUriStatRecorder.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultUriStatRecorder.java @@ -48,7 +48,7 @@ public void record(T request, String rawUri, boolean status, long startTime, lon return; } - uriStatStorage.store(uri, status, endTime - startTime); + uriStatStorage.store(uri, status, startTime, endTime); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorage.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorage.java index e4243d7e5746e..40b4f082cae31 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorage.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorage.java @@ -56,9 +56,9 @@ private AsyncQueueingUriStatStorage(int queueSize, String executorName, Executor } @Override - public void store(String uri, boolean status, long elapsedTime) { + public void store(String uri, boolean status, long startTime, long endTime) { Objects.requireNonNull(uri, "uri"); - UriStatInfo uriStatInfo = new UriStatInfo(uri, status, elapsedTime); + UriStatInfo uriStatInfo = new UriStatInfo(uri, status, startTime, endTime); execute(uriStatInfo); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/DisabledUriStatStorage.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/DisabledUriStatStorage.java index 7eea51ab1615f..e8304ea06cf82 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/DisabledUriStatStorage.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/DisabledUriStatStorage.java @@ -24,7 +24,7 @@ public class DisabledUriStatStorage implements UriStatStorage { @Override - public void store(String uri, boolean status, long elapsedTime) { + public void store(String uri, boolean status, long startTime, long endTime) { // Do nothing } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/UriStatStorage.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/UriStatStorage.java index 57f2726c021da..84e5eebf23991 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/UriStatStorage.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/UriStatStorage.java @@ -23,7 +23,7 @@ */ public interface UriStatStorage { - void store(String uri, boolean status, long elapsedTime); + void store(String uri, boolean status, long startTime, long endTime); AgentUriStatData poll(); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/uri/AgentUriStatData.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/uri/AgentUriStatData.java index 0de89c67a9da9..f01d751478018 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/uri/AgentUriStatData.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/uri/AgentUriStatData.java @@ -16,22 +16,26 @@ package com.navercorp.pinpoint.profiler.monitor.metric.uri; +import com.navercorp.pinpoint.bootstrap.pair.NameValuePair; import com.navercorp.pinpoint.common.util.Assert; +import com.navercorp.pinpoint.profiler.context.storage.AsyncQueueingUriStatStorage; import com.navercorp.pinpoint.profiler.monitor.metric.MetricType; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; -import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.Set; /** * @author Taejin Koo */ public class AgentUriStatData implements MetricType { - + private static final Logger LOGGER = LogManager.getLogger(AsyncQueueingUriStatStorage.class); private final int capacity; private final long baseTimestamp; - private final Map eachUriStatDataMap = new HashMap<>(); + private final Map, EachUriStatData> eachUriStatDataMap = new HashMap<>(); public AgentUriStatData(long baseTimestamp, int capacity) { Assert.isTrue(capacity > 0, "capacity must be ` > 0`"); @@ -49,23 +53,27 @@ public long getBaseTimestamp() { } public boolean add(UriStatInfo uriStatInfo) { + String uri = uriStatInfo.getUri(); + if (eachUriStatDataMap.size() > this.capacity) { + LOGGER.warn("Number of URIs already collected met the capacity of " + this.capacity + ". Ignoring URI " + uri); return false; } - String uri = uriStatInfo.getUri(); - EachUriStatData eachUriStatData = eachUriStatDataMap.get(uri); + NameValuePair key = new NameValuePair(uri, uriStatInfo.getEndTime()); + + EachUriStatData eachUriStatData = eachUriStatDataMap.get(key); if (eachUriStatData == null) { eachUriStatData = new EachUriStatData(uri); - eachUriStatDataMap.put(uri, eachUriStatData); + eachUriStatDataMap.put(key, eachUriStatData); } eachUriStatData.add(uriStatInfo); return true; } - public Collection getAllUriStatData() { - return eachUriStatDataMap.values(); + public Set, EachUriStatData>> getAllUriStatData() { + return eachUriStatDataMap.entrySet(); } @Override diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/uri/UriStatInfo.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/uri/UriStatInfo.java index 61c0760360f28..d43f89ea44255 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/uri/UriStatInfo.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/uri/UriStatInfo.java @@ -25,12 +25,14 @@ public class UriStatInfo { private final String uri; private final boolean status; - private final long elapsed; + private final long startTime; + private final long endTime; - public UriStatInfo(String uri, boolean status, long elapsed) { + public UriStatInfo(String uri, boolean status, long startTime, long endTime) { this.uri = Objects.requireNonNull(uri, "uri"); this.status = status; - this.elapsed = elapsed; + this.startTime = startTime; + this.endTime = endTime; } public String getUri() { @@ -41,8 +43,16 @@ public boolean isStatus() { return status; } + public long getStartTime() { + return startTime; + } + + public long getEndTime() { + return endTime; + } + public long getElapsed() { - return elapsed; + return endTime - startTime; } @Override @@ -50,7 +60,8 @@ public String toString() { final StringBuilder sb = new StringBuilder("UriStatInfo{"); sb.append("uri='").append(uri).append('\''); sb.append(", status=").append(status); - sb.append(", elapsed=").append(elapsed); + sb.append(", startTime=").append(startTime); + sb.append(", endTime=").append(endTime); sb.append('}'); return sb.toString(); } diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcUriStatMessageConverterTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcUriStatMessageConverterTest.java index a53d52dd86dd6..e9af04ab1460e 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcUriStatMessageConverterTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcUriStatMessageConverterTest.java @@ -72,7 +72,8 @@ private UriStatInfo createRandomUriStatInfo() { int index = RANDOM.nextInt(URI_EXAMPLES.length); boolean status = RANDOM.nextBoolean(); final int elapsedTime = RANDOM.nextInt(10000); - return new UriStatInfo(URI_EXAMPLES[index], status, elapsedTime); + final long timestamp = System.currentTimeMillis(); + return new UriStatInfo(URI_EXAMPLES[index], status, timestamp - elapsedTime, timestamp); } private void assertData(List uriStatInfoList, List eachUriStatList) { diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorageTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorageTest.java index c7af1aaf34bbe..6840a6eb78b32 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorageTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorageTest.java @@ -17,13 +17,16 @@ package com.navercorp.pinpoint.profiler.context.storage; import com.google.common.util.concurrent.Uninterruptibles; +import com.navercorp.pinpoint.bootstrap.pair.NameValuePair; import com.navercorp.pinpoint.profiler.monitor.metric.uri.AgentUriStatData; import com.navercorp.pinpoint.profiler.monitor.metric.uri.EachUriStatData; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.Collection; +import java.util.Map; import java.util.Random; +import java.util.Set; import java.util.concurrent.TimeUnit; /** @@ -61,9 +64,9 @@ public void storageTest() { AgentUriStatData poll = storage.poll(); Assertions.assertNotNull(poll); - Collection allUriStatData = poll.getAllUriStatData(); - for (EachUriStatData eachUriStatData : allUriStatData) { - storeCount -= eachUriStatData.getTotalHistogram().getCount(); + Set, EachUriStatData>> allUriStatData = poll.getAllUriStatData(); + for (Map.Entry, EachUriStatData> eachUriStatData : allUriStatData) { + storeCount -= eachUriStatData.getValue().getTotalHistogram().getCount(); } Assertions.assertEquals(0, storeCount); @@ -75,7 +78,8 @@ public void storageTest() { } private void storeRandomValue(AsyncQueueingUriStatStorage storage) { - storage.store(URI_EXAMPLES[RANDOM.nextInt(URI_EXAMPLES.length)], RANDOM.nextBoolean(), RANDOM.nextInt(10000)); + final long timestamp = System.currentTimeMillis(); + storage.store(URI_EXAMPLES[RANDOM.nextInt(URI_EXAMPLES.length)], RANDOM.nextBoolean(), timestamp - RANDOM.nextInt(10000), timestamp); } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/view/UriStatHistogramPointSerializer.java b/web/src/main/java/com/navercorp/pinpoint/web/view/UriStatHistogramPointSerializer.java deleted file mode 100644 index 755d616116cdd..0000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/view/UriStatHistogramPointSerializer.java +++ /dev/null @@ -1,40 +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.view; - -import com.navercorp.pinpoint.web.vo.stat.chart.agent.UriStatHistogramPoint; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; - -import java.io.IOException; - -/** - * @author Taejin Koo - */ -public class UriStatHistogramPointSerializer extends JsonSerializer { - - @Override - public void serialize(UriStatHistogramPoint histogramPoint, JsonGenerator jgen, SerializerProvider serializers) throws IOException, JsonProcessingException { - int length = histogramPoint.getYVal().length; - - jgen.writeArray(histogramPoint.getYVal(), 0, length); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledEachUriStatBo.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledEachUriStatBo.java deleted file mode 100644 index 3463fc8acf70c..0000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledEachUriStatBo.java +++ /dev/null @@ -1,76 +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; - -/** - * @author Taejin Koo - */ -public class SampledEachUriStatBo implements SampledAgentStatDataPoint { - - private final String uri; - - private final SampledUriStatHistogramBo totalSampledUriStatHistogramBo; - private final SampledUriStatHistogramBo failedSampledUriStatHistogramBo; - - public SampledEachUriStatBo(String uri, SampledUriStatHistogramBo totalSampledUriStatHistogramBo, SampledUriStatHistogramBo failedSampledUriStatHistogramBo) { - this.uri = uri; - this.totalSampledUriStatHistogramBo = totalSampledUriStatHistogramBo; - this.failedSampledUriStatHistogramBo = failedSampledUriStatHistogramBo; - } - - public String getUri() { - return uri; - } - - public SampledUriStatHistogramBo getTotalSampledUriStatHistogramBo() { - return totalSampledUriStatHistogramBo; - } - - public SampledUriStatHistogramBo getFailedSampledUriStatHistogramBo() { - return failedSampledUriStatHistogramBo; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SampledEachUriStatBo that = (SampledEachUriStatBo) o; - - if (uri != null ? !uri.equals(that.uri) : that.uri != null) return false; - if (totalSampledUriStatHistogramBo != null ? !totalSampledUriStatHistogramBo.equals(that.totalSampledUriStatHistogramBo) : that.totalSampledUriStatHistogramBo != null) return false; - return failedSampledUriStatHistogramBo != null ? failedSampledUriStatHistogramBo.equals(that.failedSampledUriStatHistogramBo) : that.failedSampledUriStatHistogramBo == null; - } - - @Override - public int hashCode() { - int result = uri != null ? uri.hashCode() : 0; - result = 31 * result + (totalSampledUriStatHistogramBo != null ? totalSampledUriStatHistogramBo.hashCode() : 0); - result = 31 * result + (failedSampledUriStatHistogramBo != null ? failedSampledUriStatHistogramBo.hashCode() : 0); - return result; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledEachUriStatBo{"); - sb.append("uri='").append(uri).append('\''); - sb.append(", totalSampledUriStatHistogramBo=").append(totalSampledUriStatHistogramBo); - sb.append(", failedSampledUriStatHistogramBo=").append(failedSampledUriStatHistogramBo); - sb.append('}'); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledUriStatHistogramBo.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledUriStatHistogramBo.java deleted file mode 100644 index 353d6ef40aa4d..0000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledUriStatHistogramBo.java +++ /dev/null @@ -1,105 +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.common.trace.UriStatHistogramBucket; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint; - -import java.util.Map; - -/** - * @author Taejin Koo - */ -public class SampledUriStatHistogramBo { - - private final AgentStatPoint countPoint; - private final AgentStatPoint maxTimePoint; - private final AgentStatPoint avgTimePoint; - private final Map uriStatHistogramCountMap; - private final long totalElapsedTime; - - public SampledUriStatHistogramBo(AgentStatPoint countPoint, AgentStatPoint maxTimePoint, AgentStatPoint avgTimePoint, Map uriStatHistogramCountMap, long totalElapsedTime) { - this.countPoint = countPoint; - this.maxTimePoint = maxTimePoint; - this.avgTimePoint = avgTimePoint; - this.uriStatHistogramCountMap = uriStatHistogramCountMap; - this.totalElapsedTime = totalElapsedTime; - } - - public AgentStatPoint getCountPoint() { - return countPoint; - } - - public AgentStatPoint getMaxTimePoint() { - return maxTimePoint; - } - - public AgentStatPoint getAvgTimePoint() { - return avgTimePoint; - } - - public long getTotalElapsedTime() { - return totalElapsedTime; - } - - public int[] getUriStatHistogramValue() { - int[] newArrayValue = new int[UriStatHistogramBucket.getLayout().getBucketSize()]; - - for (Map.Entry entry : uriStatHistogramCountMap.entrySet()) { - int index = entry.getKey().getIndex(); - newArrayValue[index] = entry.getValue(); - } - - return newArrayValue; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SampledUriStatHistogramBo that = (SampledUriStatHistogramBo) o; - - if (totalElapsedTime != that.totalElapsedTime) return false; - if (countPoint != null ? !countPoint.equals(that.countPoint) : that.countPoint != null) return false; - if (maxTimePoint != null ? !maxTimePoint.equals(that.maxTimePoint) : that.maxTimePoint != null) return false; - if (avgTimePoint != null ? !avgTimePoint.equals(that.avgTimePoint) : that.avgTimePoint != null) return false; - return uriStatHistogramCountMap != null ? uriStatHistogramCountMap.equals(that.uriStatHistogramCountMap) : that.uriStatHistogramCountMap == null; - } - - @Override - public int hashCode() { - int result = countPoint != null ? countPoint.hashCode() : 0; - result = 31 * result + (maxTimePoint != null ? maxTimePoint.hashCode() : 0); - result = 31 * result + (avgTimePoint != null ? avgTimePoint.hashCode() : 0); - result = 31 * result + (uriStatHistogramCountMap != null ? uriStatHistogramCountMap.hashCode() : 0); - result = 31 * result + (int) (totalElapsedTime ^ (totalElapsedTime >>> 32)); - return result; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("SampledUriStatHistogramBo{"); - sb.append("countPoint=").append(countPoint); - sb.append(", maxTimePoint=").append(maxTimePoint); - sb.append(", avgTimePoint=").append(avgTimePoint); - sb.append(", uriStatHistogramCountMap=").append(uriStatHistogramCountMap); - sb.append(", totalElapsedTime=").append(totalElapsedTime); - sb.append('}'); - return sb.toString(); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/AgentUriStatChart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/AgentUriStatChart.java deleted file mode 100644 index 5501808d8d375..0000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/AgentUriStatChart.java +++ /dev/null @@ -1,212 +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.trace.UriStatHistogramBucket; -import com.navercorp.pinpoint.web.mapper.stat.sampling.sampler.AgentStatPointFactory; -import com.navercorp.pinpoint.web.util.TimeWindow; -import com.navercorp.pinpoint.web.vo.chart.Chart; -import com.navercorp.pinpoint.web.vo.chart.Point; -import com.navercorp.pinpoint.web.vo.chart.TimeSeriesChartBuilder; -import com.navercorp.pinpoint.web.vo.stat.SampledEachUriStatBo; -import com.navercorp.pinpoint.web.vo.stat.SampledUriStatHistogramBo; -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.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; - -/** - * @author Taejin Koo - */ -public class AgentUriStatChart implements StatChart { - - private static final String UNCOLLECTED_STRING = null; - - private static final AgentStatPointFactory DEFAULT_STAT_POINT_FACTORY = new AgentStatPointFactory(-1, -1L, -1D); - - private final String uri; - - private final AgentUriChartGroup agentUriChartGroup; - private final AgentUriChartGroup failedAgentUriChartGroup; - - public AgentUriStatChart(TimeWindow timeWindow, List sampledEachUriStatBoList) { - SampledEachUriStatBo representative = CollectionUtils.firstElement(sampledEachUriStatBoList); - if (representative == null) { - this.uri = UNCOLLECTED_STRING; - } else { - this.uri = representative.getUri(); - } - - List total = sampledEachUriStatBoList.stream() - .map(SampledEachUriStatBo::getTotalSampledUriStatHistogramBo).collect(Collectors.toList()); - this.agentUriChartGroup = new AgentUriChartGroup(timeWindow, total); - - List failed = sampledEachUriStatBoList.stream() - .map(SampledEachUriStatBo::getFailedSampledUriStatHistogramBo).collect(Collectors.toList()); - this.failedAgentUriChartGroup = new AgentUriChartGroup(timeWindow, failed); - } - - public String getUri() { - return uri; - } - - public long getTotalCount() { - return agentUriChartGroup.totalCount; - } - - public double getAvgTime() { - return agentUriChartGroup.avgTime; - } - - public long getMaxTime() { - return agentUriChartGroup.maxTime; - } - - @Override - public StatChartGroup getCharts() { - return agentUriChartGroup; - } - -// public StatChartGroup getFailedCharts() { -// return failedAgentUriChartGroup; -// } - - public static class AgentUriChartGroup implements StatChartGroup { - - private final TimeWindow timeWindow; - - private final long totalCount; - private final long maxTime; - private final double avgTime; - - private final Map> charts; - - - private AgentUriChartGroup(TimeWindow timeWindow, List sampledUriStatHistogramBoList) { - this.timeWindow = timeWindow; - - this.totalCount = sampledUriStatHistogramBoList.stream().mapToLong(o -> o.getCountPoint().getSumYVal()).sum(); - this.maxTime = sampledUriStatHistogramBoList.stream().mapToLong(o -> o.getMaxTimePoint().getMaxYVal()).max().getAsLong(); - if (totalCount != 0) { - this.avgTime = sampledUriStatHistogramBoList.stream().mapToLong(o -> o.getTotalElapsedTime()).sum() / (double)totalCount; - } else { - this.avgTime = 0L; - } - - this.charts = newChart(sampledUriStatHistogramBoList); - } - - @Override - public TimeWindow getTimeWindow() { - return timeWindow; - } - - - @Override - public Map> getCharts() { - return charts; - } - - public enum AgentUriChartType implements AgentChartType { - COUNT, - AVG, - MAX; - } - - public enum AgentUriHistogramType implements AgentChartType { - HISTOGRAM_BUCKET; - - @Override - public String[] getSchema() { - UriStatHistogramBucket[] values = UriStatHistogramBucket.values(); - int length = values.length; - String[] schemaDescs = new String[length]; - - for (int i = 0; i < length; i++) { - schemaDescs[i] = values[i].getDesc(); - } - - return schemaDescs; - } - } - - private Map> newChart(List sampledEachUriStatHistogramBoList) { - Map> totalCharts = new HashMap<>(); - - Chart> totalCountChart = newIntChart(sampledEachUriStatHistogramBoList, SampledUriStatHistogramBo::getCountPoint); - totalCharts.put(AgentUriChartType.COUNT, totalCountChart); - - Chart> avgChart = newDoubleChart(sampledEachUriStatHistogramBoList, SampledUriStatHistogramBo::getAvgTimePoint); - totalCharts.put(AgentUriChartType.AVG, avgChart); - - Chart> maxElapsedChart = newLongChart(sampledEachUriStatHistogramBoList, SampledUriStatHistogramBo::getMaxTimePoint); - totalCharts.put(AgentUriChartType.MAX, maxElapsedChart); - - List histogramPoints = new ArrayList<>(); - for (SampledUriStatHistogramBo sampledUriStatHistogramBo : sampledEachUriStatHistogramBoList) { - UriStatHistogramPoint uriStatHistogramPoint = createUriStatHistogramPoint(sampledUriStatHistogramBo); - histogramPoints.add(uriStatHistogramPoint); - } - totalCharts.put(AgentUriHistogramType.HISTOGRAM_BUCKET, newHistogramPointChart(histogramPoints)); - - return (Map>)(Map) totalCharts; - } - - private UriStatHistogramPoint createUriStatHistogramPoint(SampledUriStatHistogramBo sampledUriStatHistogramBo) { - long xVal = sampledUriStatHistogramBo.getMaxTimePoint().getXVal(); - int[] uriStatHistogramValues = sampledUriStatHistogramBo.getUriStatHistogramValue(); - - return new UriStatHistogramPoint(xVal, uriStatHistogramValues); - } - - private Chart> newIntChart(List sampledEachUriStatBoList, Function> function) { - TimeSeriesChartBuilder> builder = new TimeSeriesChartBuilder<>(DEFAULT_STAT_POINT_FACTORY.getUncollectedIntValuePointCreator()); - return builder.build(this.timeWindow, sampledEachUriStatBoList, function); - } - - private Chart> newLongChart(List sampledEachUriStatBoList, Function> function) { - TimeSeriesChartBuilder> builder = new TimeSeriesChartBuilder<>(DEFAULT_STAT_POINT_FACTORY.getUncollectedLongValuePointCreator()); - return builder.build(this.timeWindow, sampledEachUriStatBoList, function); - } - - private Chart> newDoubleChart(List sampledEachUriStatBoList, Function> function) { - TimeSeriesChartBuilder> builder = new TimeSeriesChartBuilder<>(DEFAULT_STAT_POINT_FACTORY.getUncollectedDoubleValuePointCreator()); - return builder.build(this.timeWindow, sampledEachUriStatBoList, function); - } - - private Chart newHistogramPointChart(List histogramPointList) { - TimeSeriesChartBuilder builder = new TimeSeriesChartBuilder<>(UNCOLLECTED_POINT_CREATOR); - return builder.build(this.timeWindow, histogramPointList); - } - - } - - public static final int[] UNCOLLECTED = new int[UriStatHistogramBucket.getLayout().getBucketSize()]; - public static final Point.UncollectedPointCreator UNCOLLECTED_POINT_CREATOR = new Point.UncollectedPointCreator() { - @Override - public UriStatHistogramPoint createUnCollectedPoint(long xVal) { - return new UriStatHistogramPoint(xVal, UNCOLLECTED); - } - }; - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/UriStatHistogramPoint.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/UriStatHistogramPoint.java deleted file mode 100644 index 9df5c0e8f20a0..0000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/agent/UriStatHistogramPoint.java +++ /dev/null @@ -1,75 +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.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.navercorp.pinpoint.web.view.UriStatHistogramPointSerializer; -import com.navercorp.pinpoint.web.vo.chart.Point; - -import java.util.Arrays; - -/** - * @author Taejin Koo - */ -@JsonSerialize(using = UriStatHistogramPointSerializer.class) -public class UriStatHistogramPoint implements Point { - - private final long xVal; - private final int[] yVal; - - public UriStatHistogramPoint(long xVal, int[] yVal) { - this.xVal = xVal; - this.yVal = yVal; - } - - @Override - public long getXVal() { - return xVal; - } - - public int[] getYVal() { - return yVal; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - UriStatHistogramPoint that = (UriStatHistogramPoint) o; - - if (xVal != that.xVal) return false; - return Arrays.equals(yVal, that.yVal); - } - - @Override - public int hashCode() { - int result = (int) (xVal ^ (xVal >>> 32)); - result = 31 * result + Arrays.hashCode(yVal); - return result; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("UriStatHistogramPoint{"); - sb.append("xVal=").append(xVal); - sb.append(", yVal=").append(Arrays.toString(yVal)); - sb.append('}'); - return sb.toString(); - } - -} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/view/UriStatHistogramPointSerializerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/view/UriStatHistogramPointSerializerTest.java deleted file mode 100644 index 9e3ccb2220314..0000000000000 --- a/web/src/test/java/com/navercorp/pinpoint/web/view/UriStatHistogramPointSerializerTest.java +++ /dev/null @@ -1,54 +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.view; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.navercorp.pinpoint.common.trace.UriStatHistogramBucket; -import com.navercorp.pinpoint.web.vo.stat.chart.agent.UriStatHistogramPoint; -import org.apache.commons.lang3.StringUtils; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; -import java.util.concurrent.ThreadLocalRandom; - -/** - * @author Taejin Koo - */ -public class UriStatHistogramPointSerializerTest { - - @Test - public void jsonTest() throws JsonProcessingException { - int[] newArrayValue = new int[UriStatHistogramBucket.getLayout().getBucketSize()]; - for (int i = 0; i < newArrayValue.length; i++) { - newArrayValue[i] = ThreadLocalRandom.current().nextInt(0, 100); - } - - long currentTimeMillis = System.currentTimeMillis(); - UriStatHistogramPoint point = new UriStatHistogramPoint(currentTimeMillis, newArrayValue); - - ObjectMapper om = new ObjectMapper(); - String jsonString = om.writeValueAsString(point); - - String arrayAsString = Arrays.toString(newArrayValue); - String replace = StringUtils.replace(arrayAsString, " ", ""); - - Assertions.assertEquals(replace, jsonString); - } - -}