Chromium Code Reviews| Index: fuzzer/go/fuzzer/main.go |
| diff --git a/fuzzer/go/fuzzer/main.go b/fuzzer/go/fuzzer/main.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4c6065956a15c8e0557b1732b5f2e54255bae10c |
| --- /dev/null |
| +++ b/fuzzer/go/fuzzer/main.go |
| @@ -0,0 +1,91 @@ |
| +package main |
| + |
| +import ( |
| + "flag" |
| + htemplate "html/template" |
| + "math/rand" |
| + "net" |
| + "net/http" |
| + "os" |
| + "path/filepath" |
| + "time" |
| +) |
|
jcgregorio
2015/02/11 12:49:11
Have all imports in one import() section, put a si
humper
2015/02/11 13:17:50
Done.
|
| + |
| +import ( |
| + "github.com/BurntSushi/toml" |
| + "github.com/fiorix/go-web/autogzip" |
| + metrics "github.com/rcrowley/go-metrics" |
| + "github.com/skia-dev/glog" |
| + "skia.googlesource.com/buildbot.git/fuzzer/go/config" |
| + "skia.googlesource.com/buildbot.git/go/common" |
| +) |
| + |
| +var ( |
| + // indexTemplate is the main index.html page we serve. |
| + indexTemplate *htemplate.Template = nil |
| + |
| + requestsCounter = metrics.NewRegisteredCounter("requests", metrics.DefaultRegistry) |
| +) |
| + |
| +// Command line flags. |
| +var ( |
| + configFilename = flag.String("config_filename", "fuzzer.toml", "Configuration filename") |
|
jcgregorio
2015/02/11 12:49:11
Just 'config'.
humper
2015/02/11 13:17:51
Done.
|
| +) |
| + |
| +func Init() { |
| + rand.Seed(time.Now().UnixNano()) |
| + |
| + common.Init() |
| + |
| + if _, err := toml.DecodeFile(*configFilename, &config.FuzzerConfig); err != nil { |
| + glog.Fatalf("Failed to decode config file: %s", err) |
| + } |
| + |
| + path, err := filepath.Abs(config.FuzzerConfig.FrontEnd.ResourcePath) |
|
jcgregorio
2015/02/11 12:49:11
This looks like it requires that the path be provi
humper
2015/02/11 13:17:50
Done.
|
| + if err != nil { |
| + glog.Fatal(err) |
|
jcgregorio
2015/02/11 12:49:11
Always try to give errors some context:
glog.Fa
humper
2015/02/11 13:17:50
Done.
|
| + } |
| + if err := os.Chdir(path); err != nil { |
| + glog.Fatal(err) |
| + } |
| + |
| + indexTemplate = htemplate.Must(htemplate.ParseFiles( |
| + filepath.Join(path, "templates/index.html"), |
| + filepath.Join(path, "templates/header.html"), |
| + filepath.Join(path, "templates/footer.html"), |
| + )) |
| + |
| + metrics.RegisterRuntimeMemStats(metrics.DefaultRegistry) |
|
jcgregorio
2015/02/11 12:49:11
Don't do this manually, instead call common.InitWi
humper
2015/02/11 13:17:50
Done.
|
| + go metrics.CaptureRuntimeMemStats(metrics.DefaultRegistry, 1*time.Minute) |
| + |
| + // Start reporting metrics. |
| + // TODO(jcgregorio) We need a centrialized config server for storing things |
| + // like the IP address of the Graphite monitor. |
| + addr, _ := net.ResolveTCPAddr("tcp", "skia-monitoring-b:2003") |
|
jcgregorio
2015/02/11 12:49:11
Put the address of the graphite server in the toml
humper
2015/02/11 13:17:50
Done.
|
| + go metrics.Graphite(metrics.DefaultRegistry, 1*time.Minute, "fuzzer", addr) |
| +} |
| + |
| +type indexContext struct { |
| +} |
| + |
| +// mainHandler handles the GET and POST of the main page. |
| +func mainHandler(w http.ResponseWriter, r *http.Request) { |
| + glog.Infof("Main Handler: %q\n", r.URL.Path) |
| + requestsCounter.Inc(1) |
| + if r.Method == "GET" { |
| + // Expand the template. |
| + w.Header().Set("Content-Type", "text/html") |
| + if err := indexTemplate.Execute(w, indexContext{}); err != nil { |
|
jcgregorio
2015/02/11 12:49:11
Since indexContext is empty you can drop it and in
humper
2015/02/11 13:17:50
It's empty for now; I'm sure there will be stuff i
|
| + glog.Errorf("Failed to expand template: %q\n", err) |
| + } |
| + } |
| +} |
| + |
| +func main() { |
| + flag.Parse() |
| + Init() |
| + // Resources are served directly |
| + http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) |
| + http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) |
| + glog.Fatal(http.ListenAndServe(config.FuzzerConfig.FrontEnd.Port, nil)) |
| +} |