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

Side by Side Diff: common/tsmon/monitor/pubsub.go

Issue 2219023003: Update APIs to use new Google cloud paths. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Created 4 years, 4 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 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 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 monitor 5 package monitor
6 6
7 import ( 7 import (
8 "net/http" 8 "net/http"
9 9
10 "cloud.google.com/go/pubsub"
10 "github.com/golang/protobuf/proto" 11 "github.com/golang/protobuf/proto"
11 "golang.org/x/net/context" 12 "golang.org/x/net/context"
12 » "google.golang.org/cloud" 13 » "google.golang.org/api/option"
13 » "google.golang.org/cloud/pubsub"
14 14
15 gcps "github.com/luci/luci-go/common/gcloud/pubsub" 15 gcps "github.com/luci/luci-go/common/gcloud/pubsub"
16 "github.com/luci/luci-go/common/logging" 16 "github.com/luci/luci-go/common/logging"
17 "github.com/luci/luci-go/common/tsmon/types" 17 "github.com/luci/luci-go/common/tsmon/types"
18 ) 18 )
19 19
20 type pubSubMonitor struct { 20 type pubSubMonitor struct {
21 topic *pubsub.Topic 21 topic *pubsub.Topic
22 } 22 }
23 23
24 // NewPubsubMonitor returns a Monitor that sends metrics to the Cloud Pub/Sub 24 // NewPubsubMonitor returns a Monitor that sends metrics to the Cloud Pub/Sub
25 // API. 25 // API.
26 // 26 //
27 // The provided client should implement sufficient authentication to send 27 // The provided client should implement sufficient authentication to send
28 // Cloud Pub/Sub requests. 28 // Cloud Pub/Sub requests.
29 func NewPubsubMonitor(ctx context.Context, client *http.Client, topic gcps.Topic ) (Monitor, error) { 29 func NewPubsubMonitor(ctx context.Context, client *http.Client, topic gcps.Topic ) (Monitor, error) {
30 project, name := topic.Split() 30 project, name := topic.Split()
31 31
32 » psClient, err := pubsub.NewClient(ctx, project, cloud.WithBaseHTTP(clien t)) 32 » psClient, err := pubsub.NewClient(ctx, project, option.WithHTTPClient(cl ient))
33 if err != nil { 33 if err != nil {
34 return nil, err 34 return nil, err
35 } 35 }
36 36
37 return &pubSubMonitor{ 37 return &pubSubMonitor{
38 topic: psClient.Topic(name), 38 topic: psClient.Topic(name),
39 }, nil 39 }, nil
40 } 40 }
41 41
42 func (m *pubSubMonitor) ChunkSize() int { 42 func (m *pubSubMonitor) ChunkSize() int {
(...skipping 11 matching lines...) Expand all
54 } 54 }
55 55
56 ids, err := m.topic.Publish(ctx, &pubsub.Message{Data: data}) 56 ids, err := m.topic.Publish(ctx, &pubsub.Message{Data: data})
57 if err != nil { 57 if err != nil {
58 logging.Errorf(ctx, "PubSub publish error - %s", err) 58 logging.Errorf(ctx, "PubSub publish error - %s", err)
59 return err 59 return err
60 } 60 }
61 logging.Debugf(ctx, "Sent %d tsmon cells to PubSub, message id: %v", len (cells), ids) 61 logging.Debugf(ctx, "Sent %d tsmon cells to PubSub, message id: %v", len (cells), ids)
62 return nil 62 return nil
63 } 63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698