Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1996)

Unified Diff: appengine/tsmon/handler.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: gaemiddleware: add middleware func for WithProd Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/tsmon/global_callback_test.go ('k') | appengine/tsmon/handler_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/tsmon/handler.go
diff --git a/appengine/tsmon/handler.go b/appengine/tsmon/handler.go
index 462af8a0f4658e669f5c9417d0bfef94cd8fd659..59bf193fb61577d8689dcd7ffdae38d5c5efeca0 100644
--- a/appengine/tsmon/handler.go
+++ b/appengine/tsmon/handler.go
@@ -1,51 +1,50 @@
// Copyright 2016 The LUCI Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package tsmon
import (
"net/http"
- "github.com/julienschmidt/httprouter"
"golang.org/x/net/context"
"github.com/luci/gae/service/datastore"
"github.com/luci/gae/service/info"
"github.com/luci/luci-go/common/clock"
"github.com/luci/luci-go/common/logging"
"github.com/luci/luci-go/common/parallel"
"github.com/luci/luci-go/common/tsmon"
- "github.com/luci/luci-go/server/middleware"
+ "github.com/luci/luci-go/server/router"
)
// InstallHandlers installs HTTP handlers for tsmon routes.
-func InstallHandlers(r *httprouter.Router, base middleware.Base) {
- r.GET("/internal/cron/ts_mon/housekeeping", base(housekeepingHandler))
+func InstallHandlers(r *router.Router, base router.MiddlewareChain) {
+ r.GET("/internal/cron/ts_mon/housekeeping", base, housekeepingHandler)
}
// housekeepingHandler is an HTTP handler that should be run every minute by
// cron on App Engine. It assigns task numbers to datastore entries, and runs
// any global metric callbacks.
-func housekeepingHandler(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
- if !info.Get(c).IsDevAppServer() && r.Header.Get("X-Appengine-Cron") != "true" {
- rw.WriteHeader(http.StatusForbidden)
- http.Error(rw, "request not made from cron", http.StatusForbidden)
+func housekeepingHandler(c *router.Context) {
+ if !info.Get(c.Context).IsDevAppServer() && c.Request.Header.Get("X-Appengine-Cron") != "true" {
+ c.Writer.WriteHeader(http.StatusForbidden)
+ http.Error(c.Writer, "request not made from cron", http.StatusForbidden)
return
}
- if err := assignTaskNumbers(c); err != nil {
- rw.WriteHeader(http.StatusInternalServerError)
+ if err := assignTaskNumbers(c.Context); err != nil {
+ c.Writer.WriteHeader(http.StatusInternalServerError)
}
- tsmon.GetState(c).RunGlobalCallbacks(c)
+ tsmon.GetState(c.Context).RunGlobalCallbacks(c.Context)
}
// assignTaskNumbers does some housekeeping on the datastore entries for App
// Engine instances - assigning unique task numbers to those without ones set,
// and expiring old entities.
func assignTaskNumbers(c context.Context) error {
c = info.Get(c).MustNamespace(instanceNamespace)
ds := datastore.Get(c)
logger := logging.Get(c)
« no previous file with comments | « appengine/tsmon/global_callback_test.go ('k') | appengine/tsmon/handler_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698