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

Unified Diff: milo/appengine/common/middleware.go

Issue 2796743004: Milo flex raw log viewer endpoint (Closed)
Patch Set: Fix module path Created 3 years, 8 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
Index: milo/appengine/common/middleware.go
diff --git a/milo/appengine/common/middleware.go b/milo/appengine/common/middleware.go
index 5e74b389009f209479d749880b8f6d6cfa2a4e2f..bbeb35c728c98451da0aaf66d354d9df3d35226e 100644
--- a/milo/appengine/common/middleware.go
+++ b/milo/appengine/common/middleware.go
@@ -8,12 +8,17 @@ import (
"net/http"
"strings"
+ "cloud.google.com/go/compute/metadata"
+
"golang.org/x/net/context"
+ "github.com/luci/gae/impl/cloud"
"github.com/luci/gae/service/info"
"github.com/luci/luci-go/appengine/gaeauth/server"
"github.com/luci/luci-go/appengine/gaemiddleware"
"github.com/luci/luci-go/common/clock"
+ "github.com/luci/luci-go/common/cloudlogging"
+ "github.com/luci/luci-go/common/logging/cloudlog"
"github.com/luci/luci-go/server/analytics"
"github.com/luci/luci-go/server/auth"
"github.com/luci/luci-go/server/auth/identity"
@@ -21,6 +26,8 @@ import (
"github.com/luci/luci-go/server/templates"
)
+var authconfig *auth.Config
+
// GetTemplateBundles is used to render HTML templates. It provides base args
// passed to all templates.
func GetTemplateBundle() *templates.Bundle {
@@ -64,6 +71,38 @@ func Base() router.MiddlewareChain {
)
}
+// Flex returns the basic middleware for use on appengine flex. Flex does not
nodir 2017/04/29 00:59:44 s/Flex/FlexBase/
hinoka 2017/05/01 23:08:02 Done.
+// allow the use of appengine APIs.
+func FlexBase() router.MiddlewareChain {
+ // Get the name of this project from the metadata server, since we're on GCE.
+ project, err := metadata.Get("project/project-id")
+ if err != nil {
+ panic(err)
+ }
+ // Use the cloud logger.
+ logger := func(c *router.Context, next router.Handler) {
+ logClient, err := cloudlogging.NewClient(
+ cloudlogging.ClientOptions{
+ ProjectID: project,
+ LogID: "gae_app",
+ ResourceType: "gae_app",
+ },
+ http.DefaultClient)
nodir 2017/04/29 00:59:44 i doubt cloud logging API will accept anonymous re
hinoka 2017/05/01 23:08:02 Acknowledged. This probably doesn't work, adding
+ if err != nil {
+ panic(err)
+ }
+ cloudlog.Use(c.Context, cloudlog.Config{}, logClient)
nodir 2017/04/29 00:59:45 this is noop because it misses c.Context = ... po
hinoka 2017/05/01 23:08:02 Oh you're right.. that explains a lot.
+ next(c)
+ }
+ // Installs the Info and Datastore services.
+ base := func(c *router.Context, next router.Handler) {
+ c.Context = cloud.UseFlex(c.Context)
+ next(c)
+ }
+ // Now chain it all together!
+ return router.NewMiddlewareChain(logger, base)
nodir 2017/04/29 00:59:44 why logger comes before base? if you plan to log u
hinoka 2017/05/01 23:08:02 Done.
+}
+
// The context key, so that we can embed the http.Request object into
// the context.
var requestKey = "http.request"

Powered by Google App Engine
This is Rietveld 408576698