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

Side by Side Diff: appengine/tsmon/middleware.go

Issue 1838303002: Use native Pub/Sub library primitives. (Closed) Base URL: https://github.com/luci/luci-go@logdog-go1.6
Patch Set: Use "Topic" instead of "NewTopic" ... don't want to create :) Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | client/cmd/logdog_butler/main.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package tsmon 5 package tsmon
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "net/http" 9 "net/http"
10 "strings" 10 "strings"
11 "sync" 11 "sync"
12 "time" 12 "time"
13 13
14 "github.com/golang/protobuf/proto" 14 "github.com/golang/protobuf/proto"
15 "github.com/julienschmidt/httprouter" 15 "github.com/julienschmidt/httprouter"
16 "github.com/luci/gae/service/datastore" 16 "github.com/luci/gae/service/datastore"
17 "github.com/luci/gae/service/info" 17 "github.com/luci/gae/service/info"
18 gaeauth "github.com/luci/luci-go/appengine/gaeauth/client" 18 gaeauth "github.com/luci/luci-go/appengine/gaeauth/client"
19 "github.com/luci/luci-go/common/clock" 19 "github.com/luci/luci-go/common/clock"
20 » "github.com/luci/luci-go/common/gcloud/pubsub" 20 » gcps "github.com/luci/luci-go/common/gcloud/pubsub"
21 "github.com/luci/luci-go/common/logging" 21 "github.com/luci/luci-go/common/logging"
22 "github.com/luci/luci-go/common/tsmon" 22 "github.com/luci/luci-go/common/tsmon"
23 "github.com/luci/luci-go/common/tsmon/monitor" 23 "github.com/luci/luci-go/common/tsmon/monitor"
24 "github.com/luci/luci-go/common/tsmon/store" 24 "github.com/luci/luci-go/common/tsmon/store"
25 "github.com/luci/luci-go/common/tsmon/target" 25 "github.com/luci/luci-go/common/tsmon/target"
26 "github.com/luci/luci-go/server/middleware" 26 "github.com/luci/luci-go/server/middleware"
27 "golang.org/x/net/context" 27 "golang.org/x/net/context"
28 ) 28 )
29 29
30 var ( 30 var (
(...skipping 17 matching lines...) Expand all
48 flushIfNeeded(c) 48 flushIfNeeded(c)
49 } 49 }
50 } 50 }
51 51
52 func initialize(c context.Context) error { 52 func initialize(c context.Context) error {
53 var mon monitor.Monitor 53 var mon monitor.Monitor
54 i := info.Get(c) 54 i := info.Get(c)
55 if i.IsDevAppServer() { 55 if i.IsDevAppServer() {
56 mon = monitor.NewDebugMonitor("") 56 mon = monitor.NewDebugMonitor("")
57 } else { 57 } else {
58 » » client := func(c context.Context) (*http.Client, error) { 58 » » // Create an HTTP client with the default appengine service acco unt.
59 » » » // Create an HTTP client with the default appengine serv ice account. 59 » » auth, err := gaeauth.Authenticator(c, gcps.PublisherScopes, nil)
60 » » » auth, err := gaeauth.Authenticator(c, pubsub.PublisherSc opes, nil)
61 » » » if err != nil {
62 » » » » return nil, err
63 » » » }
64 » » » return auth.Client()
65 » » }
66
67 » » var err error
68 » » mon, err = monitor.NewPubsubMonitor(client, pubsubProject, pubsu bTopic)
69 if err != nil { 60 if err != nil {
70 return err 61 return err
71 } 62 }
63 client, err := auth.Client()
64 if err != nil {
65 return err
66 }
67
68 mon, err = monitor.NewPubsubMonitor(c, client, gcps.NewTopic(pub subProject, pubsubTopic))
69 if err != nil {
70 return err
71 }
72 } 72 }
73 73
74 // Create the target. 74 // Create the target.
75 tar := &target.Task{ 75 tar := &target.Task{
76 DataCenter: proto.String(targetDataCenter), 76 DataCenter: proto.String(targetDataCenter),
77 ServiceName: proto.String(i.AppID()), 77 ServiceName: proto.String(i.AppID()),
78 JobName: proto.String(i.ModuleName()), 78 JobName: proto.String(i.ModuleName()),
79 HostName: proto.String(strings.SplitN(i.VersionID(), ".", 2)[ 0]), 79 HostName: proto.String(strings.SplitN(i.VersionID(), ".", 2)[ 0]),
80 TaskNum: proto.Int32(-1), 80 TaskNum: proto.Int32(-1),
81 } 81 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 if err := datastore.Get(c).Put(entity); err != nil { 152 if err := datastore.Get(c).Put(entity); err != nil {
153 logger.Errorf("Failed to update instance entity: %s", er r) 153 logger.Errorf("Failed to update instance entity: %s", er r)
154 } 154 }
155 }() 155 }()
156 156
157 ret := tsmon.Flush(c) 157 ret := tsmon.Flush(c)
158 158
159 <-putDone 159 <-putDone
160 return ret 160 return ret
161 } 161 }
OLDNEW
« no previous file with comments | « no previous file | client/cmd/logdog_butler/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698