Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2316)

Unified Diff: appengine/logdog/coordinator/service.go

Issue 1672833003: LogDog: Add log rendering view. Base URL: https://github.com/luci/luci-go@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
+}

Powered by Google App Engine
This is Rietveld 408576698