Skip to content

Commit

Permalink
show topic limits if they're there in kafka:topics (#149)
Browse files Browse the repository at this point in the history
if there are topic limits on the addon, show them in `heroku kafka:topics`
  • Loading branch information
tcrayford committed Feb 3, 2017
1 parent 3f88c9e commit acfd4bc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 11 additions & 1 deletion commands/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ function * listTopics (context, heroku) {
path: `/data/kafka/${VERSION}/clusters/${addon.id}/topics`
})
cli.styledHeader('Kafka Topics on ' + (topics.attachment_name || 'HEROKU_KAFKA'))

if (topics.topics.length !== 0 && topics.limits && topics.limits.max_topics) {
cli.log(`${topics.topics.length} / ${topics.limits.max_topics} topics`)
}

let filtered = topics.topics.filter((t) => t.name !== '__consumer_offsets')
let topicData = filtered.map((t) => {
return {
Expand All @@ -26,7 +31,12 @@ function * listTopics (context, heroku) {
cli.log()
if (topicData.length === 0) {
cli.log('No topics found on this Kafka cluster.')
cli.log('Use heroku kafka:topics:create to create a topic.')

if (topics.limits && topics.limits.max_topics) {
cli.log(`Use heroku kafka:topics:create to create a topic (limit ${topics.limits.max_topics}).`)
} else {
cli.log('Use heroku kafka:topics:create to create a topic.')
}
} else {
cli.table(topicData,
{
Expand Down
11 changes: 9 additions & 2 deletions test/commands/topics_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ describe('kafka:topics', () => {
it('indicates there are no topics', () => {
kafka.get(topicsUrl('00000000-0000-0000-0000-000000000000')).reply(200, {
attachment_name: 'HEROKU_KAFKA_BLUE_URL',
limits: {
max_topics: 10
},
topics: []
})

return cmd.run({app: 'myapp', args: {}})
.then(() => expect(cli.stdout).to.equal(`=== Kafka Topics on HEROKU_KAFKA_BLUE_URL
No topics found on this Kafka cluster.
Use heroku kafka:topics:create to create a topic.
Use heroku kafka:topics:create to create a topic (limit 10).
`))
.then(() => expect(cli.stderr).to.be.empty)
})
Expand Down Expand Up @@ -80,11 +83,15 @@ Use heroku kafka:topics:create to create a topic.
topics: [
{ name: 'topic-1', messages_in_per_second: 10.0, bytes_in_per_second: 0 },
{ name: 'topic-2', messages_in_per_second: 12.0, bytes_in_per_second: 3 }
]
],
limits: {
max_topics: 10
}
})

return cmd.run({app: 'myapp', args: {}})
.then(() => expect(cli.stdout).to.equal(`=== Kafka Topics on HEROKU_KAFKA_BLUE_URL
2 / 10 topics
Name Messages Traffic
─────── ──────── ───────────
Expand Down

0 comments on commit acfd4bc

Please sign in to comment.