Skip to content

Commit

Permalink
[#10299] Adding network information for Pinpoint inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-ram committed Sep 25, 2023
1 parent e5ec4a2 commit e7c3203
Show file tree
Hide file tree
Showing 36 changed files with 1,185 additions and 91 deletions.
8 changes: 8 additions & 0 deletions agent/src/main/resources/profiles/local/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -1374,3 +1374,11 @@ profiler.kotlin.coroutines.record.threadName=false
#This is important information to check whether the developer's intention and the behavior of the coroutine match.
#Recommend that you use it in the development environment and not in the production environment.
profiler.kotlin.coroutines.record.cancel=false

###########################################################
# Network Metric #
###########################################################
profiler.network.metric.enable=false
profiler.network.metric.enable.udpstats=false
profiler.network.metric.enable.tcpstats=false
profiler.network.metric.collect.interval=5000
8 changes: 8 additions & 0 deletions agent/src/main/resources/profiles/release/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -1399,3 +1399,11 @@ profiler.kotlin.coroutines.record.threadName=false
#This is important information to check whether the developer's intention and the behavior of the coroutine match.
#Recommend that you use it in the development environment and not in the production environment.
profiler.kotlin.coroutines.record.cancel=false

###########################################################
# Network Metric #
###########################################################
profiler.network.metric.enable=false
profiler.network.metric.enable.udpstats=false
profiler.network.metric.enable.tcpstats=false
profiler.network.metric.collect.interval=5000
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.navercorp.pinpoint.grpc.trace.PAgentStat;
import com.navercorp.pinpoint.grpc.trace.PAgentStatBatch;
import com.navercorp.pinpoint.grpc.trace.PAgentUriStat;
import com.navercorp.pinpoint.grpc.trace.PProfilerMetric;
import com.navercorp.pinpoint.io.request.ServerRequest;
import io.grpc.Status;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -73,7 +74,7 @@ public void handleSimple(ServerRequest<GeneratedMessageV3> serverRequest) {
handleAgentStat((PAgentStat) data);
} else if (data instanceof PAgentStatBatch) {
handleAgentStatBatch((PAgentStatBatch) data);
} else if (data instanceof PAgentUriStat) {
} else if ((data instanceof PAgentUriStat) || (data instanceof PProfilerMetric)) {
// do nothing
} else {
logger.warn("Invalid request type. serverRequest={}", serverRequest);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2023 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.handler.grpc.metric;

import com.google.protobuf.GeneratedMessageV3;
import com.navercorp.pinpoint.collector.handler.grpc.GrpcMetricHandler;
import com.navercorp.pinpoint.collector.mapper.grpc.stat.GrpcAgentProfilerMetricMapper;
import com.navercorp.pinpoint.collector.service.AgentStatService;
import com.navercorp.pinpoint.common.server.bo.stat.ProfilerMetricBo;
import com.navercorp.pinpoint.grpc.MessageFormatUtils;
import com.navercorp.pinpoint.grpc.trace.PProfilerMetric;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class AgentProfilerMetricHandler implements GrpcMetricHandler {
private final Logger logger = LogManager.getLogger(this.getClass());
private final GrpcAgentProfilerMetricMapper agentProfilerMetricMapper;
private final AgentStatService[] agentStatServiceList;

public AgentProfilerMetricHandler(GrpcAgentProfilerMetricMapper agentProfilerMetricMapper,
AgentStatService[] agentStatServiceList) {
this.agentProfilerMetricMapper = Objects.requireNonNull(agentProfilerMetricMapper, "agentProfilerMetricMapper");
this.agentStatServiceList = Objects.requireNonNull(agentStatServiceList, "agentStatServiceList");

for (AgentStatService service : this.agentStatServiceList) {
logger.info("{}:{}", AgentStatService.class.getSimpleName(), service.getClass().getSimpleName());
}
}

@Override
public boolean accept(GeneratedMessageV3 message) {
return message instanceof PProfilerMetric;
}

@Override
public void handle(GeneratedMessageV3 message) {
if (logger.isDebugEnabled()) {
logger.debug("Handle PProfilerMetric={}", MessageFormatUtils.debugLog(message));
}

final PProfilerMetric profilerMetric = (PProfilerMetric) message;
final ProfilerMetricBo profilerMetricBo = this.agentProfilerMetricMapper.map(profilerMetric);
if (profilerMetricBo == null) {
return;
}

handleProfilerMetric(profilerMetricBo);
}

private void handleProfilerMetric(ProfilerMetricBo profilerMetricBo) {
for (AgentStatService agentStatService : agentStatServiceList) {
try {
agentStatService.save(profilerMetricBo);
} catch (Exception e) {
logger.warn("Failed to handle service={}, AgentStatBo={}", agentStatService, profilerMetricBo, e);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2023 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.mapper.grpc.stat;

import com.navercorp.pinpoint.common.server.bo.stat.ProfilerMetricBo;
import com.navercorp.pinpoint.grpc.Header;
import com.navercorp.pinpoint.grpc.server.ServerContext;
import com.navercorp.pinpoint.grpc.trace.PProfilerMetric;
import com.navercorp.pinpoint.grpc.trace.PProfilerMetricField;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class GrpcAgentProfilerMetricMapper {

public ProfilerMetricBo map(PProfilerMetric profilerMetric) {
if (profilerMetric == null) {
return null;
}

final Header agentInfo = ServerContext.getAgentInfo();
final String agentId = agentInfo.getAgentId();
final long startTimestamp = agentInfo.getAgentStartTime();

final ProfilerMetricBo profilerMetricBo = new ProfilerMetricBo();
profilerMetricBo.setAgentId(agentId);
profilerMetricBo.setStartTimestamp(startTimestamp);
profilerMetricBo.setTimestamp(profilerMetric.getTimestamp());
profilerMetricBo.setMetricName(profilerMetric.getName());

List<PProfilerMetricField> tags = profilerMetric.getTagsList();
for (PProfilerMetricField tag : tags) {
profilerMetricBo.addTags(tag.getName(), tag.getStringValue());
}

List<PProfilerMetricField> fields = profilerMetric.getFieldsList();
for (PProfilerMetricField field : fields) {
profilerMetricBo.addValues(field.getName(), field.getLongValue());
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.navercorp.pinpoint.grpc.trace.PAgentStatBatch;
import com.navercorp.pinpoint.grpc.trace.PAgentUriStat;
import com.navercorp.pinpoint.grpc.trace.PStatMessage;
import com.navercorp.pinpoint.grpc.trace.PProfilerMetric;
import com.navercorp.pinpoint.grpc.trace.StatGrpc;
import com.navercorp.pinpoint.io.header.Header;
import com.navercorp.pinpoint.io.header.HeaderEntity;
Expand Down Expand Up @@ -79,6 +80,9 @@ public void onNext(PStatMessage statMessage) {
} else if (statMessage.hasAgentUriStat()) {
final Message<PAgentUriStat> message = newMessage(statMessage.getAgentUriStat(), DefaultTBaseLocator.AGENT_URI_STAT);
send(message, responseObserver);
} else if (statMessage.hasProfilerMetric()) {
final Message<PProfilerMetric> message = newMessage(statMessage.getProfilerMetric(), DefaultTBaseLocator.AGENT_PROFILER_STAT);
send(message, responseObserver);
} else {
if (isDebug) {
logger.debug("Found empty stat message {}", MessageFormatUtils.debugLog(statMessage));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.navercorp.pinpoint.collector.service;

import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo;
import com.navercorp.pinpoint.common.server.bo.stat.ProfilerMetricBo;

import javax.validation.Valid;

Expand All @@ -24,4 +25,6 @@
*/
public interface AgentStatService {
void save(@Valid AgentStatBo agentStatBo);

void save(@Valid ProfilerMetricBo profilerMetricBo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.navercorp.pinpoint.collector.dao.AgentStatDao;
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo;
import com.navercorp.pinpoint.common.server.bo.stat.ProfilerMetricBo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -55,4 +56,9 @@ public void save(@Valid AgentStatBo agentStatBo) {
}
}

@Override
public void save(ProfilerMetricBo profilerMetricBo) {
// Does nothing
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.navercorp.pinpoint.collector.config.FlinkProperties;
import com.navercorp.pinpoint.collector.mapper.flink.TFAgentStatBatchMapper;
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo;
import com.navercorp.pinpoint.common.server.bo.stat.ProfilerMetricBo;
import com.navercorp.pinpoint.thrift.dto.flink.TFAgentStatBatch;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -51,4 +52,9 @@ public void save(@Valid AgentStatBo agentStatBo) {
TFAgentStatBatch tFAgentStatBatch = tFAgentStatBatchMapper.map(agentStatBo);
flinkService.sendData(tFAgentStatBatch);
}

@Override
public void save(ProfilerMetricBo profilerMetricBo) {
// does nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public enum AgentStatType {
FILE_DESCRIPTOR((byte) 9, "FileDescriptor", "fileDescriptor"),
DIRECT_BUFFER((byte) 10, "DirectBuffer", "directBuffer"),
TOTAL_THREAD((byte) 11, "Total Thread Count", "totalThreadCount"),
LOADED_CLASS((byte) 12, "Loaded Class", "loadedClass");
LOADED_CLASS((byte) 12, "Loaded Class", "loadedClass"),
PROFILER_METRIC((byte) 13, "Profiler Metric", "profilerMetric");

public static final int TYPE_CODE_BYTE_LENGTH = 1;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2023 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.stat;

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

public class ProfilerMetricBo implements AgentStatDataPoint {

public static final long UNCOLLECTED_VALUE = -1;

private String agentId;
private long startTimestamp;
private long timestamp;
private String metricName; // is this necessary?
private final Map<String, String> tags = new HashMap<>();
private final Map<String, Double> values = new HashMap<>();

@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.PROFILER_METRIC;
}

public void addTags(String name, String value) {
tags.put(name, value);
}

public Map<String, String> getTags() {
return tags;
}

public void addValues(String name, double value) {
values.put(name, value);
}

public Map<String, Double> getValues() {
return values;
}

public void setMetricName(String metricName) {
this.metricName = Objects.requireNonNull(metricName);
}

public String getMetricName() {
return metricName;
}
}
2 changes: 1 addition & 1 deletion grpc/grpc-idl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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.ProfilerMetricBo;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public class DefaultAgentStatDao <T extends AgentStatDataPoint> implements Agent

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

private final Function<AgentStatBo, List<T>> dataPointFunction;
private final Function<AgentStatBo, List<T>> agentStatBoDataPointFunction;
private final Function<List<T>, List<AgentStat>> convertToKafkaModelFunction;
private final KafkaTemplate kafkaAgentStatTemplate;
private final String topic;

public DefaultAgentStatDao(Function<AgentStatBo, List<T>> dataPointFunction, KafkaTemplate kafkaAgentStatTemplate, Function<List<T>, List<AgentStat>> convertToKafkaModelFunction, String topic) {
this.dataPointFunction = Objects.requireNonNull(dataPointFunction, "dataPointFunction");
public DefaultAgentStatDao(Function<AgentStatBo, List<T>> agentStatBoDataPointFunction, KafkaTemplate kafkaAgentStatTemplate, Function<List<T>, List<AgentStat>> convertToKafkaModelFunction, String topic) {
this.agentStatBoDataPointFunction = Objects.requireNonNull(agentStatBoDataPointFunction, "dataPointFunction");
this.kafkaAgentStatTemplate = Objects.requireNonNull(kafkaAgentStatTemplate, "kafkaAgentStatTemplate");
this.convertToKafkaModelFunction = convertToKafkaModelFunction;
this.topic = topic;
Expand All @@ -64,7 +64,7 @@ private List<AgentStat> convertDataToKafkaModel(List<T> AgentStatDataPointList)
@Override
public void dispatch(AgentStatBo agentStatBo) {
Objects.requireNonNull(agentStatBo, "agentStatBo");
List<T> dataPointList = this.dataPointFunction.apply(agentStatBo);
List<T> dataPointList = this.agentStatBoDataPointFunction.apply(agentStatBo);
insert(agentStatBo.getAgentId(), dataPointList);
}

Expand Down
Loading

0 comments on commit e7c3203

Please sign in to comment.