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

Side by Side Diff: client/cmd/isolate/archive.go

Issue 2918043003: Log eventlogs from legacy isolate archive command (Closed)
Patch Set: Address review comments Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | client/cmd/isolate/exp_archive.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 main 5 package main
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "fmt" 9 "fmt"
10 "log"
10 "os" 11 "os"
11 "path/filepath" 12 "path/filepath"
12 "time" 13 "time"
13 14
15 "github.com/golang/protobuf/proto"
14 "github.com/maruel/subcommands" 16 "github.com/maruel/subcommands"
15 17
16 "github.com/luci/luci-go/client/archiver" 18 "github.com/luci/luci-go/client/archiver"
17 "github.com/luci/luci-go/client/internal/common" 19 "github.com/luci/luci-go/client/internal/common"
18 "github.com/luci/luci-go/client/isolate" 20 "github.com/luci/luci-go/client/isolate"
19 "github.com/luci/luci-go/common/auth" 21 "github.com/luci/luci-go/common/auth"
20 "github.com/luci/luci-go/common/data/text/units" 22 "github.com/luci/luci-go/common/data/text/units"
23 logpb "github.com/luci/luci-go/common/eventlog/proto"
21 "github.com/luci/luci-go/common/isolatedclient" 24 "github.com/luci/luci-go/common/isolatedclient"
22 ) 25 )
23 26
24 func cmdArchive(defaultAuthOpts auth.Options) *subcommands.Command { 27 func cmdArchive(defaultAuthOpts auth.Options) *subcommands.Command {
25 return &subcommands.Command{ 28 return &subcommands.Command{
26 UsageLine: "archive <options>", 29 UsageLine: "archive <options>",
27 ShortDesc: "creates a .isolated file and uploads the tree to an isolate server.", 30 ShortDesc: "creates a .isolated file and uploads the tree to an isolate server.",
28 LongDesc: "All the files listed in the .isolated file are put i n the isolate server cache", 31 LongDesc: "All the files listed in the .isolated file are put i n the isolate server cache",
29 CommandRun: func() subcommands.CommandRun { 32 CommandRun: func() subcommands.CommandRun {
30 c := archiveRun{} 33 c := archiveRun{}
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 item := isolate.Archive(arch, &c.ArchiveOptions) 77 item := isolate.Archive(arch, &c.ArchiveOptions)
75 item.WaitForHashed() 78 item.WaitForHashed()
76 if err = item.Error(); err != nil { 79 if err = item.Error(); err != nil {
77 fmt.Printf("%s%s %s\n", prefix, filepath.Base(c.Isolate), err) 80 fmt.Printf("%s%s %s\n", prefix, filepath.Base(c.Isolate), err)
78 } else { 81 } else {
79 fmt.Printf("%s%s %s\n", prefix, item.Digest(), filepath.Base(c. Isolate)) 82 fmt.Printf("%s%s %s\n", prefix, item.Digest(), filepath.Base(c. Isolate))
80 } 83 }
81 if err2 := arch.Close(); err == nil { 84 if err2 := arch.Close(); err == nil {
82 err = err2 85 err = err2
83 } 86 }
87 stats := arch.Stats()
84 if !c.defaultFlags.Quiet { 88 if !c.defaultFlags.Quiet {
85 duration := time.Since(start) 89 duration := time.Since(start)
86 stats := arch.Stats()
87 fmt.Fprintf(os.Stderr, "Hits : %5d (%s)\n", stats.TotalHits() , stats.TotalBytesHits()) 90 fmt.Fprintf(os.Stderr, "Hits : %5d (%s)\n", stats.TotalHits() , stats.TotalBytesHits())
88 fmt.Fprintf(os.Stderr, "Misses : %5d (%s)\n", stats.TotalMisses (), stats.TotalBytesPushed()) 91 fmt.Fprintf(os.Stderr, "Misses : %5d (%s)\n", stats.TotalMisses (), stats.TotalBytesPushed())
89 fmt.Fprintf(os.Stderr, "Duration: %s\n", units.Round(duration, t ime.Millisecond)) 92 fmt.Fprintf(os.Stderr, "Duration: %s\n", units.Round(duration, t ime.Millisecond))
90 } 93 }
94
95 end := time.Now()
96
97 archiveDetails := &logpb.IsolateClientEvent_ArchiveDetails{
98 HitCount: proto.Int64(int64(stats.TotalHits())),
99 MissCount: proto.Int64(int64(stats.TotalMisses())),
100 HitBytes: proto.Int64(int64(stats.TotalBytesHits())),
101 MissBytes: proto.Int64(int64(stats.TotalBytesPushed())),
102 }
103 if item.Error() != nil {
104 archiveDetails.IsolateHash = []string{string(item.Digest())}
105 }
106 eventlogger := NewLogger(ctx, c.isolateFlags.EventlogEndpoint)
107 op := logpb.IsolateClientEvent_LEGACY_ARCHIVE.Enum()
108 if err := eventlogger.logStats(ctx, op, start, end, archiveDetails); err != nil {
109 log.Printf("Failed to log to eventlog: %v", err)
110 }
91 return err 111 return err
92 } 112 }
93 113
94 func (c *archiveRun) Run(a subcommands.Application, args []string, _ subcommands .Env) int { 114 func (c *archiveRun) Run(a subcommands.Application, args []string, _ subcommands .Env) int {
95 if err := c.Parse(a, args); err != nil { 115 if err := c.Parse(a, args); err != nil {
96 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) 116 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err)
97 return 1 117 return 1
98 } 118 }
99 cl, err := c.defaultFlags.StartTracing() 119 cl, err := c.defaultFlags.StartTracing()
100 if err != nil { 120 if err != nil {
101 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) 121 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err)
102 return 1 122 return 1
103 } 123 }
104 defer cl.Close() 124 defer cl.Close()
105 if err := c.main(a, args); err != nil { 125 if err := c.main(a, args); err != nil {
106 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) 126 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err)
107 return 1 127 return 1
108 } 128 }
109 return 0 129 return 0
110 } 130 }
OLDNEW
« no previous file with comments | « no previous file | client/cmd/isolate/exp_archive.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698