PIP-207: Add clientStats API for ProxyStats
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 160
Description
### Motivation
Add a new api named clientStats to proxy stats. After the producer or consumer is created, we can find some client stats like topic or producer name/subscription name。This is useful for knowing which topic the client is connecting to.
```json
{
"/127.0.0.1:58774":{
"channelId":"b5b8e701",
"type":"producer",
"clientId":0,
"producerName":"client01",
"createTime":"2022-09-13 11:40:56",
"topic":"persistent://pulsar/default/test-topic-partition-0"
},
"/127.0.0.1:58775":{
"channelId":"bcd86c75",
"type":"producer",
"clientId":1,
"producerName":"client01",
"createTime":"2022-09-13 11:40:56",
"topic":"persistent://pulsar/default/test-topic-partition-1"
}
}
```
### Goal
With the increase of the number of clients, it becomes unclear or even difficult to get the client associated with the topic. Therefore, it is hoped that there is an api that can obtain the relevant information of the client, and can know the associated client information when the topic changes.
### API Changes
Add a new api named clientStats to proxy stats.
```
@GET
@Path("/clients")
@ApiOperation(value = "Proxy stats api to get info for clients",
response = Map.class, responseContainer = "Map")
@ApiResponses(value = { @ApiResponse(code = 412, message = "Proxy logging should be > 0 to capture client stats"),
@ApiResponse(code = 503, message = "Proxy service is not initialized") })
public Map clients() {
return proxyService().getClientStats();
}
```
### Implementation
Added a new `ClientStats` class. This class return some client stats like `producerName/subscriptionName`. When we process a create producer request or create a subscribe request, we add client stats to the map. If the connection is closed, we remove client stats from the map.
### Alternatives
_No response_
### Anything else?
_No response_
Contributor guide
Research direction
Start by locating the proxy stats API and proxy service entry points, then trace producer creation, subscription creation, and connection-close handling. Review how existing proxy statistics are exposed and stored. Done means a GET /clients API returns the requested client fields and client entries are added and removed with their connections.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100