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

Unified Diff: appengine/cmd/milo/logdog/http.go

Issue 2191693003: Milo: Add LogDog annotation stream support. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Rebarse Created 4 years, 5 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/cmd/milo/logdog/build.go ('k') | appengine/cmd/milo/logdog/internal/gen.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/cmd/milo/logdog/http.go
diff --git a/appengine/cmd/milo/logdog/http.go b/appengine/cmd/milo/logdog/http.go
new file mode 100644
index 0000000000000000000000000000000000000000..0c53c16336c80a0b22c0afb5053ca2c6b273c122
--- /dev/null
+++ b/appengine/cmd/milo/logdog/http.go
@@ -0,0 +1,73 @@
+// 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 logdog
+
+import (
+ "net/http"
+ "strings"
+
+ "github.com/julienschmidt/httprouter"
+ "github.com/luci/luci-go/appengine/cmd/milo/miloerror"
+ "github.com/luci/luci-go/appengine/cmd/milo/settings"
+ authClient "github.com/luci/luci-go/appengine/gaeauth/client"
+ "github.com/luci/luci-go/common/config"
+ log "github.com/luci/luci-go/common/logging"
+ "github.com/luci/luci-go/logdog/common/types"
+ "github.com/luci/luci-go/server/templates"
+
+ "golang.org/x/net/context"
+)
+
+// AnnotationStream is a ThemedHandler that renders a LogDog Milo annotation
+// protobuf stream.
+//
+// The protobuf stream is fetched live from LogDog and cached locally, either
+// temporarily (if incomplete) or indefinitely (if complete).
+type AnnotationStream struct {
+ // logDogClient is a reusable HTTP client to use for LogDog.
+ logDogClient *http.Client
+}
+
+// GetTemplateName implements settings.ThemedHandler.
+func (s *AnnotationStream) GetTemplateName(t settings.Theme) string {
+ return "build.html"
+}
+
+// Render implements settings.ThemedHandler.
+func (s *AnnotationStream) Render(c context.Context, req *http.Request, p httprouter.Params) (*templates.Args, error) {
+ // Initialize the LogDog client authentication.
+ a, err := authClient.Transport(c, nil, nil)
+ if err != nil {
+ log.WithError(err).Errorf(c, "Failed to get transport for LogDog server.")
+ return nil, &miloerror.Error{
+ Code: http.StatusInternalServerError,
+ }
+ }
+
+ as := annotationStreamRequest{
+ AnnotationStream: s,
+
+ project: config.ProjectName(p.ByName("project")),
+ path: types.StreamPath(strings.Trim(p.ByName("path"), "/")),
+ host: req.FormValue("host"),
+
+ logDogClient: http.Client{
+ Transport: a,
+ },
+ }
+ if err := as.normalize(); err != nil {
+ return nil, err
+ }
+
+ // Load the Milo annotation protobuf from the annotation stream.
+ if err := as.load(c); err != nil {
+ return nil, err
+ }
+
+ // Convert the Milo Annotation protobuf to Milo objects.
+ return &templates.Args{
+ "Build": as.toMiloBuild(c),
+ }, nil
+}
« no previous file with comments | « appengine/cmd/milo/logdog/build.go ('k') | appengine/cmd/milo/logdog/internal/gen.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698