In confluent kafka rest proxy we can get the last committed offset of particular consumer group but how can we get the latest offset of topic to calculate the lag.
2 Answers
You can use Kafka REST Proxy to fetch the latest offset committed for a particular partition. According to the Confluent Docs,
GET /consumers/(string: group_name)/instances/(string: instance)/offsets
Get the last committed offsets for the given partitions (whether the commit happened by this process or another).
Note that this request must be made to the specific REST proxy instance holding the consumer instance.
Parameters:
group_name (string) -- The name of the consumer group
instance (string) -- The ID of the consumer instance Request JSON
Array of Objects:
- partitions -- A list of partitions to find the last committed offsets for
- partitions[i].topic (string) -- Name of the topic
- partitions[i].partition (int) -- Partition ID
Response JSON Array of Objects:
- offsets -- A list of committed offsets
- offsets[i].topic (string) -- Name of the topic for which an offset was committed
- offsets[i].partition (int) -- Partition ID for which an offset was committed
- offsets[i].offset (int) -- Committed offset
- offsets[i].metadata (string) -- Metadata for the committed offset
Status Codes:
- 404 Not Found --
- Error code 40402 -- Partition not found
- Error code 40403 -- Consumer instance not found
Example Request:
GET /consumers/testgroup/instances/my_consumer/offsets HTTP/1.1
Host: proxy-instance.kafkaproxy.example.com
Accept: application/vnd.kafka.v2+json, application/vnd.kafka+json, application/json
{
"partitions": [
{
"topic": "test",
"partition": 0
},
{
"topic": "test",
"partition": 1
}
]
}
Example Response:
HTTP/1.1 200 OK
Content-Type: application/vnd.kafka.v2+json
{"offsets":
[
{
"topic": "test",
"partition": 0,
"offset": 21,
"metadata":""
},
{
"topic": "test",
"partition": 1,
"offset": 31,
"metadata":""
}
]
}

- 36,235
- 20
- 134
- 156
-
1It will give me last committed offset by consumer but i want last offset of partition for the given topic so I can calculate the **lag**. – Sagar Shinde Jul 12 '19 at 07:52
Looks like there is an early access feature for this: https://docs.confluent.io/platform/current/kafka-rest/api.html#get--clusters-cluster_id-consumer-groups-consumer_group_id-lags

- 6,194
- 1
- 23
- 24
-
Lag is calculated by log end offset (LEO) minus current offset. With the generally available v2 api you could use the following endpoints for this calculation: https://docs.confluent.io/platform/current/kafka-rest/api.html#get--clusters-cluster_id-consumer-groups-consumer_group_id-lags and https://docs.confluent.io/platform/current/kafka-rest/api.html#get--clusters-cluster_id-consumer-groups-consumer_group_id-lags – aidanmelen Feb 04 '23 at 15:33