This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rollout: Include health report in service object (#51)
This adds annotation about the last health report. It uses the key rollout.cloud.run/lastHealthReport and assigns it a string with the last diagnosis (healthy, unhealthy) and the check results.
- Loading branch information
Getulio Valentin Sánchez
committed
Aug 7, 2020
1 parent
b780b66
commit 6f36920
Showing
7 changed files
with
156 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package health | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/GoogleCloudPlatform/cloud-run-release-operator/pkg/config" | ||
) | ||
|
||
// StringReport returns a human-readable report of the diagnosis. | ||
func StringReport(healthCriteria []config.Metric, diagnosis Diagnosis) string { | ||
report := fmt.Sprintf("status: %s\n", diagnosis.OverallResult.String()) | ||
report += "metrics:" | ||
for i, result := range diagnosis.CheckResults { | ||
criteria := healthCriteria[i] | ||
|
||
// Include percentile value for latency criteria. | ||
if criteria.Type == config.LatencyMetricsCheck { | ||
report += fmt.Sprintf("\n- %s[p%.0f]: %.2f (needs %.2f)", criteria.Type, criteria.Percentile, result.ActualValue, criteria.Threshold) | ||
continue | ||
} | ||
|
||
format := "\n- %s: %.2f (needs %.2f)" | ||
if criteria.Type == config.RequestCountMetricsCheck { | ||
// No decimals for request count. | ||
format = "\n- %s: %.0f (needs %.0f)" | ||
} | ||
report += fmt.Sprintf(format, criteria.Type, result.ActualValue, criteria.Threshold) | ||
} | ||
|
||
return report | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package health_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/GoogleCloudPlatform/cloud-run-release-operator/pkg/config" | ||
"github.com/GoogleCloudPlatform/cloud-run-release-operator/pkg/health" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestStringReport(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
healthCriteria []config.Metric | ||
diagnosis health.Diagnosis | ||
expected string | ||
}{ | ||
{ | ||
name: "single metrics", | ||
healthCriteria: []config.Metric{ | ||
{Type: config.LatencyMetricsCheck, Percentile: 99, Threshold: 750}, | ||
}, | ||
diagnosis: health.Diagnosis{ | ||
OverallResult: health.Unhealthy, | ||
CheckResults: []health.CheckResult{ | ||
{Threshold: 750, ActualValue: 1000, IsCriteriaMet: true}, | ||
}, | ||
}, | ||
expected: "status: unhealthy\n" + | ||
"metrics:" + | ||
"\n- request-latency[p99]: 1000.00 (needs 750.00)", | ||
}, | ||
{ | ||
name: "more than one metrics", | ||
healthCriteria: []config.Metric{ | ||
{Type: config.RequestCountMetricsCheck, Threshold: 1000}, | ||
{Type: config.LatencyMetricsCheck, Percentile: 99, Threshold: 750}, | ||
{Type: config.ErrorRateMetricsCheck, Threshold: 5}, | ||
}, | ||
diagnosis: health.Diagnosis{ | ||
OverallResult: health.Healthy, | ||
CheckResults: []health.CheckResult{ | ||
{Threshold: 1000, ActualValue: 1500, IsCriteriaMet: true}, | ||
{Threshold: 750, ActualValue: 500, IsCriteriaMet: true}, | ||
{Threshold: 5, ActualValue: 2, IsCriteriaMet: true}, | ||
}, | ||
}, | ||
expected: "status: healthy\n" + | ||
"metrics:" + | ||
"\n- request-count: 1500 (needs 1000)" + | ||
"\n- request-latency[p99]: 500.00 (needs 750.00)" + | ||
"\n- error-rate-percent: 2.00 (needs 5.00)", | ||
}, | ||
{ | ||
name: "no metrics", | ||
expected: "status: unknown\nmetrics:", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(tt *testing.T) { | ||
report := health.StringReport(test.healthCriteria, test.diagnosis) | ||
assert.Equal(tt, test.expected, report) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters