| 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 implements a simple CLI tool to load and interact with storage | 5 // Package main implements a simple CLI tool to load and interact with storage |
| 6 // data in Google BigTable data. | 6 // data in Google BigTable data. |
| 7 package main | 7 package main |
| 8 | 8 |
| 9 import ( | 9 import ( |
| 10 "bytes" | 10 "bytes" |
| 11 "flag" | 11 "flag" |
| 12 "io" | 12 "io" |
| 13 "os" | 13 "os" |
| 14 | 14 |
| 15 "github.com/luci/luci-go/client/authcli" | 15 "github.com/luci/luci-go/client/authcli" |
| 16 "github.com/luci/luci-go/common/auth" | 16 "github.com/luci/luci-go/common/auth" |
| 17 "github.com/luci/luci-go/common/cli" | 17 "github.com/luci/luci-go/common/cli" |
| 18 "github.com/luci/luci-go/common/config" | |
| 19 "github.com/luci/luci-go/common/errors" | 18 "github.com/luci/luci-go/common/errors" |
| 20 log "github.com/luci/luci-go/common/logging" | 19 log "github.com/luci/luci-go/common/logging" |
| 21 "github.com/luci/luci-go/common/logging/gologger" | 20 "github.com/luci/luci-go/common/logging/gologger" |
| 22 "github.com/luci/luci-go/logdog/common/storage" | 21 "github.com/luci/luci-go/logdog/common/storage" |
| 23 "github.com/luci/luci-go/logdog/common/storage/bigtable" | 22 "github.com/luci/luci-go/logdog/common/storage/bigtable" |
| 24 "github.com/luci/luci-go/logdog/common/storage/memory" | 23 "github.com/luci/luci-go/logdog/common/storage/memory" |
| 25 "github.com/luci/luci-go/logdog/common/types" | 24 "github.com/luci/luci-go/logdog/common/types" |
| 25 "github.com/luci/luci-go/luci_config/common/cfgtypes" |
| 26 | 26 |
| 27 "github.com/golang/protobuf/proto" | 27 "github.com/golang/protobuf/proto" |
| 28 "github.com/maruel/subcommands" | 28 "github.com/maruel/subcommands" |
| 29 "golang.org/x/net/context" | 29 "golang.org/x/net/context" |
| 30 "google.golang.org/api/option" | 30 "google.golang.org/api/option" |
| 31 ) | 31 ) |
| 32 | 32 |
| 33 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
| 34 // main | 34 // main |
| 35 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 renderErr(c, errors.Annotate(err).Reason("failed to create stora
ge client").Err()) | 215 renderErr(c, errors.Annotate(err).Reason("failed to create stora
ge client").Err()) |
| 216 return 1 | 216 return 1 |
| 217 } | 217 } |
| 218 defer stClient.Close() | 218 defer stClient.Close() |
| 219 | 219 |
| 220 for round := 0; round < cmd.rounds; round++ { | 220 for round := 0; round < cmd.rounds; round++ { |
| 221 log.Infof(c, "Get round %d.", round+1) | 221 log.Infof(c, "Get round %d.", round+1) |
| 222 | 222 |
| 223 var innerErr error | 223 var innerErr error |
| 224 err = stClient.Get(storage.GetRequest{ | 224 err = stClient.Get(storage.GetRequest{ |
| 225 » » » Project: config.ProjectName(cmd.project), | 225 » » » Project: cfgtypes.ProjectName(cmd.project), |
| 226 Path: types.StreamPath(cmd.path), | 226 Path: types.StreamPath(cmd.path), |
| 227 Index: types.MessageIndex(cmd.index), | 227 Index: types.MessageIndex(cmd.index), |
| 228 Limit: cmd.limit, | 228 Limit: cmd.limit, |
| 229 }, func(e *storage.Entry) bool { | 229 }, func(e *storage.Entry) bool { |
| 230 le, err := e.GetLogEntry() | 230 le, err := e.GetLogEntry() |
| 231 if err != nil { | 231 if err != nil { |
| 232 log.WithError(err).Errorf(c, "Failed to unmarsha
l log entry.") | 232 log.WithError(err).Errorf(c, "Failed to unmarsha
l log entry.") |
| 233 return false | 233 return false |
| 234 } | 234 } |
| 235 | 235 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 296 |
| 297 stClient, err := app.getBigTableClient(c) | 297 stClient, err := app.getBigTableClient(c) |
| 298 if err != nil { | 298 if err != nil { |
| 299 renderErr(c, errors.Annotate(err).Reason("failed to create stora
ge client").Err()) | 299 renderErr(c, errors.Annotate(err).Reason("failed to create stora
ge client").Err()) |
| 300 return 1 | 300 return 1 |
| 301 } | 301 } |
| 302 defer stClient.Close() | 302 defer stClient.Close() |
| 303 | 303 |
| 304 for round := 0; round < cmd.rounds; round++ { | 304 for round := 0; round < cmd.rounds; round++ { |
| 305 log.Infof(c, "Tail round %d.", round+1) | 305 log.Infof(c, "Tail round %d.", round+1) |
| 306 » » e, err := stClient.Tail(config.ProjectName(cmd.project), types.S
treamPath(cmd.path)) | 306 » » e, err := stClient.Tail(cfgtypes.ProjectName(cmd.project), types
.StreamPath(cmd.path)) |
| 307 if err != nil { | 307 if err != nil { |
| 308 renderErr(c, errors.Annotate(err).Reason("failed to tail
log entries").Err()) | 308 renderErr(c, errors.Annotate(err).Reason("failed to tail
log entries").Err()) |
| 309 return 1 | 309 return 1 |
| 310 } | 310 } |
| 311 | 311 |
| 312 if e == nil { | 312 if e == nil { |
| 313 log.Infof(c, "No log data to tail.") | 313 log.Infof(c, "No log data to tail.") |
| 314 continue | 314 continue |
| 315 } | 315 } |
| 316 | 316 |
| 317 le, err := e.GetLogEntry() | 317 le, err := e.GetLogEntry() |
| 318 if err != nil { | 318 if err != nil { |
| 319 renderErr(c, errors.Annotate(err).Reason("failed to unma
rshal log entry").Err()) | 319 renderErr(c, errors.Annotate(err).Reason("failed to unma
rshal log entry").Err()) |
| 320 return 1 | 320 return 1 |
| 321 } | 321 } |
| 322 | 322 |
| 323 log.Fields{ | 323 log.Fields{ |
| 324 "index": le.StreamIndex, | 324 "index": le.StreamIndex, |
| 325 "size": len(e.D), | 325 "size": len(e.D), |
| 326 }.Debugf(c, "Dumping tail entry.") | 326 }.Debugf(c, "Dumping tail entry.") |
| 327 if err := unmarshalAndDump(c, os.Stdout, nil, le); err != nil { | 327 if err := unmarshalAndDump(c, os.Stdout, nil, le); err != nil { |
| 328 renderErr(c, errors.Annotate(err).Reason("failed to dump
log entry").Err()) | 328 renderErr(c, errors.Annotate(err).Reason("failed to dump
log entry").Err()) |
| 329 return 1 | 329 return 1 |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 | 332 |
| 333 return 0 | 333 return 0 |
| 334 } | 334 } |
| OLD | NEW |