apache/hadoop · error · MetricsException

Error creating Producer, {}

Error message

Error creating Producer, {}

What it means

During init(), KafkaSink constructs a KafkaProducer with the configured properties (bootstrap.servers from broker_list, byte-array serializers). Any exception from the constructor — unreachable/invalid broker list, missing or incompatible kafka-clients classes, bad producer config — is rethrown as MetricsException('Error creating Producer, <brokerList>'). This is a startup-time failure: the sink cannot function without a producer.

Source

Thrown at hadoop-tools/hadoop-kafka/src/main/java/org/apache/hadoop/metrics2/sink/KafkaSink.java:120

    props.put("value.serializer",
        "org.apache.kafka.common.serialization.ByteArraySerializer");
    props.put("request.required.acks", "0");

    // Set the hostname once and use it in every message.
    hostname = "null";
    try {
      hostname = InetAddress.getLocalHost().getHostName();
    } catch (Exception e) {
      LOG.warn("Error getting Hostname, going to continue");
    }

    System.setProperty("org.apache.kafka.automatic.config.providers", "none");

    try {
      // Create the producer object.
      producer = new KafkaProducer<Integer, byte[]>(props);
    } catch (Exception e) {
      throw new MetricsException("Error creating Producer, " + brokerList, e);
    }
  }

  @Override
  public void putMetrics(MetricsRecord record) {

    if (producer == null) {
      throw new MetricsException("Producer in KafkaSink is null!");
    }

    // Create the json object.
    StringBuilder jsonLines = new StringBuilder();

    long timestamp = record.timestamp();
    Instant instant = Instant.ofEpochMilli(timestamp);
    LocalDateTime ldt = LocalDateTime.ofInstant(instant, zoneId);
    String date = ldt.format(dateFormat);
    String time = ldt.format(timeFormat);

View on GitHub (pinned to 2add963021)

Solutions

  1. Validate broker_list is a comma-separated host:port list (e.g. kafka1:9092,kafka2:9092) and reachable from the Hadoop node (nc -vz kafka1 9092)
  2. Ensure a compatible kafka-clients jar is on the classpath of every daemon loading the sink
  3. Inspect the cause chain (MetricsException wraps the original) — ConfigException points at the exact bad property
  4. Temporarily set *.sink.kafka.* off or point metrics to a file sink until Kafka connectivity is fixed

Example fix

# before
resourcemanager.sink.kafka.broker_list=kafka1:9092;

# after
resourcemanager.sink.kafka.broker_list=kafka1:9092,kafka2:9092
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight broker reachability before enabling the sink
for (String hp : brokerList.split(",")) {
  String[] parts = hp.split(":");
  try (Socket s = new Socket()) {
    s.connect(new InetSocketAddress(parts[0], Integer.parseInt(parts[1])), 2000);
  }
}

Try / catch

try {
  sink.init(conf);
} catch (MetricsException e) {
  // cause chain holds the KafkaProducer failure: fix classpath or broker_list
  LOG.error("Kafka sink init failed", e.getCause());
}

Prevention

When it happens

Trigger: broker_list empty, malformed (e.g. 'kafka1:9092;' instead of comma-separated), or pointing at hosts that fail DNS resolution (KafkaProducer constructor can fail on bad bootstrap config); kafka-clients.jar missing from the classpath or a version conflicting with the one hadoop-kafka was built against; ConfigException from invalid producer properties.

Common situations: Deploying the metrics sink without adding kafka-clients.jar to the classpath; broker hostnames not resolvable from the Hadoop node; firewall/proxy setups; mixing Kafka client versions (e.g. old producer configs like request.required.acks against newer clients); typo in broker_list format.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/ec69f2e99bea2b1a. Report an issue: GitHub.