apache/pulsar · error · RuntimeException

Unknown component type: %s

Error message

Unknown component type: %s

What it means

ContextImpl registers user metrics with a metrics-name prefix that depends on the component type (FUNCTION, SOURCE, SINK). The switch in the metrics initialization has cases for SOURCE and SINK only; any other component type reaching this code hits the default branch and throws a RuntimeException, because there is no metrics prefix defined for it.

Source

Thrown at pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/ContextImpl.java:209

                    }.getType());
        } else {
            secretsMap = new HashMap<>();
        }

        this.metricsLabels = metricsLabels;
        String prefix;
        switch (componentType) {
            case FUNCTION:
                prefix = FunctionStatsManager.PULSAR_FUNCTION_METRICS_PREFIX;
                break;
            case SINK:
                prefix = SinkStatsManager.PULSAR_SINK_METRICS_PREFIX;
                break;
            case SOURCE:
                prefix = SourceStatsManager.PULSAR_SOURCE_METRICS_PREFIX;
                break;
            default:
                throw new RuntimeException("Unknown component type: " + componentType);
        }
        this.userMetricsSummary = collectorRegistry.registerIfNotExist(
                prefix + ComponentStatsManager.USER_METRIC_PREFIX,
                Summary.build()
                        .name(prefix + ComponentStatsManager.USER_METRIC_PREFIX)
                        .help("User defined metric.")
                        .labelNames(userMetricsLabelNames)
                        .quantile(0.5, 0.01)
                        .quantile(0.9, 0.01)
                        .quantile(0.99, 0.01)
                        .quantile(0.999, 0.01)
                        .create());
        this.componentType = componentType;
        this.stateManager = stateManager;
        this.defaultStateStore = (DefaultStateStore) stateManager.getStore(
                config.getFunctionDetails().getTenant(),
                config.getFunctionDetails().getNamespace(),
                config.getFunctionDetails().getName()

View on GitHub (pinned to 820761864e)

Solutions

  1. Verify the instance config (instances.yml / function details) sets componentType correctly (FUNCTION for functions, SOURCE/SINK for connectors).
  2. If you hit this for a plain Function, it is a framework bug — check the Pulsar version and upgrade to a release where the FUNCTION case is handled.
  3. Inspect how the instance was launched (KubernetesRuntime/JavaInstanceMain args) to ensure the correct component type is passed.
Defensive patterns

Strategy: validation

Validate before calling

if (componentType != ComponentType.SOURCE && componentType != ComponentType.SINK) {
    throw new IllegalArgumentException("Metrics prefix only defined for SOURCE/SINK, got: " + componentType);
}

Try / catch

try { /* init context */ } catch (RuntimeException e) { if (e.getMessage().startsWith("Unknown component type")) { log.error("instance componentType misconfigured"); throw e; } }

Prevention

When it happens

Trigger: An instance is created with a ComponentType that is neither SOURCE nor SINK (i.e. FUNCTION) yet the user-metrics registration path runs — a framework bug/misconfiguration where FunctionStatsManager prefix handling is bypassed, or componentType enum is null/unexpected.

Common situations: Deploying a function where the instance config's componentType was mis-set (e.g. left unset/null) by a custom runner; running a Function instance through a code path intended only for connectors; version mismatches between broker and function instance packages.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/7d3a0a16b0558d1a. Report an issue: GitHub.