snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
120
extra/server-discovery/pkg/healthcheck/check.go
Normal file
120
extra/server-discovery/pkg/healthcheck/check.go
Normal file
@@ -0,0 +1,120 @@
|
||||
package healthcheck
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type (
|
||||
checkFn func(ctx context.Context) error
|
||||
|
||||
Meta struct {
|
||||
Label string
|
||||
Description string
|
||||
}
|
||||
|
||||
check struct {
|
||||
fn checkFn
|
||||
*Meta
|
||||
}
|
||||
|
||||
result struct {
|
||||
err error
|
||||
*Meta
|
||||
}
|
||||
|
||||
results []*result
|
||||
checks struct {
|
||||
cc []*check
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
defaults *checks
|
||||
)
|
||||
|
||||
func init() {
|
||||
defaults = New()
|
||||
}
|
||||
|
||||
func Defaults() *checks {
|
||||
return defaults
|
||||
}
|
||||
|
||||
func New() *checks {
|
||||
return &checks{cc: []*check{}}
|
||||
}
|
||||
|
||||
// Add appends new check
|
||||
func (c *checks) Add(fn checkFn, label string, description ...string) {
|
||||
c.cc = append(c.cc, &check{fn, &Meta{Label: label, Description: strings.Join(description, "")}})
|
||||
}
|
||||
|
||||
func (c checks) Run(ctx context.Context) results {
|
||||
var rr = make([]*result, len(c.cc))
|
||||
|
||||
for i, c := range c.cc {
|
||||
rr[i] = &result{c.fn(ctx), c.Meta}
|
||||
}
|
||||
|
||||
return rr
|
||||
}
|
||||
|
||||
func (rr results) Healthy() bool {
|
||||
for _, c := range rr {
|
||||
if c.err != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (rr results) String() string {
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
rr.WriteTo(buf)
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func (rr results) WriteTo(w io.Writer) (int64, error) {
|
||||
var (
|
||||
p = func(f string, aa ...interface{}) {
|
||||
_, _ = fmt.Fprintf(w, f, aa...)
|
||||
}
|
||||
)
|
||||
|
||||
for _, r := range rr {
|
||||
if r.IsHealthy() {
|
||||
p("PASS")
|
||||
} else {
|
||||
p("FAIL")
|
||||
}
|
||||
|
||||
p(" %s", r.Label)
|
||||
|
||||
if !r.IsHealthy() {
|
||||
p(": %v", r.Error())
|
||||
}
|
||||
|
||||
p("\n")
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (r *result) IsHealthy() bool {
|
||||
return r != nil && r.err == nil
|
||||
}
|
||||
|
||||
func (r *result) Error() string {
|
||||
if r == nil || r.err == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return r.err.Error()
|
||||
}
|
||||
Reference in New Issue
Block a user