| Index: appengine/logdog/coordinator/service.go
|
| diff --git a/appengine/logdog/coordinator/service.go b/appengine/logdog/coordinator/service.go
|
| index 660293f369eabeb116da508156d0ac1247a5319f..475c72af03298a08f5509cd80662a50c564a581f 100644
|
| --- a/appengine/logdog/coordinator/service.go
|
| +++ b/appengine/logdog/coordinator/service.go
|
| @@ -9,6 +9,7 @@ import (
|
| "github.com/luci/luci-go/common/gcloud/gs"
|
| log "github.com/luci/luci-go/common/logging"
|
| "github.com/luci/luci-go/server/logdog/storage"
|
| + "github.com/luci/luci-go/server/logdog/storage/archive"
|
| "golang.org/x/net/context"
|
| )
|
|
|
| @@ -59,3 +60,38 @@ func (s *Service) GSClient(c context.Context) (gs.Client, error) {
|
| }
|
| return gsc, nil
|
| }
|
| +
|
| +// GetLogStreamStorage returns the Storage instance to use for a given
|
| +// LogStream. The caller is responsible for calling Close on the returned
|
| +// Storage instance if successful.
|
| +func (s *Service) GetLogStreamStorage(c context.Context, ls *LogStream) (storage.Storage, error) {
|
| + if !ls.Archived() {
|
| + log.Debugf(c, "Log is not archived. Fetching from intermediate storage.")
|
| +
|
| + // Logs are not archived. Fetch from intermediate storage.
|
| + return s.Storage(c)
|
| + }
|
| +
|
| + log.Debugf(c, "Log is archived. Fetching from archive storage.")
|
| + gs, err := s.GSClient(c)
|
| + if err != nil {
|
| + log.WithError(err).Errorf(c, "Failed to create Google Storage client.")
|
| + return nil, err
|
| + }
|
| + defer func() {
|
| + if err := gs.Close(); err != nil {
|
| + log.WithError(err).Warningf(c, "Failed to close Google Storage client.")
|
| + }
|
| + }()
|
| +
|
| + st, err := archive.New(c, archive.Options{
|
| + IndexURL: ls.ArchiveIndexURL,
|
| + StreamURL: ls.ArchiveStreamURL,
|
| + Client: gs,
|
| + })
|
| + if err != nil {
|
| + log.WithError(err).Errorf(c, "Failed to create Google Storage storage instance.")
|
| + return nil, err
|
| + }
|
| + return st, nil
|
| +}
|
|
|