Merge pull request #14059 from heww/trivy-health-checker

feat: add health checker for trivy when it's enabled
This commit is contained in:
Daniel Jiang 2021-01-24 11:44:10 +08:00 committed by GitHub
commit 7039e0d2fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,8 @@ import (
"fmt"
"io/ioutil"
"net/http"
"sort"
"strings"
"sync"
"time"
@ -77,6 +79,9 @@ func (h *HealthAPI) CheckHealth() {
}
components = append(components, componentStatus)
}
sort.Slice(components, func(i, j int) bool { return components[i].Name < components[j].Name })
status := &overallHealthStatus{}
status.Status = isHealthy.String()
status.Components = components
@ -269,6 +274,14 @@ func redisHealthChecker() health.Checker {
return PeriodicHealthChecker(checker, period)
}
func trivyHealthChecker() health.Checker {
url := strings.TrimSuffix(config.TrivyAdapterURL(), "/") + "/probe/healthy"
timeout := 60 * time.Second
period := 10 * time.Second
checker := HTTPStatusCodeHealthChecker(http.MethodGet, url, nil, timeout, http.StatusOK)
return PeriodicHealthChecker(checker, period)
}
func registerHealthCheckers() {
HealthCheckerRegistry["core"] = coreHealthChecker()
HealthCheckerRegistry["portal"] = portalHealthChecker()
@ -283,6 +296,9 @@ func registerHealthCheckers() {
if config.WithNotary() {
HealthCheckerRegistry["notary"] = notaryHealthChecker()
}
if config.WithTrivy() {
HealthCheckerRegistry["trivy"] = trivyHealthChecker()
}
}
func getRegistryURL() string {