序
本文主要研究一下eureka instance的overriddenstatus
overriddenstatus
eureka-client-1.8.8-sources.jar!/com/netflix/appinfo/InstanceInfo.java
/**
* Sets the status overridden by some other external process.This is
* mostly used in putting an instance out of service to block traffic to
* it.
*
* @param status the overridden {@link InstanceStatus} of the instance.
* @return @return the {@link InstanceInfo} builder.
*/
public Builder setOverriddenStatus(InstanceStatus status) {
result.overriddenstatus = status;
return this;
}
通过注释可以看到,这个overriddenstatus的意思就是用于外部的一些操作,在netflix里头就是用于red/black部署的时候,先把指定服务设置为OUT_OF_SERVICE来故意关闭请求流量。
InstanceStatus枚举定义如下:
public enum InstanceStatus {
UP, // Ready to receive traffic
DOWN, // Do not send traffic- healthcheck callback failed
STARTING, // Just about starting- initializations to be done - do not
// send traffic
OUT_OF_SERVICE, // Intentionally shutdown for traffic
UNKNOWN;
public static InstanceStatus toEnum(String s) {
if (s != null) {
try {
return InstanceStatus.valueOf(s.toUpperCase());
} catch (IllegalArgumentException e) {
// ignore and fall through to unknown
logger.debug("illegal argument supplied to InstanceStatus.valueOf: {}, defaulting to {}", s, UNKNOWN);
}
}
return UNKNOWN;
}
}
操作
设置OUT_OF_SERVICE
curl -i -X PUT http://localhost:8761/eureka/apps/client1/127.0.0.1:client1:8081/status?value=OUT_OF_SERVICE
HTTP/1.1 200
Content-Type: application/xml
Content-Length: 0
Date: Wed, 16 May 2018 06:52:29 GMT
删除OUT_OF_SERVICE
curl -i -X DELETE http://localhost:8761/eureka/apps/client1/127.0.0.1:client1:8081/status
HTTP/1.1 200
Content-Type: application/xml
Content-Length: 0
Date: Wed, 16 May 2018 06:54:30 GM
小结
eureka instance的overriddenstatus对于部署来说非常好用,比如red/black升级,将部分原服务先设置为OUT_OF_SERVICE,停止接收请求,即变为black,之后新部署的服务启动起来,即为red。如果新服务正常,就可以关闭旧服务了,假设新服务出现问题,则立马删除掉新服务,将原有服务的overriddenstatus删除掉,恢复UP,恢复接收流量。
doc
- 聊聊Eureka Server的REST API
- 聊聊eureka server的instance注册及元数据变更接口
- Deploying the Netflix API
- The Mystery of Eureka Health Monitoring
- The Mystery of Eureka self-preservation
- Unable to return status to UP after overridden status was set to OUT_OF_SERVICE #955
- Eureka 1.x - there is no mechanism provided to remove overridden status #389
- Provide an API to remove all overridden status #89
- Support DELETE operation for instance status override.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。