Skip to content

Commit 5031301

Browse files
committed
[#10299] Adding network information for Pinpoint inspector
1 parent e5ec4a2 commit 5031301

File tree

36 files changed

+1185
-91
lines changed

36 files changed

+1185
-91
lines changed

agent/src/main/resources/profiles/local/pinpoint.config

+8
Original file line numberDiff line numberDiff line change
@@ -1374,3 +1374,11 @@ profiler.kotlin.coroutines.record.threadName=false
13741374
#This is important information to check whether the developer's intention and the behavior of the coroutine match.
13751375
#Recommend that you use it in the development environment and not in the production environment.
13761376
profiler.kotlin.coroutines.record.cancel=false
1377+
1378+
###########################################################
1379+
# Network Metric #
1380+
###########################################################
1381+
profiler.network.metric.enable=false
1382+
profiler.network.metric.enable.udpstats=false
1383+
profiler.network.metric.enable.tcpstats=false
1384+
profiler.network.metric.collect.interval=5000

agent/src/main/resources/profiles/release/pinpoint.config

+8
Original file line numberDiff line numberDiff line change
@@ -1399,3 +1399,11 @@ profiler.kotlin.coroutines.record.threadName=false
13991399
#This is important information to check whether the developer's intention and the behavior of the coroutine match.
14001400
#Recommend that you use it in the development environment and not in the production environment.
14011401
profiler.kotlin.coroutines.record.cancel=false
1402+
1403+
###########################################################
1404+
# Network Metric #
1405+
###########################################################
1406+
profiler.network.metric.enable=false
1407+
profiler.network.metric.enable.udpstats=false
1408+
profiler.network.metric.enable.tcpstats=false
1409+
profiler.network.metric.collect.interval=5000

collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcAgentEventHandler.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.navercorp.pinpoint.grpc.trace.PAgentStat;
3232
import com.navercorp.pinpoint.grpc.trace.PAgentStatBatch;
3333
import com.navercorp.pinpoint.grpc.trace.PAgentUriStat;
34+
import com.navercorp.pinpoint.grpc.trace.PProfilerMetric;
3435
import com.navercorp.pinpoint.io.request.ServerRequest;
3536
import io.grpc.Status;
3637
import org.apache.logging.log4j.Logger;
@@ -73,7 +74,7 @@ public void handleSimple(ServerRequest<GeneratedMessageV3> serverRequest) {
7374
handleAgentStat((PAgentStat) data);
7475
} else if (data instanceof PAgentStatBatch) {
7576
handleAgentStatBatch((PAgentStatBatch) data);
76-
} else if (data instanceof PAgentUriStat) {
77+
} else if ((data instanceof PAgentUriStat) || (data instanceof PProfilerMetric)) {
7778
// do nothing
7879
} else {
7980
logger.warn("Invalid request type. serverRequest={}", serverRequest);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2023 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.navercorp.pinpoint.collector.handler.grpc.metric;
18+
19+
import com.google.protobuf.GeneratedMessageV3;
20+
import com.navercorp.pinpoint.collector.handler.grpc.GrpcMetricHandler;
21+
import com.navercorp.pinpoint.collector.mapper.grpc.stat.GrpcAgentProfilerMetricMapper;
22+
import com.navercorp.pinpoint.collector.service.AgentStatService;
23+
import com.navercorp.pinpoint.common.server.bo.stat.ProfilerMetricBo;
24+
import com.navercorp.pinpoint.grpc.MessageFormatUtils;
25+
import com.navercorp.pinpoint.grpc.trace.PProfilerMetric;
26+
import org.apache.logging.log4j.LogManager;
27+
import org.apache.logging.log4j.Logger;
28+
import org.springframework.stereotype.Service;
29+
30+
import java.util.Objects;
31+
32+
@Service
33+
public class AgentProfilerMetricHandler implements GrpcMetricHandler {
34+
private final Logger logger = LogManager.getLogger(this.getClass());
35+
private final GrpcAgentProfilerMetricMapper agentProfilerMetricMapper;
36+
private final AgentStatService[] agentStatServiceList;
37+
38+
public AgentProfilerMetricHandler(GrpcAgentProfilerMetricMapper agentProfilerMetricMapper,
39+
AgentStatService[] agentStatServiceList) {
40+
this.agentProfilerMetricMapper = Objects.requireNonNull(agentProfilerMetricMapper, "agentProfilerMetricMapper");
41+
this.agentStatServiceList = Objects.requireNonNull(agentStatServiceList, "agentStatServiceList");
42+
43+
for (AgentStatService service : this.agentStatServiceList) {
44+
logger.info("{}:{}", AgentStatService.class.getSimpleName(), service.getClass().getSimpleName());
45+
}
46+
}
47+
48+
@Override
49+
public boolean accept(GeneratedMessageV3 message) {
50+
return message instanceof PProfilerMetric;
51+
}
52+
53+
@Override
54+
public void handle(GeneratedMessageV3 message) {
55+
if (logger.isDebugEnabled()) {
56+
logger.debug("Handle PProfilerMetric={}", MessageFormatUtils.debugLog(message));
57+
}
58+
59+
final PProfilerMetric profilerMetric = (PProfilerMetric) message;
60+
final ProfilerMetricBo profilerMetricBo = this.agentProfilerMetricMapper.map(profilerMetric);
61+
if (profilerMetricBo == null) {
62+
return;
63+
}
64+
65+
handleProfilerMetric(profilerMetricBo);
66+
}
67+
68+
private void handleProfilerMetric(ProfilerMetricBo profilerMetricBo) {
69+
for (AgentStatService agentStatService : agentStatServiceList) {
70+
try {
71+
agentStatService.save(profilerMetricBo);
72+
} catch (Exception e) {
73+
logger.warn("Failed to handle service={}, AgentStatBo={}", agentStatService, profilerMetricBo, e);
74+
}
75+
}
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2023 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.navercorp.pinpoint.collector.mapper.grpc.stat;
17+
18+
import com.navercorp.pinpoint.common.server.bo.stat.ProfilerMetricBo;
19+
import com.navercorp.pinpoint.grpc.Header;
20+
import com.navercorp.pinpoint.grpc.server.ServerContext;
21+
import com.navercorp.pinpoint.grpc.trace.PProfilerMetric;
22+
import com.navercorp.pinpoint.grpc.trace.PProfilerMetricField;
23+
import org.springframework.stereotype.Component;
24+
25+
import java.util.List;
26+
27+
@Component
28+
public class GrpcAgentProfilerMetricMapper {
29+
30+
public ProfilerMetricBo map(PProfilerMetric profilerMetric) {
31+
if (profilerMetric == null) {
32+
return null;
33+
}
34+
35+
final Header agentInfo = ServerContext.getAgentInfo();
36+
final String agentId = agentInfo.getAgentId();
37+
final long startTimestamp = agentInfo.getAgentStartTime();
38+
39+
final ProfilerMetricBo profilerMetricBo = new ProfilerMetricBo();
40+
profilerMetricBo.setAgentId(agentId);
41+
profilerMetricBo.setStartTimestamp(startTimestamp);
42+
profilerMetricBo.setTimestamp(profilerMetric.getTimestamp());
43+
profilerMetricBo.setMetricName(profilerMetric.getName());
44+
45+
List<PProfilerMetricField> tags = profilerMetric.getTagsList();
46+
for (PProfilerMetricField tag : tags) {
47+
profilerMetricBo.addTags(tag.getName(), tag.getStringValue());
48+
}
49+
50+
List<PProfilerMetricField> fields = profilerMetric.getFieldsList();
51+
for (PProfilerMetricField field : fields) {
52+
profilerMetricBo.addValues(field.getName(), field.getLongValue());
53+
}
54+
55+
return profilerMetricBo;
56+
}
57+
}

collector/src/main/java/com/navercorp/pinpoint/collector/receiver/StatDispatchHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private SimpleHandler<REQ> getSimpleHandler(Header header) {
4545
// To change below code to switch table make it a little bit faster.
4646
// FIXME (2014.08) Legacy - TAgentStats should not be sent over the wire.
4747
final short type = header.getType();
48-
if (type == DefaultTBaseLocator.AGENT_STAT || type == DefaultTBaseLocator.AGENT_STAT_BATCH || type == DefaultTBaseLocator.AGENT_URI_STAT) {
48+
if (type == DefaultTBaseLocator.AGENT_STAT || type == DefaultTBaseLocator.AGENT_STAT_BATCH || type == DefaultTBaseLocator.AGENT_URI_STAT || type == DefaultTBaseLocator.AGENT_PROFILER_STAT) {
4949
return new SimpleDualHandler<>(agentStatHandler, agentEventHandler);
5050
}
5151

collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/service/StatService.java

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.navercorp.pinpoint.grpc.trace.PAgentStatBatch;
2626
import com.navercorp.pinpoint.grpc.trace.PAgentUriStat;
2727
import com.navercorp.pinpoint.grpc.trace.PStatMessage;
28+
import com.navercorp.pinpoint.grpc.trace.PProfilerMetric;
2829
import com.navercorp.pinpoint.grpc.trace.StatGrpc;
2930
import com.navercorp.pinpoint.io.header.Header;
3031
import com.navercorp.pinpoint.io.header.HeaderEntity;
@@ -79,6 +80,9 @@ public void onNext(PStatMessage statMessage) {
7980
} else if (statMessage.hasAgentUriStat()) {
8081
final Message<PAgentUriStat> message = newMessage(statMessage.getAgentUriStat(), DefaultTBaseLocator.AGENT_URI_STAT);
8182
send(message, responseObserver);
83+
} else if (statMessage.hasProfilerMetric()) {
84+
final Message<PProfilerMetric> message = newMessage(statMessage.getProfilerMetric(), DefaultTBaseLocator.AGENT_PROFILER_STAT);
85+
send(message, responseObserver);
8286
} else {
8387
if (isDebug) {
8488
logger.debug("Found empty stat message {}", MessageFormatUtils.debugLog(statMessage));

collector/src/main/java/com/navercorp/pinpoint/collector/service/AgentStatService.java

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.navercorp.pinpoint.collector.service;
1717

1818
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo;
19+
import com.navercorp.pinpoint.common.server.bo.stat.ProfilerMetricBo;
1920

2021
import javax.validation.Valid;
2122

@@ -24,4 +25,6 @@
2425
*/
2526
public interface AgentStatService {
2627
void save(@Valid AgentStatBo agentStatBo);
28+
29+
void save(@Valid ProfilerMetricBo profilerMetricBo);
2730
}

collector/src/main/java/com/navercorp/pinpoint/collector/service/HBaseAgentStatService.java

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.navercorp.pinpoint.collector.dao.AgentStatDao;
1919
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo;
20+
import com.navercorp.pinpoint.common.server.bo.stat.ProfilerMetricBo;
2021
import org.apache.logging.log4j.LogManager;
2122
import org.apache.logging.log4j.Logger;
2223
import org.springframework.stereotype.Service;
@@ -55,4 +56,9 @@ public void save(@Valid AgentStatBo agentStatBo) {
5556
}
5657
}
5758

59+
@Override
60+
public void save(ProfilerMetricBo profilerMetricBo) {
61+
// Does nothing
62+
}
63+
5864
}

collector/src/main/java/com/navercorp/pinpoint/collector/service/SendAgentStatService.java

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.navercorp.pinpoint.collector.config.FlinkProperties;
1919
import com.navercorp.pinpoint.collector.mapper.flink.TFAgentStatBatchMapper;
2020
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo;
21+
import com.navercorp.pinpoint.common.server.bo.stat.ProfilerMetricBo;
2122
import com.navercorp.pinpoint.thrift.dto.flink.TFAgentStatBatch;
2223
import org.springframework.beans.factory.annotation.Qualifier;
2324
import org.springframework.stereotype.Service;
@@ -51,4 +52,9 @@ public void save(@Valid AgentStatBo agentStatBo) {
5152
TFAgentStatBatch tFAgentStatBatch = tFAgentStatBatchMapper.map(agentStatBo);
5253
flinkService.sendData(tFAgentStatBatch);
5354
}
55+
56+
@Override
57+
public void save(ProfilerMetricBo profilerMetricBo) {
58+
// does nothing
59+
}
5460
}

commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/AgentStatType.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public enum AgentStatType {
3535
FILE_DESCRIPTOR((byte) 9, "FileDescriptor", "fileDescriptor"),
3636
DIRECT_BUFFER((byte) 10, "DirectBuffer", "directBuffer"),
3737
TOTAL_THREAD((byte) 11, "Total Thread Count", "totalThreadCount"),
38-
LOADED_CLASS((byte) 12, "Loaded Class", "loadedClass");
38+
LOADED_CLASS((byte) 12, "Loaded Class", "loadedClass"),
39+
PROFILER_METRIC((byte) 13, "Profiler Metric", "profilerMetric");
3940

4041
public static final int TYPE_CODE_BYTE_LENGTH = 1;
4142

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright 2023 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.navercorp.pinpoint.common.server.bo.stat;
17+
18+
import java.util.HashMap;
19+
import java.util.Map;
20+
import java.util.Objects;
21+
22+
public class ProfilerMetricBo implements AgentStatDataPoint {
23+
24+
public static final long UNCOLLECTED_VALUE = -1;
25+
26+
private String agentId;
27+
private long startTimestamp;
28+
private long timestamp;
29+
private String metricName; // is this necessary?
30+
private final Map<String, String> tags = new HashMap<>();
31+
private final Map<String, Double> values = new HashMap<>();
32+
33+
@Override
34+
public String getAgentId() {
35+
return agentId;
36+
}
37+
38+
@Override
39+
public void setAgentId(String agentId) {
40+
this.agentId = agentId;
41+
}
42+
43+
@Override
44+
public long getStartTimestamp() {
45+
return startTimestamp;
46+
}
47+
48+
@Override
49+
public void setStartTimestamp(long startTimestamp) {
50+
this.startTimestamp = startTimestamp;
51+
}
52+
53+
@Override
54+
public long getTimestamp() {
55+
return timestamp;
56+
}
57+
58+
@Override
59+
public void setTimestamp(long timestamp) {
60+
this.timestamp = timestamp;
61+
}
62+
63+
@Override
64+
public AgentStatType getAgentStatType() {
65+
return AgentStatType.PROFILER_METRIC;
66+
}
67+
68+
public void addTags(String name, String value) {
69+
tags.put(name, value);
70+
}
71+
72+
public Map<String, String> getTags() {
73+
return tags;
74+
}
75+
76+
public void addValues(String name, double value) {
77+
values.put(name, value);
78+
}
79+
80+
public Map<String, Double> getValues() {
81+
return values;
82+
}
83+
84+
public void setMetricName(String metricName) {
85+
this.metricName = Objects.requireNonNull(metricName);
86+
}
87+
88+
public String getMetricName() {
89+
return metricName;
90+
}
91+
}

grpc/grpc-idl

inspector-module/inspector-collector/src/main/java/com/navercorp/pinpoint/inspector/collector/dao/AgentStatDao.java

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo;
2020
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint;
21+
import com.navercorp.pinpoint.common.server.bo.stat.ProfilerMetricBo;
2122
import org.springframework.stereotype.Repository;
2223

2324
import java.util.List;

inspector-module/inspector-collector/src/main/java/com/navercorp/pinpoint/inspector/collector/dao/pinot/DefaultAgentStatDao.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public class DefaultAgentStatDao <T extends AgentStatDataPoint> implements Agent
3535

3636
private final Logger logger = LogManager.getLogger(DefaultAgentStatDao.class.getName());
3737

38-
private final Function<AgentStatBo, List<T>> dataPointFunction;
38+
private final Function<AgentStatBo, List<T>> agentStatBoDataPointFunction;
3939
private final Function<List<T>, List<AgentStat>> convertToKafkaModelFunction;
4040
private final KafkaTemplate kafkaAgentStatTemplate;
4141
private final String topic;
4242

43-
public DefaultAgentStatDao(Function<AgentStatBo, List<T>> dataPointFunction, KafkaTemplate kafkaAgentStatTemplate, Function<List<T>, List<AgentStat>> convertToKafkaModelFunction, String topic) {
44-
this.dataPointFunction = Objects.requireNonNull(dataPointFunction, "dataPointFunction");
43+
public DefaultAgentStatDao(Function<AgentStatBo, List<T>> agentStatBoDataPointFunction, KafkaTemplate kafkaAgentStatTemplate, Function<List<T>, List<AgentStat>> convertToKafkaModelFunction, String topic) {
44+
this.agentStatBoDataPointFunction = Objects.requireNonNull(agentStatBoDataPointFunction, "dataPointFunction");
4545
this.kafkaAgentStatTemplate = Objects.requireNonNull(kafkaAgentStatTemplate, "kafkaAgentStatTemplate");
4646
this.convertToKafkaModelFunction = convertToKafkaModelFunction;
4747
this.topic = topic;
@@ -64,7 +64,7 @@ private List<AgentStat> convertDataToKafkaModel(List<T> AgentStatDataPointList)
6464
@Override
6565
public void dispatch(AgentStatBo agentStatBo) {
6666
Objects.requireNonNull(agentStatBo, "agentStatBo");
67-
List<T> dataPointList = this.dataPointFunction.apply(agentStatBo);
67+
List<T> dataPointList = this.agentStatBoDataPointFunction.apply(agentStatBo);
6868
insert(agentStatBo.getAgentId(), dataPointList);
6969
}
7070

0 commit comments

Comments
 (0)