【问题标题】:Different actuator (management server) port changes HTTP response不同的执行器(管理服务器)端口更改 HTTP 响应
【发布时间】:2020-07-30 17:36:21
【问题描述】:

我在 Chaos Monkey For Spring Boot 中遇到了当用户发布无效信息时的错误响应(例如 {"level": -2}update 通过 REST 到我们的执行器端点,在那里人们可以更新 CMSB 行为的选项(只有正面级别是允许的)。在第一张图片中,我将management.server.port 设置为8888,并将应用程序端口设置为8080。当向 CMSB REST API 发布新属性时,我收到以下响应(这不是我们的本来预期的):

如果我将管理端口留在与应用程序相同的端口,我会收到以下响应:

对于这两种情况,我们都希望得到相同的错误响应(第二种)。所以我们(在 CMSB)问我们这是否是 Spring Boot 的预期行为,如果不是,如果管理端口与应用程序端口不同,我们有什么选择可以绕过编写我们自己的错误响应处理程序。 请注意,这不是关于 Chaos Monkey 对于 Spring Boot 的预期行为,而是关于这是否是 Spring Boot 错误。在这两种情况下,我们都希望有详细的错误响应,以便用户知道出了什么问题。在后台,我们使用 @Validated 注释结合类似的东西来验证输入:

@Data
@NoArgsConstructor
@Validated
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AssaultPropertiesUpdate {
    @Nullable
    @Min(value = 1)
    @Max(value = 10000)
    private Integer level;

附带说明:在这两种情况下,日志中的错误消息都是正确的。但只有在第二种情况下才会出现这个错误信息

WARN 4477 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument [0] in public org.springframework.http.ResponseEntity<?> de.codecentric.spring.boot.chaos.monkey.endpoints.ChaosMonkeyRestEndpoint.updateAssaultProperties(de.codecentric.spring.boot.chaos.monkey.endpoints.AssaultPropertiesUpdate): [Field error in object 'assaultPropertiesUpdate' on field 'level': rejected value [-2]; codes [Min.assaultPropertiesUpdate.level,Min.level,Min.java.lang.Integer,Min]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [assaultPropertiesUpdate.level,level]; arguments []; default message [level],1]; default message [must be greater than or equal to 1]] ]

用作响应负载。

最小示例项目:https://github.com/fletchgqc/mediator 使用mvn spring-boot:run 启动项目。然后使用有效负载对http://localhost:8080/actuator/chaosmonkey/assaults 进行POST:{"level": -2}。应显示正确的错误响应(如图 2 所示)。

然后停止项目,到https://github.com/fletchgqc/mediator/blob/master/src/main/resources/application.properties 添加management.server.port=8888 并再次启动应用程序。使用与以前相同的有效负载对http://localhost:8888/actuator/chaosmonkey/assaults 执行 POST。应该会出现错误的错误消息(如图 1 所示)。

【问题讨论】:

    标签: spring-boot spring-boot-chaos-monkey


    【解决方案1】:

    看来 spring 团队在这里修复了它:https://github.com/spring-projects/spring-boot/issues/21036

    【讨论】:

      猜你喜欢
      • 2019-04-17
      • 2020-05-13
      • 1970-01-01
      • 2020-05-10
      • 1970-01-01
      • 1970-01-01
      • 2015-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多