-
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.
[#9563] Dynamic loading of GrpcMetricHandler
- Loading branch information
Showing
6 changed files
with
230 additions
and
122 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
11 changes: 11 additions & 0 deletions
11
collector/src/main/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcMetricHandler.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,11 @@ | ||
package com.navercorp.pinpoint.collector.handler.grpc; | ||
|
||
import com.google.protobuf.GeneratedMessageV3; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public interface GrpcMetricHandler { | ||
boolean accept(GeneratedMessageV3 message); | ||
|
||
void handle(GeneratedMessageV3 message); | ||
} |
52 changes: 52 additions & 0 deletions
52
...in/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentMetricBatchHandler.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,52 @@ | ||
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.GrpcAgentStatBatchMapper; | ||
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo; | ||
import com.navercorp.pinpoint.grpc.Header; | ||
import com.navercorp.pinpoint.grpc.MessageFormatUtils; | ||
import com.navercorp.pinpoint.grpc.server.ServerContext; | ||
import com.navercorp.pinpoint.grpc.trace.PAgentStatBatch; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Objects; | ||
|
||
@Component | ||
public class AgentMetricBatchHandler implements GrpcMetricHandler { | ||
private final Logger logger = LogManager.getLogger(this.getClass()); | ||
|
||
private final GrpcAgentStatBatchMapper agentStatBatchMapper; | ||
|
||
private final AgentMetricHandler agentMetricHandler; | ||
|
||
|
||
public AgentMetricBatchHandler(GrpcAgentStatBatchMapper agentStatBatchMapper, | ||
AgentMetricHandler agentMetricHandler) { | ||
this.agentStatBatchMapper = Objects.requireNonNull(agentStatBatchMapper, "agentStatBatchMapper"); | ||
this.agentMetricHandler = Objects.requireNonNull(agentMetricHandler, "agentStatHandler"); | ||
} | ||
|
||
@Override | ||
public boolean accept(GeneratedMessageV3 message) { | ||
return message instanceof PAgentStatBatch; | ||
} | ||
|
||
@Override | ||
public void handle(GeneratedMessageV3 message) { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("Handle PAgentStatBatch={}", MessageFormatUtils.debugLog(message)); | ||
} | ||
final PAgentStatBatch agentStatBatch = (PAgentStatBatch) message; | ||
|
||
final Header header = ServerContext.getAgentInfo(); | ||
final AgentStatBo agentStatBo = this.agentStatBatchMapper.map(agentStatBatch, header); | ||
if (agentStatBo == null) { | ||
return; | ||
} | ||
|
||
this.agentMetricHandler.handleAgentStat(agentStatBo); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...rc/main/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentMetricHandler.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,63 @@ | ||
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.GrpcAgentStatMapper; | ||
import com.navercorp.pinpoint.collector.service.AgentStatService; | ||
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo; | ||
import com.navercorp.pinpoint.grpc.MessageFormatUtils; | ||
import com.navercorp.pinpoint.grpc.trace.PAgentStat; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Objects; | ||
|
||
@Component | ||
public class AgentMetricHandler implements GrpcMetricHandler { | ||
private final Logger logger = LogManager.getLogger(this.getClass()); | ||
|
||
private final GrpcAgentStatMapper agentStatMapper; | ||
|
||
private final AgentStatService[] agentStatServiceList; | ||
|
||
public AgentMetricHandler(GrpcAgentStatMapper agentStatMapper, | ||
AgentStatService[] agentStatServiceList) { | ||
this.agentStatMapper = Objects.requireNonNull(agentStatMapper, "agentStatMapper"); | ||
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 PAgentStat; | ||
} | ||
|
||
@Override | ||
public void handle(GeneratedMessageV3 message) { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("Handle PAgentStat={}", MessageFormatUtils.debugLog(message)); | ||
} | ||
final PAgentStat agentStat = (PAgentStat) message; | ||
|
||
final AgentStatBo agentStatBo = this.agentStatMapper.map(agentStat); | ||
if (agentStatBo == null) { | ||
return; | ||
} | ||
|
||
handleAgentStat(agentStatBo); | ||
} | ||
|
||
public void handleAgentStat(AgentStatBo agentStatBo) { | ||
for (AgentStatService agentStatService : agentStatServiceList) { | ||
try { | ||
agentStatService.save(agentStatBo); | ||
} catch (Exception e) { | ||
logger.warn("Failed to handle service={}, AgentStatBo={}", agentStatService, agentStatBo, e); | ||
} | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...main/java/com/navercorp/pinpoint/collector/handler/grpc/metric/AgentUriMetricHandler.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 @@ | ||
package com.navercorp.pinpoint.collector.handler.grpc.metric; | ||
|
||
import com.google.protobuf.GeneratedMessageV3; | ||
import com.navercorp.pinpoint.collector.config.CollectorConfiguration; | ||
import com.navercorp.pinpoint.collector.handler.grpc.GrpcMetricHandler; | ||
import com.navercorp.pinpoint.collector.mapper.grpc.stat.GrpcAgentUriStatMapper; | ||
import com.navercorp.pinpoint.collector.service.AgentUriStatService; | ||
import com.navercorp.pinpoint.common.server.bo.stat.AgentUriStatBo; | ||
import com.navercorp.pinpoint.grpc.MessageFormatUtils; | ||
import com.navercorp.pinpoint.grpc.trace.PAgentUriStat; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Objects; | ||
|
||
@Component | ||
public class AgentUriMetricHandler implements GrpcMetricHandler { | ||
|
||
private final Logger logger = LogManager.getLogger(this.getClass()); | ||
|
||
private final GrpcAgentUriStatMapper agentUriStatMapper; | ||
private final AgentUriStatService agentUriStatService; | ||
|
||
private final boolean uriStatEnable; | ||
|
||
public AgentUriMetricHandler(CollectorConfiguration collectorConfiguration, | ||
GrpcAgentUriStatMapper agentUriStatMapper, | ||
AgentUriStatService agentUriStatService) { | ||
Objects.requireNonNull(collectorConfiguration, "collectorConfiguration"); | ||
this.uriStatEnable = collectorConfiguration.isUriStatEnable(); | ||
|
||
this.agentUriStatMapper = Objects.requireNonNull(agentUriStatMapper, "agentUriStatMapper"); | ||
this.agentUriStatService = Objects.requireNonNull(agentUriStatService, "agentUriStatService"); | ||
} | ||
|
||
@Override | ||
public boolean accept(GeneratedMessageV3 message) { | ||
return message instanceof PAgentUriStat; | ||
|
||
} | ||
|
||
@Override | ||
public void handle(GeneratedMessageV3 message) { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("Handle PAgentUriStat={}", MessageFormatUtils.debugLog(message)); | ||
} | ||
if (!uriStatEnable) { | ||
return; | ||
} | ||
final PAgentUriStat agentUriStat = (PAgentUriStat) message; | ||
final AgentUriStatBo agentUriStatBo = agentUriStatMapper.map(agentUriStat); | ||
agentUriStatService.save(agentUriStatBo); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AgentUriStatHandler{" + | ||
"uriStatEnable=" + uriStatEnable + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.