Skip to content

Commit dc4e40c

Browse files
committed
pkg/cli (debug-zip): add dry-run mode for debug zip uploads
Introduce a `--dry-run` flag to the debug zip upload command. This allows us to simulate the upload process without performing actual uploads. The dry-run mode is used only for debugging/testing. This flag is hidden from the help text Release note: None
1 parent db7f5f4 commit dc4e40c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pkg/cli/debug.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,9 @@ func init() {
15741574
f.Lookup("log-format").Hidden = true
15751575
f.StringVar(&debugZipUploadOpts.gcpProjectID, "gcp-project-id",
15761576
defaultGCPProjectID, "GCP project ID to use to send debug.zip logs to GCS")
1577+
// --dry-run is a hidden flag that is only meant to be used for testing and diagnostics
1578+
f.BoolVar(&debugZipUploadOpts.dryRun, "dry-run", false, "run in dry-run mode without making any actual uploads")
1579+
f.Lookup("dry-run").Hidden = true
15771580

15781581
f = debugDecodeKeyCmd.Flags()
15791582
f.Var(&decodeKeyOptions.encoding, "encoding", "key argument encoding")

pkg/cli/zip_upload.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ var debugZipUploadOpts = struct {
124124
from, to timestampValue
125125
logFormat string
126126
maxConcurrentUploads int
127+
dryRun bool
127128
}{
128129
maxConcurrentUploads: system.NumCPU() * 4,
129130
}
@@ -217,6 +218,10 @@ func runDebugZipUpload(cmd *cobra.Command, args []string) error {
217218
artifactsToUpload = debugZipUploadOpts.include
218219
}
219220

221+
if debugZipUploadOpts.dryRun {
222+
fmt.Println("DRY RUN MODE: No actual uploads will be performed")
223+
}
224+
220225
// run the upload functions for each artifact type. This can run sequentially.
221226
// All the concurrency is contained within the upload functions.
222227
for _, artType := range artifactsToUpload {
@@ -238,6 +243,10 @@ func validateZipUploadReadiness() error {
238243
artifactsToUpload = zipArtifactTypes
239244
)
240245

246+
if debugZipUploadOpts.dryRun {
247+
return nil
248+
}
249+
241250
if len(debugZipUploadOpts.include) > 0 {
242251
artifactsToUpload = debugZipUploadOpts.include
243252
}
@@ -896,6 +905,11 @@ func startWriterPool(
896905
// writing to GCS. The concurrency has to be handled by the caller.
897906
// This function implements the logUploadFunc signature.
898907
var gcsLogUpload = func(ctx context.Context, sig logUploadSig) (int, error) {
908+
data := bytes.Join(sig.logLines, []byte("\n"))
909+
if debugZipUploadOpts.dryRun {
910+
return len(data), nil
911+
}
912+
899913
gcsClient, closeGCSClient, err := newGCSClient(ctx)
900914
if err != nil {
901915
return 0, err
@@ -910,7 +924,6 @@ var gcsLogUpload = func(ctx context.Context, sig logUploadSig) (int, error) {
910924
retryOpts := base.DefaultRetryOptions()
911925
retryOpts.MaxRetries = zipUploadRetries
912926

913-
data := bytes.Join(sig.logLines, []byte("\n"))
914927
for retry := retry.Start(retryOpts); retry.Next(); {
915928
objectWriter := gcsClient.Bucket(ddArchiveBucketName).Object(filename).NewWriter(ctx)
916929
w := gzip.NewWriter(objectWriter)
@@ -1137,6 +1150,10 @@ func makeDDTag(key, value string) string {
11371150
// There is also some error handling logic in this function. This is a variable so that
11381151
// we can mock this function in the tests.
11391152
var doUploadReq = func(req *http.Request) ([]byte, error) {
1153+
if debugZipUploadOpts.dryRun {
1154+
return []byte("{}"), nil
1155+
}
1156+
11401157
resp, err := http.DefaultClient.Do(req)
11411158
if err != nil {
11421159
return nil, err

0 commit comments

Comments
 (0)