2

我想在 Docker 中运行 Java APM 代理在 docker 组件中,我收到以下错误消息:

2021-08-23 08:13:52,481 [elastic-apm-server-healthcheck] WARN  co.elastic.apm.agent.report.ApmServerHealthChecker - Elastic APM server https://i-o-optimized-deployment-912238.es.us-west1.gcp.cloud.es.io:9243/ is not available (Server returned status 401)
2021-08-23 08:13:52,779 [elastic-apm-remote-config-poller] ERROR co.elastic.apm.agent.configuration.ApmServerConfigurationSource - Unexpected status 401 while fetching configuration

Dockerfile 看起来像这样

FROM gradle as gradleimage
COPY ./app /home/gradle/source/app
COPY settings.gradle /home/gradle/source/settings.gradle
WORKDIR /home/gradle/source
RUN gradle assemble
EXPOSE 5000
FROM openjdk
COPY --from=gradleimage /home/gradle/source/app/build/libs/app.jar /app/
COPY ./apmplugin/elastic-apm-agent-1.25.0.jar /app/
WORKDIR /app
ENTRYPOINT ["java",  "-javaagent:elastic-apm-agent-1.25.0.jar", "-Delastic.apm.service_name=helloworld","-Delastic.apm.server_urls=https://i-o-optimized-deployment-912238.es.us-west1.gcp.cloud.es.io:9243", "-Delastic.apm.api_key= xxxxxxx" ,"-Delastic.apm.application_packages=org.steinko.helloworld",  "-jar", "app.jar"]

docker run 命令返回这个

steinko@Steins-MacBook-Pro ci-cd-template % docker run -t -p 5000:5000  steinko/helloworld 
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
2021-08-23 08:13:50,953 [main] INFO  co.elastic.apm.agent.util.JmxUtils - Found JVM-specific OperatingSystemMXBean interface: com.sun.management.OperatingSystemMXBean
2021-08-23 08:13:50,972 [main] INFO  co.elastic.apm.agent.configuration.StartupInfo - Starting Elastic APM 1.25.0 as helloworld on Java 16.0.2 Runtime version: 16.0.2+7-67 VM version: 16.0.2+7-67 (Oracle Corporation) Linux 5.10.25-linuxkit
2021-08-23 08:13:50,973 [main] INFO  co.elastic.apm.agent.configuration.StartupInfo - service_name: 'helloworld' (source: Java System Properties)
2021-08-23 08:13:50,973 [main] INFO  co.elastic.apm.agent.configuration.StartupInfo - api_key: 'XXXX' (source: Java System Properties)
2021-08-23 08:13:50,973 [main] INFO  co.elastic.apm.agent.configuration.StartupInfo - server_urls: 'https://i-o-optimized-deployment-912238.es.us-west1.gcp.cloud.es.io:9243' (source: Java System Properties)
2021-08-23 08:13:50,973 [main] INFO  co.elastic.apm.agent.configuration.StartupInfo - application_packages: 'org.steinko.helloworld' (source: Java System Properties)
2021-08-23 08:13:51,389 [main] INFO  co.elastic.apm.agent.impl.ElasticApmTracer - Tracer switched to RUNNING state

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.5)

2021-08-23 08:13:51.968  INFO 1 --- [           main] org.steinko.helloworld.App               : Starting App using Java 16.0.2 on 0f3c5bf51643 with PID 1 (/app/app.jar started by root in /app)
2021-08-23 08:13:51.973  INFO 1 --- [           main] org.steinko.helloworld.App               : No active profile set, falling back to default profiles: default
2021-08-23 08:13:52,481 [elastic-apm-server-healthcheck] WARN  co.elastic.apm.agent.report.ApmServerHealthChecker - Elastic APM server https://i-o-optimized-deployment-912238.es.us-west1.gcp.cloud.es.io:9243/ is not available (Server returned status 401)
2021-08-23 08:13:52,779 [elastic-apm-remote-config-poller] ERROR co.elastic.apm.agent.configuration.ApmServerConfigurationSource - Unexpected status 401 while fetching configuration
2021-08-23 08:13:52.970  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 5000 (http)
2021-08-23 08:13:52.982  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-08-23 08:13:52.982  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-08-23 08:13:53.019  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-08-23 08:13:53.019  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1016 ms
2021-08-23 08:13:53,048 [main] INFO  co.elastic.apm.agent.micrometer.MicrometerMetricsReporter - Registering Micrometer MeterRegistry: io.micrometer.core.instrument.simple.SimpleMeterRegistry@7593ea79
2021-08-23 08:13:53.451  INFO 1 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 14 endpoint(s) beneath base path '/actuator'
2021-08-23 08:13:53.524  INFO 1 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-08-23 08:13:53.688  INFO 1 --- [           main] .s.s.UserDetailsServiceAutoConfiguration : 

Using generated security password: c9f8d5ae-61d5-4410-b99c-bcecbf3593de

2021-08-23 08:13:53.776  INFO 1 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@6af310c7, org.springframework.security.web.context.SecurityContextPersistenceFilter@291a4791, org.springframework.security.web.header.HeaderWriterFilter@1d289d3f, org.springframework.security.web.csrf.CsrfFilter@34045582, org.springframework.security.web.authentication.logout.LogoutFilter@349c4d1c, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@46394f65, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@340cb97f, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@4a216eb4, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@4aed311e, org.springframework.security.web.session.SessionManagementFilter@3520958b, org.springframework.security.web.access.ExceptionTranslationFilter@44d7e24, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@75eaba95]
2021-08-23 08:13:53.824  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 5000 (http) with context path ''
2021-08-23 08:13:54.034  INFO 1 --- [           main] org.steinko.helloworld.App               : Started App in 2.376 seconds (JVM running for 3.354)
2021-08-23 08:14:32,106 [elastic-apm-server-reporter] INFO  co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 0 seconds (+/-10%)
2021-08-23 08:14:32,110 [elastic-apm-server-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Error sending data to APM server: cannot retry due to server authentication, in streaming mode, response code is 401
2021-08-23 08:14:32,111 [elastic-apm-server-reporter] WARN  co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - null

我必须做什么才能连接到 APM 服务器?

4

2 回答 2

0

可能是您尝试向api_key配置选项提供秘密令牌。这些不是一回事。尝试使用-Delastic.apm.secret_token=xxxxxxx而不是-Delastic.apm.api_key=xxxxxxx.

有关差异的更多详细信息,请参阅APM 服务器文档

于 2021-08-24T15:15:09.510 回答
0

同样抛出,看起来您server_urls指向的是 Elasticsearch URL 而不是 APM URL。

我希望 APM 服务器 URL 的格式类似于https://i-o-optimized-deployment-912238.apm.us-west1.gcp.cloud.es.io(基于您当前的 Elasticsearch URL https://i-o-optimized-deployment-912238.es.us-west1.gcp.cloud.es.io:9243)。

一个 HTTPs Elasticsearch 将出现 HTTP401错误,但没有身份验证,但您可以使用 APM URL 在设置中走得更远。

于 2021-09-05T02:23:08.497 回答