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 bigtable | 5 package bigtable |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "errors" | 9 "errors" |
10 "fmt" | 10 "fmt" |
11 | 11 |
12 "github.com/luci/luci-go/common/config" | 12 "github.com/luci/luci-go/common/config" |
13 "github.com/luci/luci-go/common/data/recordio" | 13 "github.com/luci/luci-go/common/data/recordio" |
14 log "github.com/luci/luci-go/common/logging" | 14 log "github.com/luci/luci-go/common/logging" |
15 "github.com/luci/luci-go/logdog/common/storage" | 15 "github.com/luci/luci-go/logdog/common/storage" |
16 "github.com/luci/luci-go/logdog/common/types" | 16 "github.com/luci/luci-go/logdog/common/types" |
| 17 |
| 18 "cloud.google.com/go/bigtable" |
17 "golang.org/x/net/context" | 19 "golang.org/x/net/context" |
18 » "google.golang.org/cloud" | 20 » "google.golang.org/api/option" |
19 » "google.golang.org/cloud/bigtable" | |
20 ) | 21 ) |
21 | 22 |
22 var ( | 23 var ( |
23 // StorageScopes is the set of OAuth scopes needed to use the storage | 24 // StorageScopes is the set of OAuth scopes needed to use the storage |
24 // functionality. | 25 // functionality. |
25 StorageScopes = []string{ | 26 StorageScopes = []string{ |
26 bigtable.Scope, | 27 bigtable.Scope, |
27 } | 28 } |
28 | 29 |
29 // StorageReadOnlyScopes is the set of OAuth scopes needed to use the st
orage | 30 // StorageReadOnlyScopes is the set of OAuth scopes needed to use the st
orage |
(...skipping 25 matching lines...) Expand all Loading... |
55 ) | 56 ) |
56 | 57 |
57 // Options is a set of configuration options for BigTable storage. | 58 // Options is a set of configuration options for BigTable storage. |
58 type Options struct { | 59 type Options struct { |
59 // Project is the name of the project to connect to. | 60 // Project is the name of the project to connect to. |
60 Project string | 61 Project string |
61 // Instance is the name of the instance to connect to. | 62 // Instance is the name of the instance to connect to. |
62 Instance string | 63 Instance string |
63 // ClientOptions are additional client options to use when instantiating
the | 64 // ClientOptions are additional client options to use when instantiating
the |
64 // client instance. | 65 // client instance. |
65 » ClientOptions []cloud.ClientOption | 66 » ClientOptions []option.ClientOption |
66 | 67 |
67 // Table is the name of the BigTable table to use for logs. | 68 // Table is the name of the BigTable table to use for logs. |
68 LogTable string | 69 LogTable string |
69 } | 70 } |
70 | 71 |
71 func (o *Options) client(ctx context.Context) (*bigtable.Client, error) { | 72 func (o *Options) client(ctx context.Context) (*bigtable.Client, error) { |
72 return bigtable.NewClient(ctx, o.Project, o.Instance, o.ClientOptions...
) | 73 return bigtable.NewClient(ctx, o.Project, o.Instance, o.ClientOptions...
) |
73 } | 74 } |
74 | 75 |
75 func (o *Options) adminClient(ctx context.Context) (*bigtable.AdminClient, error
) { | 76 func (o *Options) adminClient(ctx context.Context) (*bigtable.AdminClient, error
) { |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 }.Debugf(ctx, "Adding entries to BigTable.") | 401 }.Debugf(ctx, "Adding entries to BigTable.") |
401 if err := raw.putLogData(ctx, rk, w.buf.Bytes()); err != nil { | 402 if err := raw.putLogData(ctx, rk, w.buf.Bytes()); err != nil { |
402 return 0, err | 403 return 0, err |
403 } | 404 } |
404 | 405 |
405 // Reset our buffer state. | 406 // Reset our buffer state. |
406 w.buf.Reset() | 407 w.buf.Reset() |
407 w.count = 0 | 408 w.count = 0 |
408 return flushCount, nil | 409 return flushCount, nil |
409 } | 410 } |
OLD | NEW |