apache/seatunnel · error · IllegalArgumentException

Unsupported metrics format

Error message

Unsupported metrics format

What it means

MetricsServlet.doGet selects the Prometheus text format based on which registered path the request hit (/metrics -> 004 format, /open-metrics -> OpenMetrics 1.0.0). If the servlet path matches neither suffix it throws IllegalArgumentException; this is marked 'should not happen' because the servlet is only mapped for those two URLs.

Solutions

  1. Scrape only the registered paths /metrics or /open-metrics
  2. Fix the servlet registration/mapping so it matches the RestConstant URL suffixes
  3. If a new path is added intentionally, add a corresponding content-type branch in doGet
  4. Check that reverse proxies pass the full original path through

Example fix

// before (custom registration without suffix match)
context.addServlet(new ServletHolder(metricsServlet), "/prometheus");
// after
context.addServlet(new ServletHolder(metricsServlet), "/metrics");
context.addServlet(new ServletHolder(metricsServlet), "/open-metrics");
Defensive patterns

Strategy: validation

Validate before calling

if (!url.endsWith("/metrics") && !url.endsWith("/open-metrics")) throw new IllegalArgumentException("scrape path must be /metrics or /open-metrics");

Type guard

String contentTypeFor(String path) { return path.endsWith("/open-metrics") ? TextFormat.CONTENT_TYPE_OPENMETRICS_100 : path.endsWith("/metrics") ? TextFormat.CONTENT_TYPE_004 : null; }

Try / catch

try { text = scrapeMetrics(path); } catch (IllegalArgumentException e) { fixScrapeConfig(); }

Prevention

When it happens

Trigger: Request reaching MetricsServlet under a path that does not end with the configured REST_URL_METRICS or REST_URL_OPEN_METRICS suffixes — e.g. a custom servlet mapping change, path suffix stripped by a proxy, or a modified RestConstant.

Common situations: Operators remount the servlet on a new path without updating RestConstant; aggressive URL normalization strips trailing segments; misconfigured metrics scrape paths in Prometheus/Grafana agent configs.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/a32ad1e4ed9dedf3. Report an issue: GitHub.

Appendix: source

Thrown at seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/servlet/MetricsServlet.java:54

    public MetricsServlet(NodeEngineImpl nodeEngine) {
        super(nodeEngine);
        nodeExtension = (NodeExtension) nodeEngine.getNode().getNodeExtension();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        String servletPath = req.getServletPath();
        String contentType;
        if (servletPath.endsWith(RestConstant.REST_URL_METRICS)) {
            contentType = TextFormat.CONTENT_TYPE_004;
        } else if (servletPath.endsWith(RestConstant.REST_URL_OPEN_METRICS)) {
            contentType = TextFormat.CONTENT_TYPE_OPENMETRICS_100;
        } else {
            // should not happen, because the servlet is only registered for /metrics and
            // /open-metrics
            throw new IllegalArgumentException("Unsupported metrics format");
        }
        try (StringWriter stringWriter = new StringWriter()) {
            TextFormat.writeFormat(
                    contentType, stringWriter, nodeExtension.getMetricFamilySamples());
            write(resp, stringWriter.toString());
        }
    }
}

View on GitHub (pinned to cf67b549a7)