-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
- Loading branch information
There are no files selected for viewing
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()); | ||
Check warning on line 34 in collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentProfilerMetricHandler.java
|
||
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"); | ||
Check warning on line 41 in collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentProfilerMetricHandler.java
|
||
|
||
for (AgentStatService service : this.agentStatServiceList) { | ||
logger.info("{}:{}", AgentStatService.class.getSimpleName(), service.getClass().getSimpleName()); | ||
Check warning on line 44 in collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentProfilerMetricHandler.java
|
||
} | ||
} | ||
Check warning on line 46 in collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentProfilerMetricHandler.java
|
||
|
||
@Override | ||
public boolean accept(GeneratedMessageV3 message) { | ||
return message instanceof PProfilerMetric; | ||
Check warning on line 50 in collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentProfilerMetricHandler.java
|
||
} | ||
|
||
@Override | ||
public void handle(GeneratedMessageV3 message) { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("Handle PProfilerMetric={}", MessageFormatUtils.debugLog(message)); | ||
Check warning on line 56 in collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentProfilerMetricHandler.java
|
||
} | ||
|
||
final PProfilerMetric profilerMetric = (PProfilerMetric) message; | ||
final ProfilerMetricBo profilerMetricBo = this.agentProfilerMetricMapper.map(profilerMetric); | ||
Check warning on line 60 in collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentProfilerMetricHandler.java
|
||
if (profilerMetricBo == null) { | ||
return; | ||
Check warning on line 62 in collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentProfilerMetricHandler.java
|
||
} | ||
|
||
handleProfilerMetric(profilerMetricBo); | ||
} | ||
Check warning on line 66 in collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentProfilerMetricHandler.java
|
||
|
||
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); | ||
} | ||
Check warning on line 74 in collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentProfilerMetricHandler.java
|
||
} | ||
} | ||
Check warning on line 76 in collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentProfilerMetricHandler.java
|
||
} |
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 { | ||
Check warning on line 28 in collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentProfilerMetricMapper.java
|
||
|
||
public ProfilerMetricBo map(PProfilerMetric profilerMetric) { | ||
if (profilerMetric == null) { | ||
return null; | ||
Check warning on line 32 in collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentProfilerMetricMapper.java
|
||
} | ||
|
||
final Header agentInfo = ServerContext.getAgentInfo(); | ||
final String agentId = agentInfo.getAgentId(); | ||
final long startTimestamp = agentInfo.getAgentStartTime(); | ||
Check warning on line 37 in collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentProfilerMetricMapper.java
|
||
|
||
final ProfilerMetricBo profilerMetricBo = new ProfilerMetricBo(); | ||
profilerMetricBo.setAgentId(agentId); | ||
profilerMetricBo.setStartTimestamp(startTimestamp); | ||
profilerMetricBo.setTimestamp(profilerMetric.getTimestamp()); | ||
profilerMetricBo.setMetricName(profilerMetric.getName()); | ||
Check warning on line 43 in collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentProfilerMetricMapper.java
|
||
|
||
List<PProfilerMetricField> tags = profilerMetric.getTagsList(); | ||
Check warning on line 45 in collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentProfilerMetricMapper.java
|
||
for (PProfilerMetricField tag : tags) { | ||
profilerMetricBo.addTags(tag.getName(), tag.getStringValue()); | ||
} | ||
Check warning on line 48 in collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentProfilerMetricMapper.java
|
||
|
||
List<PProfilerMetricField> fields = profilerMetric.getFieldsList(); | ||
Check warning on line 50 in collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentProfilerMetricMapper.java
|
||
for (PProfilerMetricField field : fields) { | ||
profilerMetricBo.addValues(field.getName(), field.getLongValue()); | ||
} | ||
Check warning on line 53 in collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentProfilerMetricMapper.java
|
||
|
||
return profilerMetricBo; | ||
Check warning on line 55 in collector/src/main/java/com/navercorp/pinpoint/collector/mapper/grpc/stat/GrpcAgentProfilerMetricMapper.java
|
||
} | ||
} |
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 { | ||
Check warning on line 22 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
|
||
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<>(); | ||
Check warning on line 31 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
|
||
@Override | ||
public String getAgentId() { | ||
return agentId; | ||
Check warning on line 35 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
} | ||
|
||
@Override | ||
public void setAgentId(String agentId) { | ||
this.agentId = agentId; | ||
} | ||
Check warning on line 41 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
|
||
@Override | ||
public long getStartTimestamp() { | ||
return startTimestamp; | ||
Check warning on line 45 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
} | ||
|
||
@Override | ||
public void setStartTimestamp(long startTimestamp) { | ||
this.startTimestamp = startTimestamp; | ||
} | ||
Check warning on line 51 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
|
||
@Override | ||
public long getTimestamp() { | ||
return timestamp; | ||
Check warning on line 55 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
} | ||
|
||
@Override | ||
public void setTimestamp(long timestamp) { | ||
this.timestamp = timestamp; | ||
} | ||
Check warning on line 61 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
|
||
@Override | ||
public AgentStatType getAgentStatType() { | ||
return AgentStatType.PROFILER_METRIC; | ||
Check warning on line 65 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
} | ||
|
||
public void addTags(String name, String value) { | ||
tags.put(name, value); | ||
} | ||
Check warning on line 70 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
|
||
public Map<String, String> getTags() { | ||
return tags; | ||
Check warning on line 73 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
} | ||
|
||
public void addValues(String name, double value) { | ||
values.put(name, value); | ||
} | ||
Check warning on line 78 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
|
||
public Map<String, Double> getValues() { | ||
return values; | ||
Check warning on line 81 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
} | ||
|
||
public void setMetricName(String metricName) { | ||
this.metricName = Objects.requireNonNull(metricName); | ||
} | ||
Check warning on line 86 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
|
||
public String getMetricName() { | ||
return metricName; | ||
Check warning on line 89 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/stat/ProfilerMetricBo.java
|
||
} | ||
} |