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

Unified Diff: logdog/appengine/coordinator/service.go

Issue 2584293002: Coordinator: AppEngine context for Pub/Sub. (Closed)
Patch Set: Comment Created 4 years 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: logdog/appengine/coordinator/service.go
diff --git a/logdog/appengine/coordinator/service.go b/logdog/appengine/coordinator/service.go
index 08adae5053fac29a0e6e274356ee8b5ae30a6ce7..7b0385d12a9b14d9c2ea6bbc58cea42aa611897e 100644
--- a/logdog/appengine/coordinator/service.go
+++ b/logdog/appengine/coordinator/service.go
@@ -5,6 +5,7 @@
package coordinator
import (
+ "net/http"
"sync"
"sync/atomic"
"time"
@@ -29,6 +30,7 @@ import (
gcst "cloud.google.com/go/storage"
"golang.org/x/net/context"
"google.golang.org/api/option"
+ "google.golang.org/appengine"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)
@@ -88,7 +90,9 @@ type Services interface {
//
// It installs a production Services instance into the Context.
func ProdCoordinatorService(c *router.Context, next router.Handler) {
- c.Context = WithServices(c.Context, &prodServicesInst{})
+ c.Context = WithServices(c.Context, &prodServicesInst{
+ req: c.Request,
+ })
next(c)
}
@@ -97,6 +101,10 @@ func ProdCoordinatorService(c *router.Context, next router.Handler) {
type prodServicesInst struct {
sync.Mutex
+ // req is the request that is being serviced. This is populated when the
+ // service is installed via ProdCoordinatorService.
+ req *http.Request
+
// gcfg is the cached global configuration.
gcfg *config.Config
projectConfigs map[luciConfig.ProjectName]*cachedProjectConfig
@@ -331,9 +339,12 @@ func (s *prodServicesInst) ArchivalPublisher(c context.Context) (ArchivalPublish
log.WithError(err).Errorf(c, "Failed to create Pub/Sub credentials.")
return nil, errors.New("failed to create Pub/Sub credentials")
}
- // Don't pass gRPC metadata to PubSub.
- psClient, err := gcps.NewClient(
- metadata.NewContext(c, nil), project,
+
+ // Create a new AppEngine context. Don't pass gRPC metadata to PubSub, since
+ // we don't want any caller RPC to be forwarded to the backend service.
+ aeCtx := appengine.WithContext(metadata.NewContext(c, nil), s.req)
+
+ psClient, err := gcps.NewClient(aeCtx, project,
option.WithGRPCDialOption(grpc.WithPerRPCCredentials(creds)))
if err != nil {
log.WithError(err).Errorf(c, "Failed to create Pub/Sub client.")
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698