@@ -17,6 +17,7 @@ limitations under the License.
17
17
package app
18
18
19
19
import (
20
+ "bytes"
20
21
"context"
21
22
"crypto/tls"
22
23
"fmt"
@@ -26,6 +27,7 @@ import (
26
27
"runtime"
27
28
runpprof "runtime/pprof"
28
29
"strconv"
30
+ "strings"
29
31
"time"
30
32
31
33
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -107,14 +109,38 @@ func (a *Agent) runHealthServer(o *options.GrpcProxyAgentOptions, cs agent.Readi
107
109
livenessHandler := http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
108
110
fmt .Fprintf (w , "ok" )
109
111
})
112
+
113
+ checks := []agent.HealthChecker {agent .Ping , agent .NewServerConnected (cs )}
110
114
readinessHandler := http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
111
- if cs .Ready () {
112
- w .WriteHeader (http .StatusOK )
113
- fmt .Fprintf (w , "ok" )
114
- } else {
115
+ var failedChecks []string
116
+ var individualCheckOutput bytes.Buffer
117
+ for _ , check := range checks {
118
+ if err := check .Check (r ); err != nil {
119
+ fmt .Fprintf (& individualCheckOutput , "[-]%s failed: %v\n " , check .Name (), err )
120
+ failedChecks = append (failedChecks , check .Name ())
121
+ } else {
122
+ fmt .Fprintf (& individualCheckOutput , "[+]%s ok\n " , check .Name ())
123
+ }
124
+ }
125
+
126
+ // Always be verbose if the check has failed
127
+ if len (failedChecks ) > 0 {
128
+ klog .V (0 ).Infoln ("%s check failed: \n %v" , strings .Join (failedChecks , "," ), individualCheckOutput .String ())
115
129
w .WriteHeader (http .StatusServiceUnavailable )
116
- fmt .Fprintf (w , "not ready" )
130
+ fmt .Fprintf (w , individualCheckOutput .String ())
131
+ return
117
132
}
133
+
134
+ if _ , found := r .URL .Query ()["verbose" ]; ! found {
135
+ w .WriteHeader (http .StatusOK )
136
+ fmt .Fprint (w , "ok" )
137
+ return
138
+ }
139
+
140
+ fmt .Fprintf (& individualCheckOutput , "check passed\n " )
141
+
142
+ w .WriteHeader (http .StatusOK )
143
+ fmt .Fprint (w , individualCheckOutput .String ())
118
144
})
119
145
120
146
muxHandler := http .NewServeMux ()
0 commit comments