apache/hadoop · error · MetricsException

Unsupported add(value) for metric {}

Error message

Unsupported add(value) for metric {}

What it means

MetricsRegistry.add(name, value) is the sampling API for stat metrics: if the name is unknown it lazily creates a MutableRate, but if the name already maps to a metric that is not a MutableStat (MutableGaugeInt/Long, MutableCounterLong, MutableQuantiles) it throws MetricsException('Unsupported add(value) for metric <name>').

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MetricsRegistry.java:366

  synchronized void add(String name, MutableMetric metric) {
    checkMetricName(name);
    metricsMap.put(name, metric);
  }

  /**
   * Add sample to a stat metric by name.
   * @param name  of the metric
   * @param value of the snapshot to add
   */
  public synchronized void add(String name, long value) {
    MutableMetric m = metricsMap.get(name);

    if (m != null) {
      if (m instanceof MutableStat) {
        ((MutableStat) m).add(value);
      }
      else {
        throw new MetricsException("Unsupported add(value) for metric "+ name);
      }
    }
    else {
      metricsMap.put(name, newRate(name)); // default is a rate metric
      add(name, value);
    }
  }

  /**
   * Set the metrics context tag
   * @param name of the context
   * @return the registry itself as a convenience
   */
  public MetricsRegistry setContext(String name) {
    return tag(MsInfo.Context, name, true);
  }

  /**

View on GitHub (pinned to 2add963021)

Solutions

  1. Hold the MutableStat/MutableRate object and call its add(value) directly
  2. For gauges/counters use their own operations (set, incr) instead of registry.add
  3. Rename the sampled stat so it does not collide with the gauge/counter name

Example fix

// before
registry.newGaugeInt("Latency", "Latency", 0);
registry.add("Latency", 25);  // throws

// after
MutableRate latency = registry.newRate("Latency", "Latency");
latency.add(25);
Defensive patterns

Strategy: validation

Validate before calling

Map<String, Class<?>> registered = new ConcurrentHashMap<>();
// record kinds: registered.put("Latency", MutableRate.class);
Class<?> kind = registered.get("Latency");
if (kind == null || MutableStat.class.isAssignableFrom(kind)) {
  registry.add("Latency", value);
} else {
  // gauge/counter under that name: use its own API instead
}

Prevention

When it happens

Trigger: Calling registry.add("Foo", 42) when "Foo" was registered via newGauge/newCounter/newQuantiles — i.e., pushing samples into a non-stat metric.

Common situations: A shared helper that does add(name, elapsed) for arbitrary metrics; reusing a name that another declaration already claimed as a gauge or counter.

Related errors


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