sandbox: fix health check, reduce number of instances
Change-Id: I906924a881467f2b23f90fd8abb07e7ae201922e
Reviewed-on: https://go-review.googlesource.com/2799
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/sandbox/app.yaml b/sandbox/app.yaml
index 0d5901f..0429b7f 100644
--- a/sandbox/app.yaml
+++ b/sandbox/app.yaml
@@ -5,7 +5,7 @@
vm: true
manual_scaling:
- instances: 15
+ instances: 5
health_check:
check_interval_sec: 20
diff --git a/sandbox/sandbox.go b/sandbox/sandbox.go
index 19c0dfd..6f10f16 100644
--- a/sandbox/sandbox.go
+++ b/sandbox/sandbox.go
@@ -83,25 +83,30 @@
return &Response{Events: events}, nil
}
-const healthProg = `package main;import "fmt";func main(){fmt.Print("ok")}`
-
func healthHandler(w http.ResponseWriter, r *http.Request) {
- resp, err := compileAndRun(&Request{Body: healthProg})
- if err == nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
- if resp.Errors != "" {
- http.Error(w, fmt.Sprintf("compile error: %v", resp.Errors), http.StatusInternalServerError)
- return
- }
- if len(resp.Events) != 1 || resp.Events[0].Message != "ok" {
- http.Error(w, fmt.Sprintf("bad health check output: %v", resp.Events), http.StatusInternalServerError)
+ if err := healthCheck(); err != nil {
+ http.Error(w, "Health check failed: "+err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprint(w, "ok")
}
+const healthProg = `package main;import "fmt";func main(){fmt.Print("ok")}`
+
+func healthCheck() error {
+ resp, err := compileAndRun(&Request{Body: healthProg})
+ if err != nil {
+ return err
+ }
+ if resp.Errors != "" {
+ return fmt.Errorf("compile error: %v", resp.Errors)
+ }
+ if len(resp.Events) != 1 || resp.Events[0].Message != "ok" {
+ return fmt.Errorf("unexpected output: %v", resp.Events)
+ }
+ return nil
+}
+
func main() {
http.HandleFunc("/compile", compileHandler)
http.HandleFunc("/_ah/health", healthHandler)