| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 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 main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "time" | 9 "time" |
| 10 | 10 |
| 11 "github.com/luci/luci-go/common/auth" | 11 "github.com/luci/luci-go/common/auth" |
| 12 "github.com/luci/luci-go/common/clock" | 12 "github.com/luci/luci-go/common/clock" |
| 13 "github.com/luci/luci-go/common/errors" | 13 "github.com/luci/luci-go/common/errors" |
| 14 gcps "github.com/luci/luci-go/common/gcloud/pubsub" | 14 gcps "github.com/luci/luci-go/common/gcloud/pubsub" |
| 15 log "github.com/luci/luci-go/common/logging" | 15 log "github.com/luci/luci-go/common/logging" |
| 16 "github.com/luci/luci-go/common/sync/parallel" | 16 "github.com/luci/luci-go/common/sync/parallel" |
| 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 "github.com/luci/luci-go/common/tsmon/types" |
| 21 "github.com/luci/luci-go/logdog/server/collector" | 21 "github.com/luci/luci-go/logdog/server/collector" |
| 22 "github.com/luci/luci-go/logdog/server/collector/coordinator" | 22 "github.com/luci/luci-go/logdog/server/collector/coordinator" |
| 23 "github.com/luci/luci-go/logdog/server/service" | 23 "github.com/luci/luci-go/logdog/server/service" |
| 24 "golang.org/x/net/context" | 24 "golang.org/x/net/context" |
| 25 » "google.golang.org/cloud" | 25 |
| 26 » "google.golang.org/cloud/pubsub" | 26 » "cloud.google.com/go/pubsub" |
| 27 » "google.golang.org/api/option" |
| 27 ) | 28 ) |
| 28 | 29 |
| 29 var ( | 30 var ( |
| 30 errInvalidConfig = errors.New("invalid configuration") | 31 errInvalidConfig = errors.New("invalid configuration") |
| 31 ) | 32 ) |
| 32 | 33 |
| 33 const ( | 34 const ( |
| 34 pubsubPullErrorDelay = 10 * time.Second | 35 pubsubPullErrorDelay = 10 * time.Second |
| 35 ) | 36 ) |
| 36 | 37 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 81 |
| 81 // New PubSub instance with the authenticated client. | 82 // New PubSub instance with the authenticated client. |
| 82 psAuth, err := a.Authenticator(c, func(o *auth.Options) { | 83 psAuth, err := a.Authenticator(c, func(o *auth.Options) { |
| 83 o.Scopes = gcps.SubscriberScopes | 84 o.Scopes = gcps.SubscriberScopes |
| 84 }) | 85 }) |
| 85 if err != nil { | 86 if err != nil { |
| 86 log.WithError(err).Errorf(c, "Failed to create Pub/Sub token sou
rce.") | 87 log.WithError(err).Errorf(c, "Failed to create Pub/Sub token sou
rce.") |
| 87 return err | 88 return err |
| 88 } | 89 } |
| 89 | 90 |
| 90 » psClient, err := pubsub.NewClient(c, pscfg.Project, cloud.WithTokenSourc
e(psAuth.TokenSource())) | 91 » psClient, err := pubsub.NewClient(c, pscfg.Project, option.WithTokenSour
ce(psAuth.TokenSource())) |
| 91 if err != nil { | 92 if err != nil { |
| 92 log.Fields{ | 93 log.Fields{ |
| 93 log.ErrorKey: err, | 94 log.ErrorKey: err, |
| 94 "subscription": sub, | 95 "subscription": sub, |
| 95 }.Errorf(c, "Failed to create Pub/Sub client.") | 96 }.Errorf(c, "Failed to create Pub/Sub client.") |
| 96 return err | 97 return err |
| 97 } | 98 } |
| 98 | 99 |
| 99 psSub := psClient.Subscription(pscfg.Subscription) | 100 psSub := psClient.Subscription(pscfg.Subscription) |
| 100 exists, err := psSub.Exists(c) | 101 exists, err := psSub.Exists(c) |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 224 |
| 224 // Entry point. | 225 // Entry point. |
| 225 func main() { | 226 func main() { |
| 226 a := application{ | 227 a := application{ |
| 227 Service: service.Service{ | 228 Service: service.Service{ |
| 228 Name: "collector", | 229 Name: "collector", |
| 229 }, | 230 }, |
| 230 } | 231 } |
| 231 a.Run(context.Background(), a.runCollector) | 232 a.Run(context.Background(), a.runCollector) |
| 232 } | 233 } |
| OLD | NEW |