/
ready_get.go
38 lines (31 loc) · 1.09 KB
/
ready_get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package frontend
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"net/http"
"time"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/env"
)
// checkReady checks the ready status of the frontend to make it consistent
// across the /healthz/ready endpoint and emitted metrics. We wait for 2
// minutes before indicating health. This ensures that there will be a gap in
// our health metric if we crash or restart.
func (f *frontend) checkReady() bool {
if !f.env.FeatureIsSet(env.FeatureDisableReadinessDelay) &&
time.Since(f.startTime) < 2*time.Minute {
return false
}
_, ok := f.lastChangefeed.Load().(time.Time)
return ok &&
f.ready.Load().(bool) &&
f.env.ArmClientAuthorizer().IsReady() &&
f.env.AdminClientAuthorizer().IsReady()
}
func (f *frontend) getReady(w http.ResponseWriter, r *http.Request) {
if f.checkReady() {
api.WriteCloudError(w, &api.CloudError{StatusCode: http.StatusOK})
} else {
api.WriteError(w, http.StatusInternalServerError, api.CloudErrorCodeInternalServerError, "", "Internal server error.")
}
}