Bump to v2.0.3: Make first substatus backwards compatible with HostGAPlugin (#25)

* Make first substatus backwards compatible with HostGA by dedicating first substatus for health store
This commit is contained in:
frank-pang-msft 2022-08-26 15:17:51 -07:00 коммит произвёл GitHub
Родитель 78cf11598b
Коммит 840303b90c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 118 добавлений и 54 удалений

Просмотреть файл

@ -31,7 +31,8 @@ teardown(){
diff="$(container_diff)"; echo "$diff"
[[ "$diff" = *"A /var/lib/waagent/Extension/status/0.status"* ]]
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "$status_file"; [[ "$status_file" = *'Application health found to be healthy'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
}
@test "handler command: enable twice, process exits cleanly" {
@ -49,7 +50,9 @@ teardown(){
diff="$(container_diff)"; echo "$diff"
[[ "$diff" = *"A /var/lib/waagent/Extension/status/0.status"* ]]
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "$status_file"; [[ "$status_file" = *'Application health found to be healthy'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState success Healthy
}
@test "handler command: enable - validates json schema" {
@ -72,7 +75,9 @@ teardown(){
echo "$output"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be initializing'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState transitioning Initializing
}
@test "handler command: enable - failed http probe" {
@ -98,7 +103,9 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be initializing'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState transitioning Initializing
}
@test "handler command: enable - failed https probe" {
@ -124,7 +131,9 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be initializing'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState transitioning Initializing
}
@test "handler command: enable - healthy tcp probe" {
@ -138,7 +147,9 @@ teardown(){
echo "$output"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be healthy'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState success Healthy
}
@test "handler command: enable - healthy http probe" {
@ -156,7 +167,9 @@ teardown(){
[[ "$output" == *'No longer honoring grace period - successful probes'* ]]
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be healthy'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState success Healthy
}
@test "handler command: enable - https unknown after 10 seconds" {
@ -187,7 +200,9 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be unknown'* ]]
verify_substatus_item "$status_file" HealthStore error "Health store will interpret application health as unhealthy"
verify_substatus_item "$status_file" ApplicationHealthState error Unknown
}
@test "handler command: enable - unknown http probe - no response body" {
@ -212,7 +227,9 @@ teardown(){
)
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be initializing'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState transitioning Initializing
}
@test "handler command: enable - unknown http probe - no response body - prefixing requestPath with a slash" {
@ -238,7 +255,9 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be initializing'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState transitioning Initializing
}
@test "handler command: enable - unknown https probe - no response body" {
@ -263,7 +282,9 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be initializing'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState transitioning Initializing
}
@test "handler command: enable - numofprobes with states = unk,unk" {
@ -291,7 +312,9 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be initializing'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState transitioning Initializing
}
@test "handler command: enable - numofprobes with states = h,h,unk,unk" {
@ -325,7 +348,9 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be unknown'* ]]
verify_substatus_item "$status_file" HealthStore error "Health store will interpret application health as unhealthy"
verify_substatus_item "$status_file" ApplicationHealthState error Unknown
}
@test "handler command: enable - numofprobes with states = h,h,unk,unk,h" {
@ -360,7 +385,9 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be unknown'* ]]
verify_substatus_item "$status_file" HealthStore error "Health store will interpret application health as unhealthy"
verify_substatus_item "$status_file" ApplicationHealthState error Unknown
}
@test "handler command: enable - numofprobes with states = h,h,unk,unk,h,h" {
@ -396,7 +423,9 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be healthy'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState success Healthy
}
@test "handler command: uninstall - deletes the data dir" {

Просмотреть файл

@ -44,7 +44,8 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be unknown'* ]]
verify_substatus_item "$status_file" HealthStore error "Health store will interpret application health as unhealthy"
verify_substatus_item "$status_file" ApplicationHealthState error Unknown
}
@test "handler command: enable - rich states - basic states = m,h,h,u,u,i,i" {
@ -82,7 +83,8 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be unknown'* ]]
verify_substatus_item "$status_file" HealthStore error "Health store will interpret application health as unhealthy"
verify_substatus_item "$status_file" ApplicationHealthState error Unknown
}
@test "handler command: enable - rich states - alternating states=i,h,h,i,h,u,h,i,h" {
@ -121,7 +123,8 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be unknown'* ]]
verify_substatus_item "$status_file" HealthStore error "Health store will interpret application health as unhealthy"
verify_substatus_item "$status_file" ApplicationHealthState error Unknown
}
@test "handler command: enable - rich states - endpoint timeout results in unknown" {
@ -155,6 +158,6 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be unknown'* ]]
verify_substatus_item "$status_file" HealthStore error "Health store will interpret application health as unhealthy"
verify_substatus_item "$status_file" ApplicationHealthState error Unknown
}

Просмотреть файл

@ -60,7 +60,8 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be initializing'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState transitioning Initializing
}
@test "handler command: enable - honor grace period - unresponsive http probe with numberOfProbes=1" {
@ -88,7 +89,8 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be initializing'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState transitioning Initializing
}
@test "handler command: enable - bypass grace period - consecutive valid health states" {
@ -127,7 +129,8 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be unknown'* ]]
verify_substatus_item "$status_file" HealthStore error "Health store will interpret application health as unhealthy"
verify_substatus_item "$status_file" ApplicationHealthState error Unknown
}
@test "handler command: enable - bypass grace period - state change behavior retained" {
@ -169,7 +172,8 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be unknown'* ]]
verify_substatus_item "$status_file" HealthStore error "Health store will interpret application health as unhealthy"
verify_substatus_item "$status_file" ApplicationHealthState error Unknown
}
@test "handler command: enable - bypass grace period - larger numberOfProbes, consecutive rich states" {
@ -211,7 +215,8 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be unknown'* ]]
verify_substatus_item "$status_file" HealthStore error "Health store will interpret application health as unhealthy"
verify_substatus_item "$status_file" ApplicationHealthState error Unknown
}
@test "handler command: enable - bypass / grace period expires - fail to bypass and expiration results in unknown" {
@ -249,7 +254,8 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be unknown'* ]]
verify_substatus_item "$status_file" HealthStore error "Health store will interpret application health as unhealthy"
verify_substatus_item "$status_file" ApplicationHealthState error Unknown
}
@test "handler command: enable - grace period expires - additional alternating health states" {
@ -292,5 +298,6 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be healthy'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState success Healthy
}

Просмотреть файл

@ -38,7 +38,8 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be healthy'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState success Healthy
echo "status_file=$status_file"; [[ "$status_file" != *'CustomMetrics'* ]]
}
@ -71,7 +72,8 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be unhealthy'* ]]
verify_substatus_item "$status_file" HealthStore error "Health store will interpret application health as unhealthy"
verify_substatus_item "$status_file" ApplicationHealthState success Unhealthy
[[ "$status_file" != *'CustomMetrics'* ]]
}
@ -102,7 +104,8 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be healthy'* ]]
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState success Healthy
[[ "$status_file" != *'CustomMetrics'* ]]
}
@ -133,10 +136,9 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be healthy'* ]]
echo "$status_file" | egrep -z '"name": "ApplicationHealthState",\s+"status": "success",\s+"formattedMessage": {\s+"lang": "en",\s+"message": "Healthy"'
echo "$status_file" | egrep -z '"name": "CustomMetrics",\s+"status": "error",\s+"formattedMessage": {\s+"lang": "en",\s+"message": "\{\}"'
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState success Healthy
verify_substatus_item "$status_file" CustomMetrics error '\{\}'
}
@test "handler command: enable - custom metrics - sending invalid formatted custom metrics appears in status file with error status" {
@ -166,10 +168,9 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be healthy'* ]]
echo "$status_file" | egrep -z '"name": "ApplicationHealthState",\s+"status": "success",\s+"formattedMessage": {\s+"lang": "en",\s+"message": "Healthy"'
echo "$status_file" | egrep -z '"name": "CustomMetrics",\s+"status": "error",\s+"formattedMessage": {\s+"lang": "en",\s+"message": "\[ \\"hello\\", \\"world\\" ]"'
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState success Healthy
verify_substatus_item "$status_file" CustomMetrics error '\[ \\"hello\\", \\"world\\" ]'
}
@test "handler command: enable - custom metrics - sending valid custom metrics is seen in status file" {
@ -199,9 +200,9 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be healthy'* ]]
echo "$status_file" | egrep -z '"name": "CustomMetrics",\s+"status": "success",\s+"formattedMessage": {\s+"lang": "en",\s+"message": "{\\"rollingUpgradePolicy\\": { \\"phase\\": 2, \\"doNotUpgrade\\": true, \\"dummy\\": \\"yes\\" } }"'
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState success Healthy
verify_substatus_item "$status_file" CustomMetrics success '{\\"rollingUpgradePolicy\\": { \\"phase\\": 2, \\"doNotUpgrade\\": true, \\"dummy\\": \\"yes\\" } }'
}
@test "handler command: enable - custom metrics - sending valid custom metrics is seen in status file even if health is unknown" {
@ -230,7 +231,7 @@ teardown(){
verify_states "$enableLog" "${expectedStateLogs[@]}"
status_file="$(container_read_file /var/lib/waagent/Extension/status/0.status)"
echo "status_file=$status_file"; [[ "$status_file" = *'Application health found to be initializing'* ]]
echo "$status_file" | egrep -z '"name": "CustomMetrics",\s+"status": "success",\s+"formattedMessage": {\s+"lang": "en",\s+"message": "{\\"rollingUpgradePolicy\\": { \\"phase\\": 2, \\"doNotUpgrade\\": true, \\"dummy\\": \\"yes\\" } }"'
verify_substatus_item "$status_file" HealthStore success "Health store will interpret application health as healthy"
verify_substatus_item "$status_file" ApplicationHealthState transitioning Initializing
verify_substatus_item "$status_file" CustomMetrics success '{\\"rollingUpgradePolicy\\": { \\"phase\\": 2, \\"doNotUpgrade\\": true, \\"dummy\\": \\"yes\\" } }'
}

Просмотреть файл

@ -165,4 +165,15 @@ verify_states() {
index=$index+1
done
done <<< "$1"
}
verify_substatus_item() {
# $1 status_file contents
# $2 substatus.name
# $3 substatus.status
# $4 substatus.formattedMessage.message
FMT='"name": "'%s'",\s+"status": "'%s'",\s+"formattedMessage": {\s+"lang": "en",\s+"message": "'%s'"'
printf -v SUBSTATUS "$FMT" "$2" "$3" "$4"
echo "Searching status file for: $SUBSTATUS"
echo "$1" | egrep -z "$SUBSTATUS"
}

Просмотреть файл

@ -164,7 +164,7 @@ func enable(ctx *log.Context, h vmextension.HandlerEnvironment, seqNum int) (str
}
substatuses := []SubstatusItem{
NewSubstatus(SubstatusKeyNameAppHealthStatus, committedState.GetStatusType(), committedState.GetSubstatusMessage()),
NewSubstatus(SubstatusKeyNameHealthStore, committedState.GetStatusTypeForHealthStore(), committedState.GetMessageForHealthStore()),
NewSubstatus(SubstatusKeyNameApplicationHealthState, committedState.GetStatusType(), string(committedState)),
}

Просмотреть файл

@ -1,7 +1,7 @@
package main
const (
SubstatusKeyNameAppHealthStatus = "AppHealthStatus"
SubstatusKeyNameHealthStore = "HealthStore"
SubstatusKeyNameApplicationHealthState = "ApplicationHealthState"
SubstatusKeyNameCustomMetrics = "CustomMetrics"

Просмотреть файл

@ -36,8 +36,21 @@ func (p HealthStatus) GetStatusType() StatusType {
}
}
func (p HealthStatus) GetSubstatusMessage() string {
return "Application health found to be " + strings.ToLower(string(p))
func (p HealthStatus) GetStatusTypeForHealthStore() StatusType {
switch p {
case Unhealthy, Unknown:
return StatusError
default:
return StatusSuccess
}
}
func (p HealthStatus) GetMessageForHealthStore() string {
if p.GetStatusTypeForHealthStore() == StatusError {
return "Health store will interpret application health as unhealthy"
} else {
return "Health store will interpret application health as healthy"
}
}
type HealthProbe interface {
@ -173,16 +186,16 @@ func (p *HttpHealthProbe) evaluate(ctx *log.Context) (ProbeResponse, error) {
probeResponse.ApplicationHealthState = Unknown
return probeResponse, err
}
if err := json.Unmarshal(bodyBytes, &probeResponse); err != nil {
probeResponse.ApplicationHealthState = Unknown
return probeResponse, err
}
}
if err := probeResponse.validateCustomMetrics(); err != nil {
ctx.Log("error", err)
}
if err := probeResponse.validateApplicationHealthState(); err != nil {
probeResponse.ApplicationHealthState = Unknown
return probeResponse, err

Просмотреть файл

@ -36,4 +36,4 @@ func (p ProbeResponse) validateCustomMetrics() error {
}
}
return nil
}
}

Просмотреть файл

@ -64,7 +64,7 @@ func NewStatus(t StatusType, operation, message string) StatusReport {
}
func NewSubstatus(name string, t StatusType, message string) SubstatusItem {
return SubstatusItem {
return SubstatusItem{
Name: name,
Status: t,
FormattedMessage: FormattedMessage{

Просмотреть файл

@ -2,7 +2,7 @@
<ExtensionImage xmlns="http://schemas.microsoft.com/windowsazure">
<ProviderNameSpace>Microsoft.ManagedServices</ProviderNameSpace>
<Type>ApplicationHealthLinux</Type>
<Version>2.0.2</Version>
<Version>2.0.3</Version>
<Label>Microsoft Azure Application Health Extension for Linux Virtual Machines</Label>
<HostingResources>VmRole</HostingResources>
<MediaLink></MediaLink>