apache/druid · error · IllegalStateException

Unknown scale metric

Error message

Unknown scale metric

What it means

LagStats.getMetric resolves a ScaleMetric enum (MIN/MAX/SUM/AVERAGE) to its corresponding lag value. If the switch falls through with no matching case, the code assumes an unknown enum value was supplied and throws IllegalStateException('Unknown scale metric'). This guards against future enum values added without updating this method.

Solutions

  1. Regenerate/recompile all code against the current Druid version so the switch covers every ScaleMetric constant
  2. Add a case (or default fallback) in LagStats.getMetric for the missing ScaleMetric value
  3. Log and inspect the offending metric value to identify where the stale enum comes from

Example fix

// before
return switch (metric) { case MIN -> getMinLag(); case MAX -> getMaxLag(); case SUM -> getTotalLag(); case AVERAGE -> getAvgLag(); };
// after
return switch (metric) { case MIN -> getMinLag(); case MAX -> getMaxLag(); case SUM -> getTotalLag(); case AVERAGE -> getAvgLag(); case NEW_METRIC -> getNewMetricValue(); };
Defensive patterns

Strategy: validation

Validate before calling

if (!EnumSet.of(ScaleMetric.MIN, ScaleMetric.MAX, ScaleMetric.SUM, ScaleMetric.AVERAGE).contains(metric)) { throw new IllegalArgumentException("Unsupported scale metric: " + metric); }

Try / catch

try { lag = lagStats.getMetric(metric); } catch (IllegalStateException e) { log.warn(e, "Unknown scale metric %s, defaulting to MAX", metric); lag = lagStats.getMaxLag(); }

Prevention

When it happens

Trigger: Calling LagStats.getMetric with a ScaleMetric value not covered by the switch (MIN, MAX, SUM, AVERAGE), typically a newly added enum constant or an arbitrary/untrusted value.

Common situations: A Druid version upgrade introduces a new ScaleMetric constant while custom autoscaler code compiled against the old LagStats switch is still deployed; or reflective/serialized deserialization of a stale ScaleMetric value.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/04750f186816041c. Report an issue: GitHub.

Appendix: source

Thrown at server/src/main/java/org/apache/druid/indexing/overlord/supervisor/autoscaler/LagStats.java:76

   * The preferred scaling metric that supervisor may specify to be used.
   * This could be overrided by the autscaler.
   */
  public AggregateFunction getAggregateForScaling()
  {
    return aggregateForScaling;
  }

  public long getMetric(AggregateFunction metric)
  {
    switch (metric) {
      case MAX:
        return getMaxLag();
      case SUM:
        return getTotalLag();
      case AVERAGE:
        return getAvgLag();
    }
    throw new IllegalStateException("Unknown scale metric");
  }
}

View on GitHub (pinned to 9b90983fd2)