You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Quarkus中禁用URL编码求助:Prometheus查询返回404

问题解决:Prometheus查询404错误修复

你的404错误核心原因是RestClient的路径配置重复,和URL自动编码无关——URL编码是HTTP协议的正常行为,Prometheus服务器完全能正确解码转义后的字符。

问题分析

你的MetricClient接口上已经标注了@Path("/api/v1/query"),但方法上又额外加了@Path("query"),这会导致最终请求的路径变成/api/v1/query/query,而Prometheus的正确查询端点是/api/v1/query,因此返回404。

另外,你的@QueryParam注解缺少参数名指定,正确写法应该是@QueryParam("query"),否则参数名可能被错误解析。

修改后的代码

package com.example.client;

import com.example.client.response.PrometheusResponse;
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.jboss.resteasy.annotations.jaxrs.QueryParam;

import javax.inject.Singleton;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Singleton
@Path("/api/v1/query")
@RegisterRestClient(configKey = "prometheus-client")
@RegisterClientHeaders(RequestInternalServiceHeaderFactory.class)
@RegisterProvider(RequestInternalServiceFilter.class)
public interface MetricClient {
    @GET
    @Consumes("application/json")
    @Produces("application/json")
    PrometheusResponse getTpsSummary(@QueryParam("query") String query);
}

关于URL编码的说明

你看到的rate%28prometheus_http_requests_total%5B1m%5D%29是标准URL编码:

  • %28对应(
  • %5B对应[
  • %5D对应]
  • %29对应)
    Prometheus API完全支持这种编码格式,所以这不是导致404的原因。

内容的提问来源于stack exchange,提问作者hoangkm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 04:17:02