Skip to content

Commit

Permalink
Make the kafka topic prefix more prominent
Browse files Browse the repository at this point in the history
Add to help in topics:info and topics list, and add link to
topics:create output as well.
  • Loading branch information
Maciek Sakrejda committed Oct 10, 2017
1 parent dee2048 commit 44ab3d9
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
6 changes: 6 additions & 0 deletions commands/topics.js
Expand Up @@ -19,6 +19,9 @@ function * listTopics (context, heroku) {
if (topics.topics.length !== 0 && topics.limits && topics.limits.max_topics) {
cli.log(`${topics.topics.length} / ${topics.limits.max_topics} topics`)
}
if (topics.prefix) {
cli.log(`prefix: ${topics.prefix}`)
}

let filtered = topics.topics.filter((t) => t.name !== '__consumer_offsets')
let topicData = filtered.map((t) => {
Expand Down Expand Up @@ -58,6 +61,9 @@ let cmd = {
help: `
Lists available Kafka topics.
Note that some plans use a topic prefix; to learn more,
visit https://devcenter.heroku.com/articles/multi-tenant-kafka-on-heroku#connecting-kafka-prefix
Examples:
$ heroku kafka:topics
Expand Down
4 changes: 4 additions & 0 deletions commands/topics_create.js
Expand Up @@ -52,6 +52,10 @@ function * createTopic (context, heroku) {
}))

cli.log(`Use \`heroku kafka:topics:info ${context.args.TOPIC}\` to monitor your topic.`)
if (addonInfo.topic_prefix) {
cli.log(`Your topic is using the prefix '${addonInfo.topic_prefix}'. Learn more in Dev Center:`)
cli.log(' https://devcenter.heroku.com/articles/multi-tenant-kafka-on-heroku#connecting-kafka-prefix')
}
})
}

Expand Down
12 changes: 11 additions & 1 deletion commands/topics_info.js
Expand Up @@ -41,6 +41,13 @@ function topicInfo (topic) {
}
]

if (topic.prefix) {
lines.unshift({
name: 'Topic Prefix',
values: [ topic.prefix ]
})
}

if (topic.compaction) {
lines.push({
name: 'Compaction',
Expand Down Expand Up @@ -85,7 +92,10 @@ let cmd = {
{ name: 'CLUSTER', optional: true }
],
help: `
Shows information about a topic in your Kafka cluster
Shows information about a topic in your Kafka cluster.
Note that some plans use a topic prefix; to learn more,
visit https://devcenter.heroku.com/articles/multi-tenant-kafka-on-heroku#connecting-kafka-prefix
Examples:
Expand Down
27 changes: 27 additions & 0 deletions test/commands/topics_create_test.js
Expand Up @@ -80,6 +80,33 @@ describe('kafka:topics:create', () => {
})
})

it('includes the topic prefix and link in output if one exists', () => {
const prefix = 'mill-4567.'
kafka.get(infoUrl('00000000-0000-0000-0000-000000000000'))
.reply(200, { topic_prefix: prefix })
kafka.post(createUrl('00000000-0000-0000-0000-000000000000'),
{
topic: {
name: 'topic-1',
retention_time_ms: 10,
replication_factor: '3',
partition_count: '7',
compaction: false
}
}).reply(200)

return cmd.run({app: 'myapp',
args: { TOPIC: 'topic-1' },
flags: { 'replication-factor': '3',
'retention-time': '10ms',
'partitions': '7' }}
)
.then(() => {
expect(cli.stderr).to.equal('Creating topic topic-1 with compaction disabled and retention time 10 milliseconds on kafka-1... done\n')
expect(cli.stdout).to.equal(`Use \`heroku kafka:topics:info topic-1\` to monitor your topic.\nYour topic is using the prefix '${prefix}'. Learn more in Dev Center:\n https://devcenter.heroku.com/articles/multi-tenant-kafka-on-heroku#connecting-kafka-prefix\n`)
})
})

it('defaults retention to the plan minimum if not specified even if retention specified', () => {
kafka.get(infoUrl('00000000-0000-0000-0000-000000000000'))
.reply(200, { shared_cluster: false, limits: { minimum_retention_ms: 66 } })
Expand Down
32 changes: 32 additions & 0 deletions test/commands/topics_info_test.js
Expand Up @@ -61,6 +61,38 @@ describe('kafka:topics:info', () => {
return cmd.run({app: 'myapp', args: { TOPIC: 'topic-1' }})
.then(() => expect(cli.stdout).to.equal(`=== kafka-1 :: topic-1
Producers: 0 messages/second (0 bytes/second) total
Consumers: 0 bytes/second total
Partitions: 3 partitions
Replication Factor: 3
Compaction: Compaction is disabled for topic-1
Retention: 24 hours
`))
.then(() => expect(cli.stderr).to.be.empty)
})

it('displays a topic prefix if one is specified', () => {
kafka.get(topicsUrl('00000000-0000-0000-0000-000000000000')).reply(200, {
attachment_name: 'HEROKU_KAFKA_BLUE_URL',
topics: [
{
name: 'topic-1',
prefix: 'wisła-12345.',
messages_in_per_second: 0,
bytes_in_per_second: 0,
bytes_out_per_second: 0,
replication_factor: 3,
partitions: 3,
compaction: false,
retention_time_ms: 86400000
}
]
})

return cmd.run({app: 'myapp', args: { TOPIC: 'topic-1' }})
.then(() => expect(cli.stdout).to.equal(`=== kafka-1 :: topic-1
Topic Prefix: wisła-12345.
Producers: 0 messages/second (0 bytes/second) total
Consumers: 0 bytes/second total
Partitions: 3 partitions
Expand Down

0 comments on commit 44ab3d9

Please sign in to comment.