forked from pinpoint-apm/pinpoint
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pinpoint-apm#10420] Removed PinpointNettyServerBuilder, Tracing gRPC…
… logId
- Loading branch information
youngjin.kim2
committed
Oct 22, 2023
1 parent
0601f71
commit ded5cfe
Showing
26 changed files
with
357 additions
and
1,340 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
145 changes: 50 additions & 95 deletions
145
collector/src/main/java/com/navercorp/pinpoint/collector/controller/ChannelzController.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 |
---|---|---|
@@ -1,134 +1,89 @@ | ||
package com.navercorp.pinpoint.collector.controller; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.navercorp.pinpoint.collector.receiver.grpc.GrpcReceiverNames; | ||
import com.navercorp.pinpoint.grpc.channelz.ChannelzRegistry; | ||
import com.navercorp.pinpoint.grpc.channelz.ChannelzUtils; | ||
import io.grpc.InternalChannelz; | ||
import io.grpc.InternalInstrumented; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.ArrayList; | ||
import com.navercorp.pinpoint.collector.service.ChannelzService; | ||
import com.navercorp.pinpoint.collector.service.ChannelzService.ServerStatsWithId; | ||
import com.navercorp.pinpoint.collector.service.ChannelzService.SocketStatsWithId; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
|
||
@RestController | ||
@RequestMapping("/channelz") | ||
public class ChannelzController { | ||
|
||
private final ChannelzRegistry channelzRegistry; | ||
private final InternalChannelz channelz = InternalChannelz.instance(); | ||
private final ObjectMapper mapper; | ||
private final ChannelzService channelzService; | ||
|
||
public ChannelzController(ChannelzRegistry channelzRegistry, ObjectMapper objectMapper) { | ||
this.channelzRegistry = Objects.requireNonNull(channelzRegistry, "channelzRegistry"); | ||
this.mapper = Objects.requireNonNull(objectMapper, "objectMapper"); | ||
public ChannelzController(ChannelzService channelzService) { | ||
this.channelzService = Objects.requireNonNull(channelzService, "channelzService"); | ||
} | ||
|
||
@GetMapping("/getSocket") | ||
public String getSocket(long logId) throws JsonProcessingException { | ||
InternalChannelz.SocketStats stats = getSocket0(logId); | ||
|
||
return mapper.writeValueAsString(stats); | ||
@GetMapping(value = "/sockets/{logId}") | ||
public SocketStatsWithId findSocketStatsByLogId(@PathVariable long logId) { | ||
return this.channelzService.getSocketStats(logId); | ||
} | ||
|
||
@GetMapping("/html/getSocket") | ||
public String getSocketToHtml(long logId) { | ||
InternalChannelz.SocketStats stats = getSocket0(logId); | ||
|
||
return new HTMLBuilder().build(stats); | ||
@GetMapping(value = "/sockets/{logId}", produces = MediaType.TEXT_HTML_VALUE) | ||
public String findSocketStatsByLogIdInHtml(@PathVariable long logId) { | ||
return buildHtml(this.findSocketStatsByLogId(logId)); | ||
} | ||
|
||
private InternalChannelz.SocketStats getSocket0(long logId) { | ||
InternalInstrumented<InternalChannelz.SocketStats> socket = channelz.getSocket(logId); | ||
if (socket == null) { | ||
return null; | ||
} | ||
return ChannelzUtils.getResult("Socket", socket); | ||
@GetMapping(value = "/sockets") | ||
public List<SocketStatsWithId> findSocketStats( | ||
@RequestParam(required = false) String remoteAddress, | ||
@RequestParam(required = false) Integer localPort | ||
) throws Exception { | ||
return this.channelzService.getSocketStatsList(remoteAddress, localPort); | ||
} | ||
|
||
@GetMapping("/findSocket") | ||
public String findSocket(String remoteAddress, int localPort) throws JsonProcessingException { | ||
|
||
ChannelzRegistry.AddressId addressId = ChannelzRegistry.AddressId.newAddressId(remoteAddress, localPort); | ||
List<InternalChannelz.SocketStats> stats = findSocket(addressId); | ||
if (stats == null) { | ||
return notFound("remoteAddress:" + remoteAddress + " localPort:" + localPort); | ||
} | ||
|
||
return mapper.writeValueAsString(stats); | ||
@GetMapping(value = "/sockets", produces = MediaType.TEXT_HTML_VALUE) | ||
public String findSocketStatInHtml( | ||
@RequestParam(required = false) String remoteAddress, | ||
@RequestParam(required = false) Integer localPort | ||
) throws Exception { | ||
return buildHtml(this.findSocketStats(remoteAddress, localPort)); | ||
} | ||
|
||
@GetMapping("/html/findSocket") | ||
public String findSocketStatToHtml(String remoteAddress, int localPort) { | ||
|
||
ChannelzRegistry.AddressId targetAddress = ChannelzRegistry.AddressId.newAddressId(remoteAddress, localPort); | ||
|
||
List<InternalChannelz.SocketStats> stats = findSocket(targetAddress); | ||
if (stats.isEmpty()) { | ||
return notFound("remoteAddress:" + remoteAddress + " localPort:" + localPort); | ||
} | ||
|
||
return buildHtml(stats); | ||
@GetMapping(value = "/servers") | ||
public List<ServerStatsWithId> getAllServerStats() { | ||
return this.channelzService.getAllServers(); | ||
} | ||
|
||
@GetMapping(value = "/servers", produces = MediaType.TEXT_HTML_VALUE) | ||
public String getAllServerStatsInHtml() { | ||
return buildHtml(this.getAllServerStats()); | ||
} | ||
|
||
private List<InternalChannelz.SocketStats> findSocket(ChannelzRegistry.AddressId targetAddress) { | ||
Set<Long> logIdSet = channelzRegistry.getSocketLogId(targetAddress); | ||
@GetMapping(value = "/servers/{name}") | ||
public ServerStatsWithId getServerStat(@PathVariable("name") String name) { | ||
return this.channelzService.getServer(name); | ||
} | ||
|
||
List<InternalInstrumented<InternalChannelz.SocketStats>> result = new ArrayList<>(); | ||
for (Long logId : logIdSet) { | ||
InternalInstrumented<InternalChannelz.SocketStats> socket = channelz.getSocket(logId); | ||
if (socket != null) { | ||
result.add(socket); | ||
} | ||
} | ||
return ChannelzUtils.getResults("Socket", result); | ||
@GetMapping(value = "/servers/{name}", produces = MediaType.TEXT_HTML_VALUE) | ||
public String getServerStatInHtml(@PathVariable("name") String name) { | ||
return buildHtml(this.getServerStat(name)); | ||
} | ||
|
||
@GetMapping("/html/getServer") | ||
public String getServerStatToHtml(String serverName) { | ||
List<InternalChannelz.ServerStats> stats = getServer(serverName); | ||
if (stats == null) { | ||
return notFound("serverName=" + serverName); | ||
private static <T> String buildHtml(List<T> stats) { | ||
if (stats == null || stats.isEmpty()) { | ||
return "Empty"; | ||
} | ||
return buildHtml(stats); | ||
} | ||
|
||
private <T> String buildHtml(List<T> stats) { | ||
StringBuilder buffer = new StringBuilder(); | ||
for (T stat : stats) { | ||
String html = new HTMLBuilder().build(stat); | ||
buffer.append(html); | ||
buffer.append(buildHtml(stat)); | ||
buffer.append("<br>"); | ||
} | ||
return buffer.toString(); | ||
} | ||
|
||
|
||
@GetMapping("/html/getSpanReceiver") | ||
public String getSpanReceiverl() { | ||
return getServerStatToHtml(GrpcReceiverNames.SPAN); | ||
} | ||
|
||
|
||
private List<InternalChannelz.ServerStats> getServer(String serverName) { | ||
Long logId = channelzRegistry.getServerLogId(serverName); | ||
|
||
InternalChannelz.ServerList serverList = channelz.getServers(logId, 10000); | ||
|
||
return ChannelzUtils.getResults("ServerStats", serverList.servers); | ||
} | ||
|
||
|
||
private String notFound(String target) { | ||
return target + " not Found"; | ||
private static <T> String buildHtml(T stats) { | ||
if (stats == null) { | ||
return "Null"; | ||
} | ||
return new HTMLBuilder().build(stats); | ||
} | ||
|
||
|
||
} |
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
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
Oops, something went wrong.