序
本文主要研究一下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部署的時候,先把指定服務(wù)設(shè)置為OUT_OF_SERVICE來故意關(guān)閉請求流量。

1_r6qGvK49cv_9A8b4OCAZZw.png
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;
}
}
操作
設(shè)置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
小結(jié)
eureka instance的overriddenstatus對于部署來說非常好用,比如red/black升級,將部分原服務(wù)先設(shè)置為OUT_OF_SERVICE,停止接收請求,即變?yōu)閎lack,之后新部署的服務(wù)啟動起來,即為red。如果新服務(wù)正常,就可以關(guān)閉舊服務(wù)了,假設(shè)新服務(wù)出現(xiàn)問題,則立馬刪除掉新服務(wù),將原有服務(wù)的overriddenstatus刪除掉,恢復(fù)UP,恢復(fù)接收流量。
doc
- 聊聊Eureka Server的REST API
- 聊聊eureka server的instance注冊及元數(shù)據(jù)變更接口
- 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.