-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
504 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...ain/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* 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.profiler.context.storage; | ||
|
||
import com.navercorp.pinpoint.common.util.Assert; | ||
import com.navercorp.pinpoint.common.util.CollectionUtils; | ||
import com.navercorp.pinpoint.profiler.monitor.metric.uri.AgentUriStatData; | ||
import com.navercorp.pinpoint.profiler.monitor.metric.uri.UriStatInfo; | ||
import com.navercorp.pinpoint.profiler.sender.AsyncQueueingExecutor; | ||
import com.navercorp.pinpoint.profiler.sender.AsyncQueueingExecutorListener; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* @author Taejin Koo | ||
*/ | ||
public class AsyncQueueingUriStatStorage extends AsyncQueueingExecutor<UriStatInfo> implements UriStatStorage { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(AsyncQueueingUriStatStorage.class); | ||
|
||
private final ExecutorListener executorListener; | ||
|
||
public AsyncQueueingUriStatStorage(int queueSize, int collectInterval, String executorName) { | ||
this(queueSize, executorName, new ExecutorListener(collectInterval)); | ||
} | ||
|
||
private AsyncQueueingUriStatStorage(int queueSize, String executorName, ExecutorListener executorListener) { | ||
super(queueSize, executorName, executorListener); | ||
this.executorListener = executorListener; | ||
} | ||
|
||
@Override | ||
public void store(String uri, boolean status, long elapsedTime) { | ||
Assert.requireNonNull(uri, "uri"); | ||
UriStatInfo uriStatInfo = new UriStatInfo(uri, status, elapsedTime); | ||
execute(uriStatInfo); | ||
} | ||
|
||
@Override | ||
protected void pollTimeout(long timeout) { | ||
executorListener.executePollTimeout(); | ||
} | ||
|
||
private static class ExecutorListener implements AsyncQueueingExecutorListener<UriStatInfo> { | ||
|
||
private AgentUriStatData agentUriStatData; | ||
private int collectInterval; | ||
|
||
public ExecutorListener(int collectInterval) { | ||
Assert.isTrue(collectInterval > 0, "collectInterval must be ' > 0'"); | ||
this.collectInterval = collectInterval; | ||
} | ||
|
||
@Override | ||
public void execute(Collection<UriStatInfo> messageList) { | ||
final long currentBaseTimestamp = getBaseTimestamp(); | ||
checkAndFlushOldData(currentBaseTimestamp); | ||
|
||
AgentUriStatData agentUriStatData = getUriStatBatchBuilder(currentBaseTimestamp); | ||
|
||
Object[] dataList = messageList.toArray(); | ||
for (int i = 0; i < CollectionUtils.nullSafeSize(messageList); i++) { | ||
try { | ||
agentUriStatData.add((UriStatInfo) dataList[i]); | ||
} catch (Throwable th) { | ||
LOGGER.warn("Unexpected Error. Cause:{}", th.getMessage(), th); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void execute(UriStatInfo message) { | ||
long currentBaseTimestamp = getBaseTimestamp(); | ||
checkAndFlushOldData(currentBaseTimestamp); | ||
|
||
AgentUriStatData agentUriStatData = getUriStatBatchBuilder(currentBaseTimestamp); | ||
agentUriStatData.add(message); | ||
} | ||
|
||
public void executePollTimeout() { | ||
long currentBaseTimestamp = getBaseTimestamp(); | ||
checkAndFlushOldData(currentBaseTimestamp); | ||
} | ||
|
||
private long getBaseTimestamp() { | ||
long currentTimeMillis = System.currentTimeMillis(); | ||
long timestamp = currentTimeMillis - (currentTimeMillis % collectInterval); | ||
return timestamp; | ||
} | ||
|
||
private boolean checkAndFlushOldData(long currentBaseTimestamp) { | ||
if (agentUriStatData == null) { | ||
return false; | ||
} | ||
|
||
if (currentBaseTimestamp > agentUriStatData.getBaseTimestamp()) { | ||
// TODO FLUSH | ||
agentUriStatData = null; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private AgentUriStatData getUriStatBatchBuilder(long currentBaseTimestamp) { | ||
if (agentUriStatData == null) { | ||
agentUriStatData = new AgentUriStatData(currentBaseTimestamp, collectInterval); | ||
} | ||
return agentUriStatData; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...er/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/uri/AgentUriStatData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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.profiler.monitor.metric.uri; | ||
|
||
import com.navercorp.pinpoint.common.util.Assert; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Taejin Koo | ||
*/ | ||
public class AgentUriStatData { | ||
|
||
private final long baseTimestamp; | ||
private final int interval; | ||
|
||
private Map<String, EachUriStatData> eachUriStatDataMap = new HashMap<>(); | ||
|
||
public AgentUriStatData(long baseTimestamp, int interval) { | ||
Assert.isTrue(baseTimestamp > 0, "baseTimestamp must be ` > 0`"); | ||
Assert.isTrue(interval > 0, "interval must be ` > 0`"); | ||
|
||
this.baseTimestamp = baseTimestamp; | ||
this.interval = interval; | ||
} | ||
|
||
public long getBaseTimestamp() { | ||
return baseTimestamp; | ||
} | ||
|
||
public int getInterval() { | ||
return interval; | ||
} | ||
|
||
public void add(UriStatInfo uriStatInfo) { | ||
String uri = uriStatInfo.getUri(); | ||
|
||
EachUriStatData eachUriStatData = eachUriStatDataMap.get(uri); | ||
if (eachUriStatData == null) { | ||
eachUriStatData = new EachUriStatData(uri); | ||
eachUriStatDataMap.put(uri, eachUriStatData); | ||
} | ||
|
||
eachUriStatData.add(uriStatInfo); | ||
} | ||
|
||
public Collection<EachUriStatData> getAllUriStatData() { | ||
return eachUriStatDataMap.values(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder sb = new StringBuilder("UriStatData{"); | ||
sb.append("baseTimestamp=").append(baseTimestamp); | ||
sb.append(", interval=").append(interval); | ||
sb.append(", eachUriStatDataMap=").append(eachUriStatDataMap); | ||
sb.append('}'); | ||
return sb.toString(); | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
...ler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/uri/EachUriStatData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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.profiler.monitor.metric.uri; | ||
|
||
/** | ||
* @author Taejin Koo | ||
*/ | ||
public class EachUriStatData { | ||
|
||
private final String uri; | ||
private final UriStatHistogram totalHistogram = new UriStatHistogram(); | ||
private final UriStatHistogram failedHistogram = new UriStatHistogram(); | ||
|
||
public EachUriStatData(String uri) { | ||
this.uri = uri; | ||
} | ||
|
||
public void add(UriStatInfo uriStatInfo) { | ||
boolean status = uriStatInfo.isStatus(); | ||
totalHistogram.add(uriStatInfo.getElapsed()); | ||
|
||
if (!status) { | ||
failedHistogram.add(uriStatInfo.getElapsed()); | ||
} | ||
} | ||
|
||
public String getUri() { | ||
return uri; | ||
} | ||
|
||
public UriStatHistogram getTotalHistogram() { | ||
return totalHistogram; | ||
} | ||
|
||
public UriStatHistogram getFailedHistogram() { | ||
return failedHistogram; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder sb = new StringBuilder("EachUriStatData{"); | ||
sb.append("uri='").append(uri).append('\''); | ||
sb.append(", totalHistogram=").append(totalHistogram); | ||
sb.append(", failedHistogram=").append(failedHistogram); | ||
sb.append('}'); | ||
return sb.toString(); | ||
} | ||
} |
Oops, something went wrong.