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

Side by Side Diff: milo/appengine/logdog/http.go

Issue 2674603002: milo: Export LogDog annotation stream, remove host (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package logdog 5 package logdog
6 6
7 import ( 7 import (
8 "net/http" 8 "net/http"
9 "strings" 9 "strings"
10 10
11 "github.com/luci/luci-go/common/errors"
11 log "github.com/luci/luci-go/common/logging" 12 log "github.com/luci/luci-go/common/logging"
12 "github.com/luci/luci-go/grpc/prpc" 13 "github.com/luci/luci-go/grpc/prpc"
13 "github.com/luci/luci-go/logdog/client/coordinator" 14 "github.com/luci/luci-go/logdog/client/coordinator"
14 "github.com/luci/luci-go/logdog/common/types" 15 "github.com/luci/luci-go/logdog/common/types"
15 "github.com/luci/luci-go/luci_config/common/cfgtypes" 16 "github.com/luci/luci-go/luci_config/common/cfgtypes"
16 "github.com/luci/luci-go/milo/appengine/settings" 17 "github.com/luci/luci-go/milo/appengine/settings"
17 "github.com/luci/luci-go/milo/common/miloerror" 18 "github.com/luci/luci-go/milo/common/miloerror"
18 "github.com/luci/luci-go/server/auth" 19 "github.com/luci/luci-go/server/auth"
19 "github.com/luci/luci-go/server/templates" 20 "github.com/luci/luci-go/server/templates"
20 21
21 "github.com/julienschmidt/httprouter" 22 "github.com/julienschmidt/httprouter"
22 "golang.org/x/net/context" 23 "golang.org/x/net/context"
23 ) 24 )
24 25
25 // AnnotationStream is a ThemedHandler that renders a LogDog Milo annotation 26 // AnnotationStreamHandler is a ThemedHandler that renders a LogDog Milo
26 // protobuf stream. 27 // annotation protobuf stream.
27 // 28 //
28 // The protobuf stream is fetched live from LogDog and cached locally, either 29 // The protobuf stream is fetched live from LogDog and cached locally, either
29 // temporarily (if incomplete) or indefinitely (if complete). 30 // temporarily (if incomplete) or indefinitely (if complete).
30 type AnnotationStream struct { 31 type AnnotationStreamHandler struct{}
31 » // logDogClient is a reusable HTTP client to use for LogDog.
32 » logDogClient *http.Client
33 }
34 32
35 // GetTemplateName implements settings.ThemedHandler. 33 // GetTemplateName implements settings.ThemedHandler.
36 func (s *AnnotationStream) GetTemplateName(t settings.Theme) string { 34 func (s *AnnotationStreamHandler) GetTemplateName(t settings.Theme) string {
37 return "build.html" 35 return "build.html"
38 } 36 }
39 37
40 // Render implements settings.ThemedHandler. 38 // Render implements settings.ThemedHandler.
41 func (s *AnnotationStream) Render(c context.Context, req *http.Request, p httpro uter.Params) (*templates.Args, error) { 39 func (s *AnnotationStreamHandler) Render(c context.Context, req *http.Request, p httprouter.Params) (
42 » // Initialize the LogDog client authentication. 40 » *templates.Args, error) {
43 » t, err := auth.GetRPCTransport(c, auth.AsUser) 41
44 » if err != nil { 42 » as := AnnotationStream{
45 » » log.WithError(err).Errorf(c, "Failed to get transport for LogDog server.") 43 » » Project: cfgtypes.ProjectName(p.ByName("project")),
44 » » Path: types.StreamPath(strings.Trim(p.ByName("path"), "/")),
45 » }
46 » if err := as.Normalize(); err != nil {
47 » » return nil, err
48 » }
49
50 » // Setup our LogDog client.
51 » var err error
52 » if as.Client, err = NewClient(c, ""); err != nil {
53 » » log.WithError(err).Errorf(c, "Failed to generate LogDog client." )
46 return nil, &miloerror.Error{ 54 return nil, &miloerror.Error{
47 Code: http.StatusInternalServerError, 55 Code: http.StatusInternalServerError,
48 } 56 }
49 } 57 }
50 58
51 » as := annotationStreamRequest{ 59 » // Load the Milo annotation protobuf from the annotation stream.
52 » » AnnotationStream: s, 60 » if err := as.Load(c); err != nil {
53
54 » » project: cfgtypes.ProjectName(p.ByName("project")),
55 » » path: types.StreamPath(strings.Trim(p.ByName("path"), "/")),
56 » » host: req.FormValue("host"),
57 » }
58 » if err := as.normalize(); err != nil {
59 return nil, err 61 return nil, err
60 } 62 }
61 63
62 // Setup our LogDog client.
63 as.logDogClient = coordinator.NewClient(&prpc.Client{
64 C: &http.Client{
65 Transport: t,
66 },
67 Host: as.host,
68 })
69
70 // Load the Milo annotation protobuf from the annotation stream.
71 if err := as.load(c); err != nil {
72 return nil, err
73 }
74
75 // Convert the Milo Annotation protobuf to Milo objects. 64 // Convert the Milo Annotation protobuf to Milo objects.
76 return &templates.Args{ 65 return &templates.Args{
77 "Build": as.toMiloBuild(c), 66 "Build": as.toMiloBuild(c),
78 }, nil 67 }, nil
79 } 68 }
69
70 // NewClient generates a new LogDog client that issues requests on behalf of the
71 // current user.
72 func NewClient(c context.Context, host string) (*coordinator.Client, error) {
73 if host == "" {
74 host = defaultLogDogHost
75 }
76
77 // Initialize the LogDog client authentication.
78 t, err := auth.GetRPCTransport(c, auth.AsUser)
79 if err != nil {
80 return nil, errors.New("failed to get transport for LogDog serve r")
81 }
82
83 // Setup our LogDog client.
84 return coordinator.NewClient(&prpc.Client{
85 C: &http.Client{
86 Transport: t,
87 },
88 Host: host,
89 }), nil
90 }
OLDNEW
« milo/appengine/logdog/build.go ('K') | « milo/appengine/logdog/build.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698