春季启动+ gcloud +“ 502错误的网关”

时间:2019-12-11 22:34:17

标签: java spring-boot google-cloud-platform gcloud

我正在尝试在gcloud上部署此项目: https://github.com/ITger/PolishAPI_sample 本地工作正常,但是在gcloud上,我总是收到502错误。

mvn清洁程序包appengine:deploy命令运行没有问题。

在日志(gcloud应用程序日志尾部)中,仅Info和Debug消息没有错误。 一个星期以来,我一直在寻找解决方案,并尝试了许多在互联网上找到的建议,但我没有遵循google,dzone等教程。

感谢您的帮助

编辑(代表约翰·汉利): 广告1:我的代码有超过165个Java文件,那么如何显示它?

广告2:app.yaml:

runtime: java
env: flex
instance_class: F2
runtime_config:
  jdk: openjdk8
#env_variables:
#  SPRING_PROFILES_ACTIVE: "gcp"
handlers:
  - url: /.*
    script: this field is required, but ignored
readiness_check:
  check_interval_sec: 15
  timeout_sec: 14
  failure_threshold: 2
  success_threshold: 2
  app_start_timeout_sec: 1200

ad 3:正如我所说的,日志中只有没有错误弹簧信息和调试消息。

application.properties文件:

debug=true
spring.application.name=polish-api-psd2
springfox.documentation.swagger.v2.path=/api-docs
server.port=${port:8080}
spring.jackson.date-format=pl.itger.PolishAPI.RFC3339DateFormat
#Mongo Config
spring.data.mongodb.database=PolishAPI
spring.data.mongodb.uri=mongodb+srv://polishapi-user:SECRET CLUSTER DATA
spring.data.mongodb.auto-index-creation=true
log4j.category.org.springframework.data.mongodb=DEBUG
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n
logging.level.pl.itger=DEBUG
logging.level.root=WARN

App引擎防火墙规则:

Priority 
1000
Action on match
Allow
IP range 
0.0.0.0/0

当我在Google Cloud Shell控制台中运行“ **mvn clean spring-boot:run -P cloud-gcp**”时,该应用程序运行良好,在Web预览中,该应用程序在预定义的swagger ui页面中运行良好:

https://8080-dot-10127310-dot-devshell.appspot.com/

显示所有模型和api。 当我在浏览器中调用“ https://8080-dot-10127310-dot-devshell.appspot.com/api-docs”时,效果也很好。用curl调用该URL上的任何其他服务都会导致“禁止访问”。

但是,在mvn -DskipTests package appengine:deploy -P cloud-gcp无效之后,只有502 Bad Gateway

[INFO] GCLOUD: Setting traffic split for service [default]...
[INFO] GCLOUD: ..............................................................done.
[INFO] GCLOUD: Deployed service [default] to [https://polish-api-psd2.appspot.com]
[INFO] GCLOUD:
[INFO] GCLOUD: You can stream logs from the command line by running:
[INFO] GCLOUD:   $ gcloud app logs tail -s default
[INFO] GCLOUD:
[INFO] GCLOUD: To view your application in the web browser run:
[INFO] GCLOUD:   $ gcloud app browse
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  09:15 min
[INFO] Finished at: 2019-12-12T15:49:39+01:00
[INFO] ------------------------------------------------------------------------
p_zerynger@cloudshell:~/PolishAPI_sample/server (polish-api-psd2)$

完整日志(非常简短,与“ mvn spring-boot:run -P cloud-gcp”之后的日志不同,我不知道为什么):

ar!/, jar:file:/app.jar!/BOOT-INF/lib/spring-data-jpa-2.1.10.RELEASE.jar!/, jar:file:/app.jar!/BOOT-INF/lib/spring-orm-5.2.2.RELEASE.jar!/, jar:file:/app.jar!/BOOT-INF/lib/spring-jdbc-5.2.2.RELEASE.jar!/, jar:file:/app.jar!/BOOT-INF/lib/aspectjrt-1.9.5.jar!/, jar:file:/app.jar!/BOOT-INF/lib/lombok-1.18.10.jar!/, jar:file:/app.jar!/BOOT-INF/lib/core-1.5.3.jar!/, jar:file:/app.jar!/BOOT-INF/lib/proxytoys-1.0.jar!/, jar:file:/app.jar!/BOOT-INF/lib/gson-2.8.6.jar!/, jar:file:/app.jar!/BOOT-INF/lib/annotations-17.0.0.jar!/, jar:file:/app.jar!/BOOT-INF/lib/jaxb-api-2.3.1.jar!/, jar:file:/app.jar!/BOOT-INF/lib/javax.activation-api-1.2.0.jar!/]
2019-12-12 14:48:53 default[1]
2019-12-12 14:48:53 default[1]    .   ____          _            __ _ _
2019-12-12 14:48:53 default[1]   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
2019-12-12 14:48:53 default[1]  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2019-12-12 14:48:53 default[1]   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
2019-12-12 14:48:53 default[1]    '  |____| .__|_| |_|_| |_\__, | / / / /
2019-12-12 14:48:53 default[1]   =========|_|==============|___/=/_/_/_/
2019-12-12 14:48:53 default[1]   :: Spring Boot ::        (v2.2.2.RELEASE)
2019-12-12 14:48:53 default[1]
2019-12-12 14:48:54 default[1]  2019-12-12 14:48:54.093  INFO 1 --- [           main] p.i.P.PolishAPI_2_1_2_SpringBoot         : Starting PolishAPI_2_1_2_SpringBoot v1.0.1 on e1b35acb6032 with PID 1 (/app.jar started by root in /)
2019-12-12 14:48:54 default[1]  2019-12-12 14:48:54.096 DEBUG 1 --- [           main] p.i.P.PolishAPI_2_1_2_SpringBoot         : Running with Spring Boot v2.2.2.RELEASE, Spring v5.2.2.RELEASE
2019-12-12 14:48:54 default[1]  2019-12-12 14:48:54.098  INFO 1 --- [           main] p.i.P.PolishAPI_2_1_2_SpringBoot         : No active profile set, falling back to default profiles: default
2019-12-12 14:48:54 default[1]  2019-12-12 14:48:54.102 DEBUG 1 --- [           main] o.s.boot.SpringApplication               : Loading source class pl.itger.PolishAPI.PolishAPI_2_1_2_SpringBoot
2019-12-12 14:48:54 default[1]  2019-12-12 14:48:54.341 DEBUG 1 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Loaded config file 'jar:file:/app.jar!/BOOT-INF/classes!/application.properties' (classpath:/application.properties)
2019-12-12 14:48:54 default[1]  2019-12-12 14:48:54.345 DEBUG 1 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6c3708b3
2019-12-12 14:52:42 default[1]  I1212 14:51:56.693214    26 callbacks_monitor.cc:66] Cloud Debugger call "JVMTI:ClassPrepare" completed after 25847 ms

+++++++++ 在云http负载均衡器日志中,我发现了这一点:

jsonPayload: {
  @type: "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry"   
  statusDetails: "failed_to_connect_to_backend"   
 }
  

这太疯狂了……现在超时:

[INFO] GCLOUD: ERROR: (gcloud.app.deploy) Error Response: [4] App Engine Flexible timed out while configuring resources, internal operation projects/polish-api-psd2/regions/europe-west1/operations/3343fc51-2991-4da1-ba45-128bd897d92f

2 个答案:

答案 0 :(得分:1)

每个部署都分配有一个版本号。 验证版本号是否出现在“应用引擎”下的“版本”部分中 您的GCP项目。如果确实出现版本号,则将在StackDriver中提供日志,详细记录发生的任何可能的部署错误。

如果没有显示版本号,则重新部署项目,这一次启用详细程度标志以生成部署日志。[1]

最后,尝试部署最低限度的“ Hello World”应用程序,看看问题是否与代码无关。

[1] https://cloud.google.com/sdk/gcloud/reference/#--verbosity

答案 1 :(得分:0)

添加

resources:
  memory_gb: 4

在您的Yaml文件中。