Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 576163259
  • Loading branch information
ZeekWang authored and copybara-github committed Oct 24, 2023
1 parent 80ff09b commit a557b00
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 16 deletions.
19 changes: 10 additions & 9 deletions src/devtools/rbe/casuploader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ func (f *multiStringFlag) Get() any {
var (
printVersion = flag.Bool("version", false, "Print version information")

zipPath = flag.String("zip-path", "", "Path to a .zip file to upload")
dirPath = flag.String("dir-path", "", "Path to a directory to upload")
casInstance = flag.String("cas-instance", "", "RBE instance")
casAddr = flag.String("cas-addr", "remotebuildexecution.googleapis.com:443", "RBE server addr")
serviceAccount = flag.String("service-account-json", "", "Path to JSON file with service account credentials to use.")
useADC = flag.Bool("use-adc", false, "True to use Application Default Credentials (ADC).")
dumpDigest = flag.String("dump-digest", "", "Output the digest to file")
excludeFilters multiStringFlag
zipPath = flag.String("zip-path", "", "Path to a .zip file to upload")
dirPath = flag.String("dir-path", "", "Path to a directory to upload")
casInstance = flag.String("cas-instance", "", "RBE instance")
casAddr = flag.String("cas-addr", "remotebuildexecution.googleapis.com:443", "RBE server addr")
serviceAccount = flag.String("service-account-json", "", "Path to JSON file with service account credentials to use.")
useADC = flag.Bool("use-adc", false, "True to use Application Default Credentials (ADC).")
dumpDigest = flag.String("dump-digest", "", "Output the digest to file")
dumpFileDetails = flag.String("dump-file-details", "", "Export information of all uploaded files to a file")
excludeFilters multiStringFlag
)

func checkFlags() error {
Expand Down Expand Up @@ -113,7 +114,7 @@ func main() {
defer client.Close()

var rootDigest digest.Digest
uploaderConfig := uploader.NewCommonConfig(ctx, client, excludeFilters)
uploaderConfig := uploader.NewCommonConfig(ctx, client, excludeFilters, *dumpFileDetails)
if *zipPath != "" {
zipUploader := uploader.NewZipUploader(uploaderConfig, *zipPath)
rootDigest, err = zipUploader.DoUpload()
Expand Down
42 changes: 42 additions & 0 deletions src/devtools/rbe/casuploader/uploader/dir.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package uploader

import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
"time"

log "github.com/golang/glog"
Expand Down Expand Up @@ -54,6 +57,7 @@ func (du *DirUploader) DoUpload() (digest.Digest, error) {
return digest.Digest{}, fmt.Errorf("failed to compute merkle tree: %v", err)
}
printEntriesStats(uploadEntries, "all entries in the directory")
du.exportEntriesInfo(uploadEntries)

// Check with CAS service to find out all files that do not exist remotely, and only load these
// files from local disk.
Expand Down Expand Up @@ -131,3 +135,41 @@ func printEntriesStats(entries []*uploadinfo.Entry, message string) {
log.Infof("Stats of %s. Size: %d bytes, count: %d, files: %d, blobs: %d\n",
message, size, len(entries), numFiles, numBlobs)
}

type uploadEntryInfo struct {
Path string `json:"path"`
Digest string `json:"digest"`
Size int64 `json:"size"`
}

// exportEntriesInfo outputs the information of upload entries to the file path specified in `dumpFileDetails`
func (du *DirUploader) exportEntriesInfo(entries []*uploadinfo.Entry) {
path := du.dumpFileDetails
if path == "" {
return
}
var infoList []uploadEntryInfo
for _, entry := range entries {
// Skip directories
if entry.Path == "" {
continue
}
relPath, _ := filepath.Rel(du.dirPath, entry.Path)
infoList = append(infoList, uploadEntryInfo{
Path: relPath,
Digest: entry.Digest.Hash,
Size: entry.Digest.Size,
})
}
outputContent, err := json.MarshalIndent(infoList, "", " ")
if err != nil {
log.Warningf("failed to export upload entries info: %v", err)
return
}

log.Infof("exporting file digests to %s", path)
err = ioutil.WriteFile(path, outputContent, 0644)
if err != nil {
log.Warningf("failed to export upload entries info to %s: %v", path, err)
}
}
16 changes: 9 additions & 7 deletions src/devtools/rbe/casuploader/uploader/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ type Uploader interface {

// CommonConfig is the common configurations used for all kinds of uploders
type CommonConfig struct {
ctx context.Context
client *client.Client
excludeFilters []string
ctx context.Context
client *client.Client
excludeFilters []string
dumpFileDetails string
}

// NewCommonConfig creates a common CAS uploader configuration.
func NewCommonConfig(ctx context.Context, client *client.Client, excludeFilters []string) *CommonConfig {
func NewCommonConfig(ctx context.Context, client *client.Client, excludeFilters []string, dumpFileDetails string) *CommonConfig {
return &CommonConfig{
ctx: ctx,
client: client,
excludeFilters: excludeFilters,
ctx: ctx,
client: client,
excludeFilters: excludeFilters,
dumpFileDetails: dumpFileDetails,
}
}

Expand Down

0 comments on commit a557b00

Please sign in to comment.