Skip to content

Commit

Permalink
[#9478] Uses tick time to aggregate uri stat
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-ram committed Dec 7, 2022
1 parent d016993 commit bf6f84b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.navercorp.pinpoint.profiler.context.storage;

import com.navercorp.pinpoint.common.profiler.clock.Clock;
import com.navercorp.pinpoint.common.profiler.clock.TickClock;
import com.navercorp.pinpoint.common.profiler.logging.ThrottledLogger;
import com.navercorp.pinpoint.common.util.Assert;
import com.navercorp.pinpoint.common.util.CollectionUtils;
Expand Down Expand Up @@ -83,7 +84,7 @@ static class ExecutorListener implements AsyncQueueingExecutorListener<UriStatIn

private static final int SNAPSHOT_LIMIT = 4;

private final Clock clock;
private final TickClock clock;
private final Queue<AgentUriStatData> snapshotQueue;

private final Snapshot<AgentUriStatData> snapshotManager;
Expand All @@ -97,10 +98,10 @@ public ExecutorListener(int uriStatDataLimitSize, int collectInterval) {
Assert.isTrue(uriStatDataLimitSize > 0, "uriStatDataLimitSize must be ' > 0'");

Assert.isTrue(collectInterval > 0, "collectInterval must be ' > 0'");
this.clock = Clock.tick(collectInterval);
this.clock = (TickClock) Clock.tick(collectInterval);

this.snapshotQueue = new ConcurrentLinkedQueue<>();
this.snapshotManager = new Snapshot<>(value -> new AgentUriStatData(value, uriStatDataLimitSize), AgentUriStatData::getBaseTimestamp);
this.snapshotManager = new Snapshot<>(value -> new AgentUriStatData(value, uriStatDataLimitSize, clock), AgentUriStatData::getBaseTimestamp);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package com.navercorp.pinpoint.profiler.monitor.metric.uri;

import com.navercorp.pinpoint.common.profiler.clock.TickClock;
import com.navercorp.pinpoint.common.util.Assert;
import com.navercorp.pinpoint.profiler.monitor.metric.MetricType;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
Expand All @@ -29,10 +31,12 @@
public class AgentUriStatData implements MetricType {
private final int capacity;
private final long baseTimestamp;
private final TickClock clock;

private final Map<URIKey, EachUriStatData> eachUriStatDataMap = new HashMap<>();

public AgentUriStatData(long baseTimestamp, int capacity) {
public AgentUriStatData(long baseTimestamp, int capacity, TickClock clock) {
this.clock = Objects.requireNonNull(clock, "clock");
Assert.isTrue(capacity > 0, "capacity must be ` > 0`");
this.capacity = capacity;
Assert.isTrue(baseTimestamp > 0, "baseTimestamp must be ` > 0`");
Expand Down Expand Up @@ -66,8 +70,8 @@ public boolean add(UriStatInfo uriStatInfo) {

private URIKey newURIKey(UriStatInfo uriStatInfo) {
String uri = uriStatInfo.getUri();
long endTime = uriStatInfo.getEndTime();
return new URIKey(uri, endTime);
long tickTime = clock.tick(uriStatInfo.getEndTime());
return new URIKey(uri, tickTime);
}

public Set<Map.Entry<URIKey, EachUriStatData>> getAllUriStatData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.navercorp.pinpoint.profiler.context.grpc;

import com.navercorp.pinpoint.common.profiler.clock.Clock;
import com.navercorp.pinpoint.common.profiler.clock.TickClock;
import com.navercorp.pinpoint.common.trace.UriStatHistogramBucket;
import com.navercorp.pinpoint.grpc.trace.PAgentUriStat;
import com.navercorp.pinpoint.grpc.trace.PEachUriStat;
Expand All @@ -34,6 +36,7 @@
* @author Taejin Koo
*/
public class GrpcUriStatMessageConverterTest {
private static final int DEFAULT_COLLECT_INTERVAL = 30000; // 30s

private static final Random RANDOM = new Random(System.currentTimeMillis());

Expand All @@ -43,8 +46,10 @@ public class GrpcUriStatMessageConverterTest {

@Test
public void convertTest() {
TickClock clock = (TickClock) Clock.tick(DEFAULT_COLLECT_INTERVAL);

long currentTimeMillis = System.currentTimeMillis();
AgentUriStatData agentUriStatData = new AgentUriStatData(currentTimeMillis, 10);
AgentUriStatData agentUriStatData = new AgentUriStatData(currentTimeMillis, 10, clock);

List<UriStatInfo> uriStatInfoList = createRandomUriStatInfo(100);
for (UriStatInfo uriStatInfo : uriStatInfoList) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.navercorp.pinpoint.profiler.monitor.metric.uri;

import com.navercorp.pinpoint.common.profiler.clock.Clock;
import com.navercorp.pinpoint.common.profiler.clock.TickClock;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -10,11 +12,14 @@
* @author Woonduk Kang(emeroad)
*/
public class AgentUriStatDataTest {
private static final int DEFAULT_COLLECT_INTERVAL = 30000; // 30s

@Test
public void add_capacity() {
TickClock clock = (TickClock) Clock.tick(DEFAULT_COLLECT_INTERVAL);

long baseTimestamp = System.currentTimeMillis();
AgentUriStatData metric = new AgentUriStatData(baseTimestamp, 1);
AgentUriStatData metric = new AgentUriStatData(baseTimestamp, 1, clock);

UriStatInfo test = new UriStatInfo("test", true, 10, baseTimestamp);

Expand All @@ -24,8 +29,10 @@ public void add_capacity() {

@Test
public void add_pattern() {
TickClock clock = (TickClock) Clock.tick(DEFAULT_COLLECT_INTERVAL);

long baseTimestamp = System.currentTimeMillis();
AgentUriStatData metric = new AgentUriStatData(baseTimestamp, 10);
AgentUriStatData metric = new AgentUriStatData(baseTimestamp, 10, clock);

UriStatInfo pattern1 = new UriStatInfo("pattern1", true, 10, baseTimestamp);
metric.add(pattern1);
Expand Down

0 comments on commit bf6f84b

Please sign in to comment.