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

Side by Side Diff: common/tsmon/iface.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 | « common/gcloud/pubsub/subscriber/subscriber_test.go ('k') | common/tsmon/monitor/pubsub.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "net/url" 10 "net/url"
11 "strings" 11 "strings"
12 12
13 "golang.org/x/net/context" 13 "golang.org/x/net/context"
14 14
15 "github.com/luci/luci-go/common/auth" 15 "github.com/luci/luci-go/common/auth"
16 » "github.com/luci/luci-go/common/gcloud/pubsub" 16 » gcps "github.com/luci/luci-go/common/gcloud/pubsub"
17 "github.com/luci/luci-go/common/logging" 17 "github.com/luci/luci-go/common/logging"
18 "github.com/luci/luci-go/common/tsmon/monitor" 18 "github.com/luci/luci-go/common/tsmon/monitor"
19 "github.com/luci/luci-go/common/tsmon/store" 19 "github.com/luci/luci-go/common/tsmon/store"
20 "github.com/luci/luci-go/common/tsmon/target" 20 "github.com/luci/luci-go/common/tsmon/target"
21 "github.com/luci/luci-go/common/tsmon/types" 21 "github.com/luci/luci-go/common/tsmon/types"
22 ) 22 )
23 23
24 // Store returns the global metric store that contains all the metric values for 24 // Store returns the global metric store that contains all the metric values for
25 // this process. Applications shouldn't need to access this directly - instead 25 // this process. Applications shouldn't need to access this directly - instead
26 // use the metric objects which provide type-safe accessors. 26 // use the metric objects which provide type-safe accessors.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 endpointURL, err := url.Parse(config.Endpoint) 202 endpointURL, err := url.Parse(config.Endpoint)
203 if err != nil { 203 if err != nil {
204 return nil, err 204 return nil, err
205 } 205 }
206 206
207 switch endpointURL.Scheme { 207 switch endpointURL.Scheme {
208 case "file": 208 case "file":
209 return monitor.NewDebugMonitor(endpointURL.Path), nil 209 return monitor.NewDebugMonitor(endpointURL.Path), nil
210 case "pubsub": 210 case "pubsub":
211 » » client := clientFactory(config.Credentials) 211 » » client, err := clientFactory(c, config.Credentials)
212 » » return monitor.NewPubsubMonitor(client, endpointURL.Host, string s.TrimPrefix(endpointURL.Path, "/")) 212 » » if err != nil {
213 » » » return nil, err
214 » » }
215
216 » » return monitor.NewPubsubMonitor(c, client, gcps.NewTopic(endpoin tURL.Host, strings.TrimPrefix(endpointURL.Path, "/")))
213 default: 217 default:
214 return nil, fmt.Errorf("unknown tsmon endpoint url: %s", config. Endpoint) 218 return nil, fmt.Errorf("unknown tsmon endpoint url: %s", config. Endpoint)
215 } 219 }
216 } 220 }
217 221
218 // makeClient returns http.Client that knows how to send authenticated requests 222 // makeClient returns http.Client that knows how to send authenticated requests
219 // to PubSub API. 223 // to PubSub API.
220 func clientFactory(credentials string) monitor.ClientFactory { 224 func clientFactory(ctx context.Context, credentials string) (*http.Client, error ) {
221 » return func(ctx context.Context) (*http.Client, error) { 225 » authOpts := auth.Options{
222 » » authOpts := auth.Options{ 226 » » Context: ctx,
223 » » » Context: ctx, 227 » » Scopes: gcps.PublisherScopes,
224 » » » Scopes: pubsub.PublisherScopes,
225 » » }
226 » » if credentials == GCECredentials {
227 » » » authOpts.Method = auth.GCEMetadataMethod
228 » » } else {
229 » » » authOpts.Method = auth.ServiceAccountMethod
230 » » » authOpts.ServiceAccountJSONPath = credentials
231 » » }
232 » » return auth.NewAuthenticator(auth.SilentLogin, authOpts).Client( )
233 } 228 }
229 if credentials == GCECredentials {
230 authOpts.Method = auth.GCEMetadataMethod
231 } else {
232 authOpts.Method = auth.ServiceAccountMethod
233 authOpts.ServiceAccountJSONPath = credentials
234 }
235 return auth.NewAuthenticator(auth.SilentLogin, authOpts).Client()
234 } 236 }
OLDNEW
« no previous file with comments | « common/gcloud/pubsub/subscriber/subscriber_test.go ('k') | common/tsmon/monitor/pubsub.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698