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

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

Issue 2717623002: Milo: Handle missing / transient LogDog failures. (Closed)
Patch Set: remote unnecessary code 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 "fmt" 8 "fmt"
9 "net/http" 9 "net/http"
10 "time" 10 "time"
11 11
12 log "github.com/luci/luci-go/common/logging" 12 log "github.com/luci/luci-go/common/logging"
13 "github.com/luci/luci-go/common/proto/google" 13 "github.com/luci/luci-go/common/proto/google"
14 miloProto "github.com/luci/luci-go/common/proto/milo" 14 miloProto "github.com/luci/luci-go/common/proto/milo"
15 "github.com/luci/luci-go/grpc/grpcutil"
16 "github.com/luci/luci-go/logdog/api/logpb" 15 "github.com/luci/luci-go/logdog/api/logpb"
17 "github.com/luci/luci-go/logdog/client/coordinator" 16 "github.com/luci/luci-go/logdog/client/coordinator"
18 "github.com/luci/luci-go/logdog/common/types" 17 "github.com/luci/luci-go/logdog/common/types"
19 "github.com/luci/luci-go/logdog/common/viewer" 18 "github.com/luci/luci-go/logdog/common/viewer"
20 "github.com/luci/luci-go/luci_config/common/cfgtypes" 19 "github.com/luci/luci-go/luci_config/common/cfgtypes"
21 "github.com/luci/luci-go/milo/api/resp" 20 "github.com/luci/luci-go/milo/api/resp"
22 "github.com/luci/luci-go/milo/appengine/logdog/internal" 21 "github.com/luci/luci-go/milo/appengine/logdog/internal"
23 "github.com/luci/luci-go/milo/common/miloerror" 22 "github.com/luci/luci-go/milo/common/miloerror"
24 23
25 "github.com/golang/protobuf/proto" 24 "github.com/golang/protobuf/proto"
26 mc "github.com/luci/gae/service/memcache" 25 mc "github.com/luci/gae/service/memcache"
27 "golang.org/x/net/context" 26 "golang.org/x/net/context"
28 "google.golang.org/grpc/codes"
29 ) 27 )
30 28
31 const ( 29 const (
32 // intermediateCacheLifetime is the amount of time to cache intermediate (non- 30 // intermediateCacheLifetime is the amount of time to cache intermediate (non-
33 // terminal) annotation streams. Terminal annotation streams are cached 31 // terminal) annotation streams. Terminal annotation streams are cached
34 // indefinitely. 32 // indefinitely.
35 intermediateCacheLifetime = 10 * time.Second 33 intermediateCacheLifetime = 10 * time.Second
36 34
37 // defaultLogDogHost is the default LogDog host, if one isn't specified via 35 // defaultLogDogHost is the default LogDog host, if one isn't specified via
38 // query string. 36 // query string.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 log.Fields{ 109 log.Fields{
112 "host": as.Client.Host, 110 "host": as.Client.Host,
113 "project": as.Project, 111 "project": as.Project,
114 "path": as.Path, 112 "path": as.Path,
115 }.Infof(c, "Making tail request to LogDog to fetch annotation stream.") 113 }.Infof(c, "Making tail request to LogDog to fetch annotation stream.")
116 114
117 var ( 115 var (
118 state coordinator.LogStream 116 state coordinator.LogStream
119 stream = as.Client.Stream(as.Project, as.Path) 117 stream = as.Client.Stream(as.Project, as.Path)
120 ) 118 )
119
121 le, err := stream.Tail(c, coordinator.WithState(&state), coordinator.Com plete()) 120 le, err := stream.Tail(c, coordinator.WithState(&state), coordinator.Com plete())
122 » switch code := grpcutil.Code(err); code { 121 » if err != nil {
123 » case codes.OK: 122 » » log.WithError(err).Errorf(c, "Failed to load stream.")
124 » » break 123 » » return nil, err
125
126 » case codes.NotFound:
127 » » return nil, &miloerror.Error{
128 » » » Message: "Stream not found",
129 » » » Code: http.StatusNotFound,
130 » » }
131
132 » default:
133 » » // TODO: Once we switch to delegation tokens and are making the request on
134 » » // behalf of a user rather than the Milo service, handle Permiss ionDenied.
135 » » log.Fields{
136 » » » log.ErrorKey: err,
137 » » » "code": code,
138 » » }.Errorf(c, "Failed to load LogDog annotation stream.")
139 » » return nil, &miloerror.Error{
140 » » » Message: "Failed to load stream",
141 » » » Code: http.StatusInternalServerError,
142 » » }
143 } 124 }
144 125
145 // Make sure that this is an annotation stream. 126 // Make sure that this is an annotation stream.
146 switch { 127 switch {
147 case state.Desc.ContentType != miloProto.ContentTypeAnnotations: 128 case state.Desc.ContentType != miloProto.ContentTypeAnnotations:
148 return nil, &miloerror.Error{ 129 return nil, &miloerror.Error{
149 Message: "Requested stream is not a Milo annotation prot obuf", 130 Message: "Requested stream is not a Milo annotation prot obuf",
150 Code: http.StatusBadRequest, 131 Code: http.StatusBadRequest,
151 } 132 }
152 133
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 if link.Label == "" { 286 if link.Label == "" {
306 link.Label = "unnamed" 287 link.Label = "unnamed"
307 } 288 }
308 return &link 289 return &link
309 290
310 default: 291 default:
311 // Don't know how to render. 292 // Don't know how to render.
312 return nil 293 return nil
313 } 294 }
314 } 295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698