Hi all, I have drafted PIP-207: Add clientStats API for ProxyStats PIP link: 
https://github.com/apache/pulsar/issues/17625 

This is my first PIP. Any advice would be greatly appreciated.


Here's a copy of the contents of the GH issue for your references: 


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.


{
    "/127.0.0.1:58774":{
        "channelId":"b5b8e701",
        "type":"producer",
        "clientId":0,
        "producerName":"client01",
        "subscriptionName":"",  
        "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",
        "subscriptionName":"",  
        "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") })
&nbsp; &nbsp; public Map<String, ClientStats&gt; clients() {
&nbsp; &nbsp; &nbsp; &nbsp; return proxyService().getClientStats();
&nbsp; &nbsp; }


Implementation




Added a new `ClientStats` class. This class return some client stats&nbsp; 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.

Reply via email to