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

Unified Diff: client/cmd/isolate/exp_archive.go

Issue 2989173002: isolate: pull exparchive and archive into functions with similar signatures. (Closed)
Patch Set: Created 3 years, 5 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
« client/cmd/isolate/archive.go ('K') | « client/cmd/isolate/archive.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/cmd/isolate/exp_archive.go
diff --git a/client/cmd/isolate/exp_archive.go b/client/cmd/isolate/exp_archive.go
index 78cbc2f3266b410a0d9ab1dcda3571f845c3188b..7b907f4f570f90b3e8077cc193db773804928b91 100644
--- a/client/cmd/isolate/exp_archive.go
+++ b/client/cmd/isolate/exp_archive.go
@@ -27,6 +27,7 @@ import (
"github.com/maruel/subcommands"
"golang.org/x/net/context"
+ "github.com/luci/luci-go/client/isolate"
"github.com/luci/luci-go/common/auth"
logpb "github.com/luci/luci-go/common/eventlog/proto"
"github.com/luci/luci-go/common/isolated"
@@ -89,6 +90,25 @@ func (c *expArchiveRun) main() error {
}
client := isolatedclient.New(nil, authCl, c.isolatedFlags.ServerURL, c.isolatedFlags.Namespace, nil, nil)
+ eventlogger := NewLogger(ctx, c.loggingFlags.EventlogEndpoint)
+
+ archiveDetails, err := doExpArchive(ctx, client, archiveOpts, c.dumpJSON)
+ if err != nil {
+ return err
+ }
+ end := time.Now()
+
+ op := logpb.IsolateClientEvent_ARCHIVE.Enum()
+ if err := eventlogger.logStats(ctx, op, start, end, archiveDetails); err != nil {
+ log.Printf("Failed to log to eventlog: %v", err)
+ }
+
+ return nil
+}
+
+// doExparchive performs the exparchive operation for an isolate specified by archiveOpts.
+// dumpJSON is the path to write a JSON summary of the uploaded isolate, in the same format as batch_archive.
+func doExpArchive(ctx context.Context, client *isolatedclient.Client, archiveOpts *isolate.ArchiveOptions, dumpJSON string) (*logpb.IsolateClientEvent_ArchiveDetails, error) {
// Set up a checker and uploader. We limit the uploader to one concurrent
// upload, since the uploads are all coming from disk (with the exception of
// the isolated JSON itself) and we only want a single goroutine reading from
@@ -98,29 +118,30 @@ func (c *expArchiveRun) main() error {
archiver := NewTarringArchiver(checker, uploader)
isolSummary, err := archiver.Archive(archiveOpts)
+ if err != nil {
+ return nil, err
+ }
// Make sure that all pending items have been checked.
if err := checker.Close(); err != nil {
- return err
+ return nil, err
}
// Make sure that all the uploads have completed successfully.
if err := uploader.Close(); err != nil {
- return err
+ return nil, err
}
printSummary(isolSummary)
- if c.dumpJSON != "" {
- f, err := os.OpenFile(c.dumpJSON, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
+ if dumpJSON != "" {
+ f, err := os.OpenFile(dumpJSON, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
- return err
+ return nil, err
}
writeSummaryJSON(f, isolSummary)
f.Close()
}
- end := time.Now()
-
archiveDetails := &logpb.IsolateClientEvent_ArchiveDetails{
HitCount: proto.Int64(int64(checker.Hit.Count)),
MissCount: proto.Int64(int64(checker.Miss.Count)),
@@ -128,13 +149,7 @@ func (c *expArchiveRun) main() error {
MissBytes: &checker.Miss.Bytes,
IsolateHash: []string{string(isolSummary.Digest)},
}
- eventlogger := NewLogger(ctx, c.loggingFlags.EventlogEndpoint)
- op := logpb.IsolateClientEvent_ARCHIVE.Enum()
- if err := eventlogger.logStats(ctx, op, start, end, archiveDetails); err != nil {
- log.Printf("Failed to log to eventlog: %v", err)
- }
-
- return nil
+ return archiveDetails, nil
}
func writeSummaryJSON(w io.Writer, summaries ...IsolatedSummary) error {
« client/cmd/isolate/archive.go ('K') | « client/cmd/isolate/archive.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698