github.com/distbuild/reclient@v0.0.0-20240401075343-3de72e395564/cmd/downloadmismatch/main.go (about) 1 // Copyright 2023 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // The tool to download compare build mismatches given the rbe stats file. 16 // After a compare build that contains mismatches, we can run the tool like this: 17 // ``` 18 // downloadmismatch --diff --proxy_log_dir=/tmp --mismatch_output_dir=/tmp 19 // ``` 20 // downloadmismatch binary will download the mismatch outputs according to 21 // /tmp/rbe_metrics.pb, extract the readable strings, and diff the strings. The 22 // outputs will be dumped to /tmp(the `mismatch_output_dir`) structured as follow: 23 // /tmp 24 // |reclient_mismatches 25 // |#ActionHash 26 // |output_file_path_of_one_mismatch 27 // |local 28 // |#LocalOutputRetry1 29 // |#LocalOutputRetry1.strings 30 // |remote 31 // |#RemoteOutputRetry1 32 // |#RemoteOutputRetry1.strings 33 // |#RemoteOutputRetry2 34 // |#RemoteOutputRetry2.strings 35 // |compare_action.diff 36 // ... 37 38 package main 39 40 import ( 41 "context" 42 "flag" 43 "log" 44 "path/filepath" 45 46 "github.com/bazelbuild/reclient/internal/pkg/downloadmismatch" 47 "github.com/bazelbuild/reclient/internal/pkg/rbeflag" 48 49 rflags "github.com/bazelbuild/remote-apis-sdks/go/pkg/flags" 50 ) 51 52 const ( 53 defaultLogDir = "/tmp" 54 ) 55 56 var ( 57 proxyLogDir = flag.String("proxy_log_dir", defaultLogDir, "The directory that stores the reproxy mismatch stats file(such as rbe_metrics.pb), the default is /tmp") 58 outputDir = flag.String("mismatch_output_dir", defaultLogDir, "The directory to store the downloaded mismatch outputs, the default is /tmp") 59 doDiff = flag.Bool("diff", true, "extract readable string content from local/remote output and generate #mismatch_output_dir/#actionHash/compare_build.diff") 60 ) 61 62 func main() { 63 rbeflag.Parse() 64 rbeflag.LogAllFlags(0) 65 66 grpcClient, err := rflags.NewClientFromFlags(context.Background()) 67 if err != nil { 68 log.Fatalf("error connecting to remote execution client: %v", err) 69 } 70 if err := downloadmismatch.DownloadMismatches(*proxyLogDir, *outputDir, grpcClient); err != nil { 71 log.Fatalf("DownloadMismatches encountered fatal error: %v", err) 72 } 73 if *doDiff { 74 err := downloadmismatch.DiffOutputDir(filepath.Join(*outputDir, downloadmismatch.DownloadDir)) 75 if err != nil { 76 log.Fatal(err) 77 } 78 } 79 }