簡體   English   中英

當普羅米修斯端點正在調用時,MockMvc 收到 404

[英]MockMvc receive 404 when prometheus endpoint is calling

我想使用MockMvc class 測試 Prometheus 指標端點。

一切正常,但昨天我將我的項目遷移到Java 15SpringBoot 2.4.3SpringCloud 2020.0.1 現在,只有普羅米修斯測試不起作用,我收到404而不是預期的200 我對build.gradle eq: runtime("io.micrometer:micrometer-registry-prometheus")有所有必要的依賴。 application-test.yml我有一個禁用安全的配置,合同測試協議代理端點等。

我的測試:

@ExtendWith({SpringExtension.class, PostgresSpringDataSourceExtension.class})
@ActiveProfiles({"test"})
@SpringBootTest
@AutoConfigureMockMvc
public class PrometheusEndpointTest {

 @Autowired private MockMvc mockMvc;

 @Test
 public void metricsThroughPrometheusEndpoint() throws Exception {
  MvcResult result = 
  this.mockMvc.perform(get("/metrics")).andExpect(status().isOk()).andReturn();
 }
}

部分application.yaml 。yaml配置:

management:
  endpoint:
    prometheus:
      enabled: true
  endpoints:
    enabled-by-default: false
    web:
      exposure:
        include: 'prometheus'
      base-path: '/'
      path-mapping:
        prometheus: 'metrics'

解決方案:我們需要將屬性添加到測試注釋或application-test.yml

@ExtendWith(SpringExtension.class)
@SpringBootTest(
  webEnvironment = RANDOM_PORT,
  properties = "management.metrics.export.prometheus.enabled")
@ActiveProfiles({"test"})
@AutoConfigureMockMvc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM