| 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 pubsub | 5 package pubsub |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "errors" | 9 "errors" |
| 10 "fmt" | 10 "fmt" |
| 11 "sync" | 11 "sync" |
| 12 "time" | 12 "time" |
| 13 | 13 |
| 14 "cloud.google.com/go/pubsub" | 14 "cloud.google.com/go/pubsub" |
| 15 "github.com/luci/luci-go/common/data/recordio" | 15 "github.com/luci/luci-go/common/data/recordio" |
| 16 gcps "github.com/luci/luci-go/common/gcloud/pubsub" | 16 gcps "github.com/luci/luci-go/common/gcloud/pubsub" |
| 17 log "github.com/luci/luci-go/common/logging" | 17 log "github.com/luci/luci-go/common/logging" |
| 18 "github.com/luci/luci-go/common/retry" | 18 "github.com/luci/luci-go/common/retry" |
| 19 "github.com/luci/luci-go/logdog/api/logpb" | 19 "github.com/luci/luci-go/logdog/api/logpb" |
| 20 "github.com/luci/luci-go/logdog/client/butler/output" | 20 "github.com/luci/luci-go/logdog/client/butler/output" |
| 21 "github.com/luci/luci-go/logdog/client/butlerproto" | 21 "github.com/luci/luci-go/logdog/client/butlerproto" |
| 22 "github.com/luci/luci-go/logdog/common/types" | 22 "github.com/luci/luci-go/logdog/common/types" |
| 23 "golang.org/x/net/context" | 23 "golang.org/x/net/context" |
| 24 ) | 24 ) |
| 25 | 25 |
| 26 // Topic is an interface for a Pub/Sub topic. | 26 // Topic is an interface for a Pub/Sub topic. |
| 27 // | 27 // |
| 28 // pubsub.Topic implements Topic. | 28 // pubsub.Topic implements Topic. |
| 29 type Topic interface { | 29 type Topic interface { |
| 30 » // Name returns the name of the topic. | 30 » // String returns the name of the topic. |
| 31 » Name() string | 31 » String() string |
| 32 | 32 |
| 33 // Publish mirrors the pubsub.Connection Publish method. | 33 // Publish mirrors the pubsub.Connection Publish method. |
| 34 Publish(context.Context, ...*pubsub.Message) ([]string, error) | 34 Publish(context.Context, ...*pubsub.Message) ([]string, error) |
| 35 } | 35 } |
| 36 | 36 |
| 37 var _ Topic = (*pubsub.Topic)(nil) | 37 var _ Topic = (*pubsub.Topic)(nil) |
| 38 | 38 |
| 39 // Config is a configuration structure for Pub/Sub output. | 39 // Config is a configuration structure for Pub/Sub output. |
| 40 type Config struct { | 40 type Config struct { |
| 41 // Topic is the Pub/Sub topic to publish to. | 41 // Topic is the Pub/Sub topic to publish to. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 if c.Track { | 84 if c.Track { |
| 85 o.et = &output.EntryTracker{} | 85 o.et = &output.EntryTracker{} |
| 86 } | 86 } |
| 87 | 87 |
| 88 o.Context = log.SetField(ctx, "pubsub", &o) | 88 o.Context = log.SetField(ctx, "pubsub", &o) |
| 89 return &o | 89 return &o |
| 90 } | 90 } |
| 91 | 91 |
| 92 func (o *pubSubOutput) String() string { | 92 func (o *pubSubOutput) String() string { |
| 93 » return fmt.Sprintf("pubsub(%s)", o.Topic.Name()) | 93 » return fmt.Sprintf("pubsub(%s)", o.Topic.String()) |
| 94 } | 94 } |
| 95 | 95 |
| 96 func (o *pubSubOutput) SendBundle(bundle *logpb.ButlerLogBundle) error { | 96 func (o *pubSubOutput) SendBundle(bundle *logpb.ButlerLogBundle) error { |
| 97 st := output.StatsBase{} | 97 st := output.StatsBase{} |
| 98 defer o.mergeStats(&st) | 98 defer o.mergeStats(&st) |
| 99 | 99 |
| 100 b := o.bufferPool.Get().(*buffer) | 100 b := o.bufferPool.Get().(*buffer) |
| 101 defer o.bufferPool.Put(b) | 101 defer o.bufferPool.Put(b) |
| 102 | 102 |
| 103 bundle.Secret = []byte(o.Secret) | 103 bundle.Secret = []byte(o.Secret) |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 // indefiniteRetry is a retry.Iterator that will indefinitely retry errors with | 220 // indefiniteRetry is a retry.Iterator that will indefinitely retry errors with |
| 221 // a maximum backoff. | 221 // a maximum backoff. |
| 222 func indefiniteRetry() retry.Iterator { | 222 func indefiniteRetry() retry.Iterator { |
| 223 return &retry.ExponentialBackoff{ | 223 return &retry.ExponentialBackoff{ |
| 224 Limited: retry.Limited{ | 224 Limited: retry.Limited{ |
| 225 Retries: -1, | 225 Retries: -1, |
| 226 }, | 226 }, |
| 227 MaxDelay: 30 * time.Second, | 227 MaxDelay: 30 * time.Second, |
| 228 } | 228 } |
| 229 } | 229 } |
| OLD | NEW |