Skip to content

Commit

Permalink
Merge 748a3ad into 86cbf0a
Browse files Browse the repository at this point in the history
  • Loading branch information
mmp37 committed Jun 4, 2018
2 parents 86cbf0a + 748a3ad commit 261bb85
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
6 changes: 5 additions & 1 deletion commands/topics_tail.js
Expand Up @@ -60,7 +60,7 @@ function * tail (context, heroku) {
cli.log(context.args.TOPIC, partition, m.offset, 0, 'NULL')
return
}
let length = Math.min(buffer.length, MAX_LENGTH)
let length = Math.min(buffer.length, parseInt(context.flags['max-length']) || MAX_LENGTH)
let body = buffer.toString('utf8', 0, length)
cli.log(context.args.TOPIC, partition, m.offset, buffer.length, body)
})
Expand All @@ -81,13 +81,17 @@ let cmd = {
{ name: 'TOPIC' },
{ name: 'CLUSTER', optional: true }
],
flags: [
{ name: 'max-length', description: 'number of characters per message to output', hasValue: true }
],
help: `
Tails a topic in Kafka. Note: kafka:tail is not available in Heroku Private Spaces.
Examples:
$ heroku kafka:topics:tail page-visits
$ heroku kafka:topics:tail page-visits kafka-aerodynamic-32763
$ heroku kafka:topics:tail page-visits --max-length 200
`,
needsApp: true,
needsAuth: true,
Expand Down
31 changes: 28 additions & 3 deletions test/commands/topics_tail_test.js
Expand Up @@ -129,13 +129,38 @@ describe('kafka:topics:tail', () => {
tail.process.emit('SIGINT')
}

return cmd.run({app: 'myapp', args: { TOPIC: 'topic-1' }})
return cmd.run({app: 'myapp', args: { TOPIC: 'topic-1' }, flags: {}})
.then(() => {
expect(cli.stdout).to.equal('topic-1 42 1 5 hello\ntopic-1 42 2 5 world\ntopic-1 42 3 0 NULL\n')
expect(cli.stderr).to.be.empty
})
})

it('tails a topic and prints the results limited by max-length flag', () => {
api.get('/apps/myapp/config-vars').reply(200, config)
api.get('/apps/myapp/addon-attachments/kafka-1')
.reply(200, { name: 'KAFKA', config_vars: stockConfigVars, app: { name: 'sushi' } })

consumer.subscribe = (topic, callback) => {
callback([
{ offset: 1, message: { value: Buffer.from('hello, this is a slightly longer message that shows an output just a litte bit longer than 80') } },
{ offset: 2, message: { value: Buffer.from('Hodor. Hodor hodor... Hodor hodor hodor hodor. Hodor, hodor. Hodor. Hodor, hodor, hodor. Hodor hodor?! Hodor, hodor.') } },
{ offset: 3, message: { value: Buffer.from('world') } },
{ offset: 4, message: { value: null } }
], undefined, 42)
tail.process.emit('SIGINT')
}

return cmd.run({app: 'myapp', args: { TOPIC: 'topic-1' }, flags: { 'max-length': '100' }})
.then(() => {
expect(cli.stdout).to.equal('topic-1 42 1 93 hello, this is a slightly longer message that shows an output just a litte bit longer than 80\n' +
'topic-1 42 2 116 Hodor. Hodor hodor... Hodor hodor hodor hodor. Hodor, hodor. Hodor. Hodor, hodor, hodor. Hodor hodor\n' +
'topic-1 42 3 5 world\n' +
'topic-1 42 4 0 NULL\n')
expect(cli.stderr).to.be.empty
})
})

it('tails a topic with a prefix and prints the results', () => {
let configWithPrefix = Object.assign({
KAFKA_PREFIX: 'nile-1234.'
Expand All @@ -154,7 +179,7 @@ describe('kafka:topics:tail', () => {
tail.process.emit('SIGINT')
}

return cmd.run({app: 'myapp', args: { TOPIC: 'topic-1' }})
return cmd.run({app: 'myapp', args: { TOPIC: 'topic-1' }, flags: {}})
.then(() => {
expect(cli.stdout).to.equal('topic-1 42 1 5 hello\ntopic-1 42 2 5 world\ntopic-1 42 3 0 NULL\n')
expect(cli.stderr).to.be.empty
Expand All @@ -179,7 +204,7 @@ describe('kafka:topics:tail', () => {
tail.process.emit('SIGINT')
}

return cmd.run({app: 'myapp', args: { TOPIC: 'nile-1234.topic-1' }})
return cmd.run({app: 'myapp', args: { TOPIC: 'nile-1234.topic-1' }, flags: {}})
.then(() => {
expect(cli.stdout).to.equal('nile-1234.topic-1 42 1 5 hello\nnile-1234.topic-1 42 2 5 world\nnile-1234.topic-1 42 3 0 NULL\n')
expect(cli.stderr).to.be.empty
Expand Down

0 comments on commit 261bb85

Please sign in to comment.