-
-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New admin method for fetching group offsets for multiple topics #992
Changes from 1 commit
a72d09f
a2216eb
e940948
231ebee
5f42dbe
7a575d0
cef4830
fa0ea86
d6b4cf3
8943aa5
b7b06e0
5f5ac39
bb9567b
23e17e2
ca704d1
5786968
2f190a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,6 +368,9 @@ module.exports = ({ | |
} | ||
|
||
/** | ||
* @deprecated - This method was replaced by `fetchConsumerGroupOffsets`. This implementation | ||
* is limited to fetching offsets to a single topic only, and lacks a default option of retrieving | ||
* offsets for all topics for a consumer group. | ||
* @param {string} groupId | ||
* @param {string} topic | ||
* @param {boolean} [resolveOffsets=false] | ||
|
@@ -428,38 +431,43 @@ module.exports = ({ | |
|
||
/** | ||
* @param {string} groupId | ||
* @param {string[]]} topics | ||
* @param {string[]} topics | ||
* @param {boolean} [resolveOffsets=false] | ||
* @return {Promise} | ||
*/ | ||
const fetchConsumerGroupOffsets = async ({ groupId, topics, resolveOffsets = false }) => { | ||
const fetchConsumerGroupOffsets = async ({ groupId, topics = [], resolveOffsets = false }) => { | ||
if (!groupId) { | ||
throw new KafkaJSNonRetriableError(`Invalid groupId ${groupId}`) | ||
} | ||
|
||
if (!Array.isArray(topics)) { | ||
throw new KafkaJSNonRetriableError(`Expected topics array, got ${topics}`) | ||
} | ||
|
||
const coordinator = await cluster.findGroupCoordinator({ groupId }) | ||
|
||
let consumerOffsets | ||
if (topics.length) { | ||
const topicsToFetch = Promise.all( | ||
const topicsToFetch = await Promise.all( | ||
Nevon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
topics.map(async topic => { | ||
const partitions = await findTopicPartitions(cluster, topic) | ||
const partitionsToFetch = partitions.map(partition => ({ partition })) | ||
return { topic, partitions: partitionsToFetch } | ||
}) | ||
) | ||
|
||
const { responses } = await coordinator.offsetFetch({ | ||
Nevon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
groupId, | ||
topicsToFetch, | ||
topics: topicsToFetch, | ||
}) | ||
consumerOffsets = responses | ||
} else { | ||
nirga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { responses } = await coordinator.offsetFetch({ groupId }) | ||
const { responses } = await coordinator.offsetFetch({ groupId }, []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's with the empty array here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It needs to be passed to |
||
consumerOffsets = responses | ||
} | ||
|
||
if (resolveOffsets) { | ||
consumerOffsets = Promise.all( | ||
consumerOffsets = await Promise.all( | ||
consumerOffsets.map(async ({ topic, partitions }) => { | ||
const indexedOffsets = indexByPartition(await fetchTopicOffsets(topic)) | ||
const recalculatedPartitions = partitions.map(({ offset, partition, ...props }) => { | ||
|
@@ -489,17 +497,15 @@ module.exports = ({ | |
) | ||
} | ||
|
||
return consumerOffsets | ||
.filter(response => !topics.length || response.topic in topics) | ||
.map(({ topic, partitions }) => { | ||
const completePartitions = partitions.map(({ partition, offset, metadata }) => ({ | ||
partition, | ||
offset, | ||
metadata: metadata || null, | ||
})) | ||
return consumerOffsets.map(({ topic, partitions }) => { | ||
const completePartitions = partitions.map(({ partition, offset, metadata }) => ({ | ||
partition, | ||
offset, | ||
metadata: metadata || null, | ||
Nevon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
})) | ||
|
||
return { topic, partitions: completePartitions } | ||
}) | ||
return { topic, partitions: completePartitions } | ||
}) | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the previous implementation if
topic
wasn't passed an exception was thrownbut here you're setting
topics
's default value to pass your exception throwing ([]
), so you're actually not validating that this param was sent hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mm yeah but I think it's kinda weird to force users to set topics=[] if they want to just fetch all of topics of the consumer instead of just calling it with
fetchConsumerGroupOffsets({groupId})
.