| OLD | NEW |
| 1 package main | 1 package main |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "encoding/json" | 4 "encoding/json" |
| 5 "flag" | 5 "flag" |
| 6 "fmt" | 6 "fmt" |
| 7 "net/http" | 7 "net/http" |
| 8 "path/filepath" | 8 "path/filepath" |
| 9 "time" | 9 "time" |
| 10 | 10 |
| 11 "github.com/golang/glog" | 11 "github.com/golang/glog" |
| 12 "github.com/gorilla/mux" | 12 "github.com/gorilla/mux" |
| 13 "skia.googlesource.com/buildbot.git/go/auth" | 13 "skia.googlesource.com/buildbot.git/go/auth" |
| 14 "skia.googlesource.com/buildbot.git/go/common" | 14 "skia.googlesource.com/buildbot.git/go/common" |
| 15 "skia.googlesource.com/buildbot.git/go/database" | 15 "skia.googlesource.com/buildbot.git/go/database" |
| 16 "skia.googlesource.com/buildbot.git/go/login" | 16 "skia.googlesource.com/buildbot.git/go/login" |
| 17 "skia.googlesource.com/buildbot.git/go/metadata" | 17 "skia.googlesource.com/buildbot.git/go/metadata" |
| 18 "skia.googlesource.com/buildbot.git/golden/go/analysis" | 18 "skia.googlesource.com/buildbot.git/golden/go/analysis" |
| 19 "skia.googlesource.com/buildbot.git/golden/go/db" | 19 "skia.googlesource.com/buildbot.git/golden/go/db" |
| 20 "skia.googlesource.com/buildbot.git/golden/go/expstorage" | 20 "skia.googlesource.com/buildbot.git/golden/go/expstorage" |
| 21 "skia.googlesource.com/buildbot.git/golden/go/filediffstore" | 21 "skia.googlesource.com/buildbot.git/golden/go/filediffstore" |
| 22 "skia.googlesource.com/buildbot.git/golden/go/types" | 22 "skia.googlesource.com/buildbot.git/golden/go/types" |
| 23 "skia.googlesource.com/buildbot.git/perf/go/filetilestore" | 23 "skia.googlesource.com/buildbot.git/perf/go/filetilestore" |
| 24 ) | 24 ) |
| 25 | 25 |
| 26 // Command line flags. | 26 // Command line flags. |
| 27 var ( | 27 var ( |
| 28 // Get the default connection string suitable for production. | |
| 29 defaultDbConnStr = db.GetConnectionString("readwrite", "", "", "") | |
| 30 | |
| 31 graphiteServer = flag.String("graphite_server", "skia-monitoring:2003",
"Where is Graphite metrics ingestion server running.") | 28 graphiteServer = flag.String("graphite_server", "skia-monitoring:2003",
"Where is Graphite metrics ingestion server running.") |
| 32 port = flag.String("port", ":9000", "HTTP service address (e.g
., ':9000')") | 29 port = flag.String("port", ":9000", "HTTP service address (e.g
., ':9000')") |
| 33 local = flag.Bool("local", false, "Running locally if true. As
opposed to in production.") | 30 local = flag.Bool("local", false, "Running locally if true. As
opposed to in production.") |
| 34 staticDir = flag.String("static_dir", "./app", "Directory with stat
ic content to serve") | 31 staticDir = flag.String("static_dir", "./app", "Directory with stat
ic content to serve") |
| 35 tileStoreDir = flag.String("tile_store_dir", "/tmp/tileStore", "What d
irectory to look for tiles in.") | 32 tileStoreDir = flag.String("tile_store_dir", "/tmp/tileStore", "What d
irectory to look for tiles in.") |
| 36 imageDir = flag.String("image_dir", "/tmp/imagedir", "What directo
ry to store test and diff images in.") | 33 imageDir = flag.String("image_dir", "/tmp/imagedir", "What directo
ry to store test and diff images in.") |
| 37 gsBucketName = flag.String("gs_bucket", "chromium-skia-gm", "Name of t
he google storage bucket that holds uploaded images.") | 34 gsBucketName = flag.String("gs_bucket", "chromium-skia-gm", "Name of t
he google storage bucket that holds uploaded images.") |
| 38 dbConnStr = flag.String("db_conn_string", defaultDbConnStr, "MySQL
connection string for backend database. If 'local' is false the password in this
string will be substituted via the metadata server.") | |
| 39 sqlitePath = flag.String("sqlite_path", "./golden.db", "Filepath of
the embedded SQLite database. Requires 'local' to be set to true and 'mysql_conn
' to be empty to take effect.") | |
| 40 doOauth = flag.Bool("oauth", true, "Run through the OAuth 2.0 flo
w on startup, otherwise use a GCE service account.") | 35 doOauth = flag.Bool("oauth", true, "Run through the OAuth 2.0 flo
w on startup, otherwise use a GCE service account.") |
| 41 oauthCacheFile = flag.String("oauth_cache_file", "/home/perf/google_stor
age_token.data", "Path to the file where to cache cache the oauth credentials.") | 36 oauthCacheFile = flag.String("oauth_cache_file", "/home/perf/google_stor
age_token.data", "Path to the file where to cache cache the oauth credentials.") |
| 42 ) | 37 ) |
| 43 | 38 |
| 44 const ( | 39 const ( |
| 45 IMAGE_URL_PREFIX = "/img/" | 40 IMAGE_URL_PREFIX = "/img/" |
| 46 ) | 41 ) |
| 47 | 42 |
| 48 // TODO (stephana): Factor out to "go/login/login.go" | 43 // TODO (stephana): Factor out to "go/login/login.go" |
| 49 const ( | 44 const ( |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 client, err := auth.RunFlow(config) | 218 client, err := auth.RunFlow(config) |
| 224 if err != nil { | 219 if err != nil { |
| 225 glog.Fatalf("Failed to auth: %s", err) | 220 glog.Fatalf("Failed to auth: %s", err) |
| 226 } | 221 } |
| 227 return client | 222 return client |
| 228 } | 223 } |
| 229 return nil | 224 return nil |
| 230 } | 225 } |
| 231 | 226 |
| 232 func main() { | 227 func main() { |
| 228 // Setup DB flags. |
| 229 database.SetupFlags(db.PROD_DB_HOST, db.PROD_DB_PORT, database.USER_RW,
db.PROD_DB_NAME) |
| 230 |
| 233 // Global init to initialize | 231 // Global init to initialize |
| 234 common.InitWithMetrics("skiacorrectness", *graphiteServer) | 232 common.InitWithMetrics("skiacorrectness", *graphiteServer) |
| 235 | 233 |
| 236 // Initialize submodules. | 234 // Initialize submodules. |
| 237 filediffstore.Init() | 235 filediffstore.Init() |
| 238 | 236 |
| 239 // Set up login | 237 // Set up login |
| 240 // TODO (stephana): Factor out to go/login/login.go and removed hard cod
ed | 238 // TODO (stephana): Factor out to go/login/login.go and removed hard cod
ed |
| 241 // values. | 239 // values. |
| 242 var cookieSalt = "notverysecret" | 240 var cookieSalt = "notverysecret" |
| 243 var clientID = "31977622648-ubjke2f3staq6ouas64r31h8f8tcbiqp.apps.google
usercontent.com" | 241 var clientID = "31977622648-ubjke2f3staq6ouas64r31h8f8tcbiqp.apps.google
usercontent.com" |
| 244 var clientSecret = "rK-kRY71CXmcg0v9I9KIgWci" | 242 var clientSecret = "rK-kRY71CXmcg0v9I9KIgWci" |
| 245 var redirectURL = fmt.Sprintf("http://localhost%s/oauth2callback/", *por
t) | 243 var redirectURL = fmt.Sprintf("http://localhost%s/oauth2callback/", *por
t) |
| 246 if !*local { | 244 if !*local { |
| 247 cookieSalt = metadata.MustGet(COOKIESALT_METADATA_KEY) | 245 cookieSalt = metadata.MustGet(COOKIESALT_METADATA_KEY) |
| 248 clientID = metadata.MustGet(CLIENT_ID_METADATA_KEY) | 246 clientID = metadata.MustGet(CLIENT_ID_METADATA_KEY) |
| 249 clientSecret = metadata.MustGet(CLIENT_SECRET_METADATA_KEY) | 247 clientSecret = metadata.MustGet(CLIENT_SECRET_METADATA_KEY) |
| 250 redirectURL = "https://skiagold.com/oauth2callback/" | 248 redirectURL = "https://skiagold.com/oauth2callback/" |
| 251 } | 249 } |
| 252 login.Init(clientID, clientSecret, redirectURL, cookieSalt) | 250 login.Init(clientID, clientSecret, redirectURL, cookieSalt) |
| 253 | 251 |
| 254 // get the Oauthclient if necessary. | 252 // get the Oauthclient if necessary. |
| 255 client := getOAuthClient(*doOauth, *oauthCacheFile) | 253 client := getOAuthClient(*doOauth, *oauthCacheFile) |
| 256 | 254 |
| 257 // Get the expecations storage, the filediff storage and the tilestore. | 255 // Get the expecations storage, the filediff storage and the tilestore. |
| 258 diffStore := filediffstore.NewFileDiffStore(client, *imageDir, *gsBucket
Name, filediffstore.DEFAULT_GS_IMG_DIR_NAME, filediffstore.RECOMMENDED_WORKER_PO
OL_SIZE) | 256 diffStore := filediffstore.NewFileDiffStore(client, *imageDir, *gsBucket
Name, filediffstore.DEFAULT_GS_IMG_DIR_NAME, filediffstore.RECOMMENDED_WORKER_PO
OL_SIZE) |
| 259 » vdb := database.NewVersionedDB(db.GetConfig(*dbConnStr, *sqlitePath, *lo
cal)) | 257 » conf, err := database.ConfigFromFlagsAndMetadata(*local, db.MigrationSte
ps()) |
| 258 » if err != nil { |
| 259 » » glog.Fatal(err) |
| 260 » } |
| 261 » vdb := database.NewVersionedDB(conf) |
| 260 expStore := expstorage.NewCachingExpectationStore(expstorage.NewSQLExpec
tationStore(vdb)) | 262 expStore := expstorage.NewCachingExpectationStore(expstorage.NewSQLExpec
tationStore(vdb)) |
| 261 tileStore := filetilestore.NewFileTileStore(*tileStoreDir, "golden", -1) | 263 tileStore := filetilestore.NewFileTileStore(*tileStoreDir, "golden", -1) |
| 262 | 264 |
| 263 // Initialize the Analyzer | 265 // Initialize the Analyzer |
| 264 imgFS := NewURLAwareFileServer(*imageDir, IMAGE_URL_PREFIX) | 266 imgFS := NewURLAwareFileServer(*imageDir, IMAGE_URL_PREFIX) |
| 265 analyzer = analysis.NewAnalyzer(expStore, tileStore, diffStore, imgFS.Ge
tURL, 5*time.Minute) | 267 analyzer = analysis.NewAnalyzer(expStore, tileStore, diffStore, imgFS.Ge
tURL, 5*time.Minute) |
| 266 | 268 |
| 267 router := mux.NewRouter() | 269 router := mux.NewRouter() |
| 268 | 270 |
| 269 // Wire up the resources. We use the 'rest' prefix to avoid any name | 271 // Wire up the resources. We use the 'rest' prefix to avoid any name |
| (...skipping 18 matching lines...) Expand all Loading... |
| 288 // Everything else is served out of the static directory. | 290 // Everything else is served out of the static directory. |
| 289 router.PathPrefix("/").Handler(http.FileServer(http.Dir(*staticDir))) | 291 router.PathPrefix("/").Handler(http.FileServer(http.Dir(*staticDir))) |
| 290 | 292 |
| 291 // Send all requests to the router | 293 // Send all requests to the router |
| 292 http.Handle("/", router) | 294 http.Handle("/", router) |
| 293 | 295 |
| 294 // Start the server | 296 // Start the server |
| 295 glog.Infoln("Serving on http://127.0.0.1" + *port) | 297 glog.Infoln("Serving on http://127.0.0.1" + *port) |
| 296 glog.Fatal(http.ListenAndServe(*port, nil)) | 298 glog.Fatal(http.ListenAndServe(*port, nil)) |
| 297 } | 299 } |
| OLD | NEW |