Skip to content
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

Add validation to client id and group id #394

Closed
hyperlink opened this issue Jun 27, 2016 · 0 comments
Closed

Add validation to client id and group id #394

hyperlink opened this issue Jun 27, 2016 · 0 comments
Assignees
Milestone

Comments

@hyperlink
Copy link
Collaborator

It's possible cause errors thrown in kafka broker when defining client id with invalid characters. The invalid characters I have tested are ?:,".

Reproduce Step

Update the producer example to add a client-id that includes an invalid character such as a colon.

var kafka = require('..');
var Producer = kafka.Producer;
var KeyedMessage = kafka.KeyedMessage;
var Client = kafka.Client;
var client = new Client('localhost:2181', 'something:12345');
var argv = require('optimist').argv;
var topic = argv.topic || 'topic1';
var p = argv.p || 0;
var a = argv.a || 0;
var producer = new Producer(client, { requireAcks: 1 });

producer.on('ready', function () {
    var message = 'a message';
    var keyedMessage = new KeyedMessage('keyed', 'a keyed message');

    producer.send([
        { topic: topic, partition: p, messages: [message, keyedMessage], attributes: a }
    ], function (err, result) {
        console.log(err || result);
        client.close(true)
        process.exit();
    });
});

producer.on('error', function (err) {
    console.log('error', err)
});

In the kafka logs:

org.apache.kafka.common.KafkaException: Error creating mbean attribute for metricName :MetricName [name=throttle-time, group=Produce, description=Tracking average throttle-time per client, tags={client-id=something:12345}]
    at org.apache.kafka.common.metrics.JmxReporter.addAttribute(JmxReporter.java:113)
    at org.apache.kafka.common.metrics.JmxReporter.metricChange(JmxReporter.java:76)
    at org.apache.kafka.common.metrics.Metrics.registerMetric(Metrics.java:288)
    at org.apache.kafka.common.metrics.Sensor.add(Sensor.java:162)
    at kafka.server.ClientQuotaManager.getOrCreateQuotaSensors(ClientQuotaManager.scala:209)
    at kafka.server.ClientQuotaManager.recordAndMaybeThrottle(ClientQuotaManager.scala:111)
    at kafka.server.KafkaApis$$anonfun$handleProducerRequest$1.apply(KafkaApis.scala:370)
    at kafka.server.KafkaApis$$anonfun$handleProducerRequest$1.apply(KafkaApis.scala:370)
    at kafka.server.ReplicaManager.appendMessages(ReplicaManager.scala:348)
    at kafka.server.KafkaApis.handleProducerRequest(KafkaApis.scala:365)
    at kafka.server.KafkaApis.handle(KafkaApis.scala:68)
    at kafka.server.KafkaRequestHandler.run(KafkaRequestHandler.scala:60)
    at java.lang.Thread.run(Thread.java:745)
 Caused by: javax.management.MalformedObjectNameException: Invalid character ':' in value part of property
    at javax.management.ObjectName.construct(ObjectName.java:618)
    at javax.management.ObjectName.<init>(ObjectName.java:1382)
    at org.apache.kafka.common.metrics.JmxReporter$KafkaMbean.<init>(JmxReporter.java:169)
    at org.apache.kafka.common.metrics.JmxReporter.addAttribute(JmxReporter.java:108)
    ... 14 more

I found the code the kafka uses to validate the client id and group id. Our validation should match something like this:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant