projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
17944: Only check for value aliases collision between different values.
[arvados.git]
/
sdk
/
go
/
health
/
aggregator.go
diff --git
a/sdk/go/health/aggregator.go
b/sdk/go/health/aggregator.go
index d8c0a4abfbafead971e25fb7faa330484d8dedee..a666ef8ec02803354e80bc3a80e61910b5f3c0f4 100644
(file)
--- a/
sdk/go/health/aggregator.go
+++ b/
sdk/go/health/aggregator.go
@@
-14,8
+14,8
@@
import (
"sync"
"time"
"sync"
"time"
- "git.
curoverse.com
/arvados.git/sdk/go/arvados"
- "git.
curoverse.com
/arvados.git/sdk/go/auth"
+ "git.
arvados.org
/arvados.git/sdk/go/arvados"
+ "git.
arvados.org
/arvados.git/sdk/go/auth"
)
const defaultTimeout = arvados.Duration(2 * time.Second)
)
const defaultTimeout = arvados.Duration(2 * time.Second)
@@
-28,7
+28,7
@@
type Aggregator struct {
httpClient *http.Client
timeout arvados.Duration
httpClient *http.Client
timeout arvados.Duration
- C
onfig *arvados.Config
+ C
luster *arvados.Cluster
// If non-nil, Log is called after handling each request.
Log func(*http.Request, error)
// If non-nil, Log is called after handling each request.
Log func(*http.Request, error)
@@
-42,6
+42,14
@@
func (agg *Aggregator) setup() {
}
}
}
}
+func (agg *Aggregator) CheckHealth() error {
+ return nil
+}
+
+func (agg *Aggregator) Done() <-chan struct{} {
+ return nil
+}
+
func (agg *Aggregator) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
agg.setupOnce.Do(agg.setup)
sendErr := func(statusCode int, err error) {
func (agg *Aggregator) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
agg.setupOnce.Do(agg.setup)
sendErr := func(statusCode int, err error) {
@@
-54,21
+62,18
@@
func (agg *Aggregator) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
resp.Header().Set("Content-Type", "application/json")
resp.Header().Set("Content-Type", "application/json")
- cluster, err := agg.Config.GetCluster("")
- if err != nil {
- err = fmt.Errorf("arvados.GetCluster(): %s", err)
- sendErr(http.StatusInternalServerError, err)
- return
- }
- if !agg.checkAuth(req, cluster) {
+ if !agg.checkAuth(req) {
sendErr(http.StatusUnauthorized, errUnauthorized)
return
}
sendErr(http.StatusUnauthorized, errUnauthorized)
return
}
- if req.URL.Path != "/_health/all" {
+ if req.URL.Path == "/_health/all" {
+ json.NewEncoder(resp).Encode(agg.ClusterHealth())
+ } else if req.URL.Path == "/_health/ping" {
+ resp.Write(healthyBody)
+ } else {
sendErr(http.StatusNotFound, errNotFound)
return
}
sendErr(http.StatusNotFound, errNotFound)
return
}
- json.NewEncoder(resp).Encode(agg.ClusterHealth(cluster))
if agg.Log != nil {
agg.Log(req, nil)
}
if agg.Log != nil {
agg.Log(req, nil)
}
@@
-104,7
+109,8
@@
type ServiceHealth struct {
N int `json:"n"`
}
N int `json:"n"`
}
-func (agg *Aggregator) ClusterHealth(cluster *arvados.Cluster) ClusterHealthResponse {
+func (agg *Aggregator) ClusterHealth() ClusterHealthResponse {
+ agg.setupOnce.Do(agg.setup)
resp := ClusterHealthResponse{
Health: "OK",
Checks: make(map[string]CheckResult),
resp := ClusterHealthResponse{
Health: "OK",
Checks: make(map[string]CheckResult),
@@
-113,7
+119,7
@@
func (agg *Aggregator) ClusterHealth(cluster *arvados.Cluster) ClusterHealthResp
mtx := sync.Mutex{}
wg := sync.WaitGroup{}
mtx := sync.Mutex{}
wg := sync.WaitGroup{}
- for svcName, svc := range
c
luster.Services.Map() {
+ for svcName, svc := range
agg.C
luster.Services.Map() {
// Ensure svc is listed in resp.Services.
mtx.Lock()
if _, ok := resp.Services[svcName]; !ok {
// Ensure svc is listed in resp.Services.
mtx.Lock()
if _, ok := resp.Services[svcName]; !ok {
@@
-133,7
+139,7
@@
func (agg *Aggregator) ClusterHealth(cluster *arvados.Cluster) ClusterHealthResp
Error: err.Error(),
}
} else {
Error: err.Error(),
}
} else {
- result = agg.ping(pingURL
, cluster
)
+ result = agg.ping(pingURL)
}
mtx.Lock()
}
mtx.Lock()
@@
-168,7
+174,7
@@
func (agg *Aggregator) pingURL(svcURL arvados.URL) (*url.URL, error) {
return base.Parse("/_health/ping")
}
return base.Parse("/_health/ping")
}
-func (agg *Aggregator) ping(target *url.URL
, cluster *arvados.Cluster
) (result CheckResult) {
+func (agg *Aggregator) ping(target *url.URL) (result CheckResult) {
t0 := time.Now()
var err error
t0 := time.Now()
var err error
@@
-185,7
+191,10
@@
func (agg *Aggregator) ping(target *url.URL, cluster *arvados.Cluster) (result C
if err != nil {
return
}
if err != nil {
return
}
- req.Header.Set("Authorization", "Bearer "+cluster.ManagementToken)
+ req.Header.Set("Authorization", "Bearer "+agg.Cluster.ManagementToken)
+
+ // Avoid workbench1's redirect-http-to-https feature
+ req.Header.Set("X-Forwarded-Proto", "https")
ctx, cancel := context.WithTimeout(req.Context(), time.Duration(agg.timeout))
defer cancel()
ctx, cancel := context.WithTimeout(req.Context(), time.Duration(agg.timeout))
defer cancel()
@@
-211,10
+220,10
@@
func (agg *Aggregator) ping(target *url.URL, cluster *arvados.Cluster) (result C
return
}
return
}
-func (agg *Aggregator) checkAuth(req *http.Request
, cluster *arvados.Cluster
) bool {
+func (agg *Aggregator) checkAuth(req *http.Request) bool {
creds := auth.CredentialsFromRequest(req)
for _, token := range creds.Tokens {
creds := auth.CredentialsFromRequest(req)
for _, token := range creds.Tokens {
- if token != "" && token ==
c
luster.ManagementToken {
+ if token != "" && token ==
agg.C
luster.ManagementToken {
return true
}
}
return true
}
}