| OLD | NEW |
| 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 Loading... |
| 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 } |
| OLD | NEW |