| OLD | NEW |
| 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 main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "flag" | 8 "flag" |
| 9 "fmt" | 9 "fmt" |
| 10 "net/http" | 10 "net/http" |
| 11 "time" | 11 "time" |
| 12 | 12 |
| 13 "github.com/luci/luci-go/common/auth" | 13 "github.com/luci/luci-go/common/auth" |
| 14 "github.com/luci/luci-go/common/clock" | 14 "github.com/luci/luci-go/common/clock" |
| 15 "github.com/luci/luci-go/common/errors" | 15 "github.com/luci/luci-go/common/errors" |
| 16 log "github.com/luci/luci-go/common/logging" | 16 log "github.com/luci/luci-go/common/logging" |
| 17 "github.com/luci/luci-go/common/tsmon/distribution" | 17 "github.com/luci/luci-go/common/tsmon/distribution" |
| 18 "github.com/luci/luci-go/common/tsmon/field" | 18 "github.com/luci/luci-go/common/tsmon/field" |
| 19 "github.com/luci/luci-go/common/tsmon/metric" | 19 "github.com/luci/luci-go/common/tsmon/metric" |
| 20 "github.com/luci/luci-go/common/tsmon/types" |
| 20 "golang.org/x/net/context" | 21 "golang.org/x/net/context" |
| 21 "google.golang.org/cloud" | 22 "google.golang.org/cloud" |
| 22 "google.golang.org/cloud/pubsub" | 23 "google.golang.org/cloud/pubsub" |
| 23 ) | 24 ) |
| 24 | 25 |
| 25 const ( | 26 const ( |
| 26 // The maximum number of items that can be pulled from a subscription at
once. | 27 // The maximum number of items that can be pulled from a subscription at
once. |
| 27 maxSubscriptionPullSize = 100 | 28 maxSubscriptionPullSize = 100 |
| 28 ) | 29 ) |
| 29 | 30 |
| 30 var ( | 31 var ( |
| 31 // OAuth2 scopes to generate. | 32 // OAuth2 scopes to generate. |
| 32 pubsubScopes = []string{ | 33 pubsubScopes = []string{ |
| 33 pubsub.ScopePubSub, | 34 pubsub.ScopePubSub, |
| 34 auth.OAuthScopeEmail, | 35 auth.OAuthScopeEmail, |
| 35 } | 36 } |
| 36 | 37 |
| 37 // Error returned by pullAckMessages to indicate that no messages were a
vailable. | 38 // Error returned by pullAckMessages to indicate that no messages were a
vailable. |
| 38 errNoMessages = errors.New("pubsub: no messages") | 39 errNoMessages = errors.New("pubsub: no messages") |
| 39 | 40 |
| 40 messageCount = metric.NewCounter("mon_proxy/pubsub/message", | 41 messageCount = metric.NewCounter("mon_proxy/pubsub/message", |
| 41 "Count of messages pulled from pub/sub, by worker", | 42 "Count of messages pulled from pub/sub, by worker", |
| 43 types.MetricMetadata{}, |
| 42 field.Int("worker")) | 44 field.Int("worker")) |
| 43 ackCount = metric.NewCounter("mon_proxy/pubsub/ack", | 45 ackCount = metric.NewCounter("mon_proxy/pubsub/ack", |
| 44 "Count of messages Ack'd, by success/failure", | 46 "Count of messages Ack'd, by success/failure", |
| 47 types.MetricMetadata{}, |
| 45 field.String("result")) | 48 field.String("result")) |
| 46 pullDurationMetric = metric.NewCumulativeDistribution("mon_proxy/pubsub/
pull_duration", | 49 pullDurationMetric = metric.NewCumulativeDistribution("mon_proxy/pubsub/
pull_duration", |
| 47 "Time taken to Pull messages from pub/sub, in milliseconds", | 50 "Time taken to Pull messages from pub/sub, in milliseconds", |
| 51 types.MetricMetadata{Units: types.Milliseconds}, |
| 48 distribution.DefaultBucketer) | 52 distribution.DefaultBucketer) |
| 49 ackDurationMetric = metric.NewCumulativeDistribution("mon_proxy/pubsub/a
ck_duration", | 53 ackDurationMetric = metric.NewCumulativeDistribution("mon_proxy/pubsub/a
ck_duration", |
| 50 "Time taken to Ack messages to pub/sub, in milliseconds", | 54 "Time taken to Ack messages to pub/sub, in milliseconds", |
| 55 types.MetricMetadata{Units: types.Milliseconds}, |
| 51 distribution.DefaultBucketer) | 56 distribution.DefaultBucketer) |
| 52 ) | 57 ) |
| 53 | 58 |
| 54 // pubsubConfig is the set of configuration parameters for a pubsubClient. | 59 // pubsubConfig is the set of configuration parameters for a pubsubClient. |
| 55 type pubsubConfig struct { | 60 type pubsubConfig struct { |
| 56 project string // The project name. | 61 project string // The project name. |
| 57 topic string // The topic name. | 62 topic string // The topic name. |
| 58 subscription string // The subscription name. | 63 subscription string // The subscription name. |
| 59 create bool | 64 create bool |
| 60 batchSize int // The number of elements to pull from a subscription p
er batch. | 65 batchSize int // The number of elements to pull from a subscription p
er batch. |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 case nil: | 352 case nil: |
| 348 return nil | 353 return nil |
| 349 | 354 |
| 350 case context.Canceled: | 355 case context.Canceled: |
| 351 return err | 356 return err |
| 352 | 357 |
| 353 default: | 358 default: |
| 354 return errors.WrapTransient(err) | 359 return errors.WrapTransient(err) |
| 355 } | 360 } |
| 356 } | 361 } |
| OLD | NEW |