Skip to content

Commit

Permalink
Merge pull request #10 from parca-dev/debug
Browse files Browse the repository at this point in the history
Add debug logging around uploads
  • Loading branch information
brancz authored Dec 15, 2022
2 parents 1c50472 + 9abaf42 commit 498b6b5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/parca-debuginfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ import (
"google.golang.org/grpc/credentials/insecure"
)

const (
LogLevelDebug = "debug"
)

type flags struct {
LogLevel string `kong:"enum='error,warn,info,debug',help='Log level.',default='info'"`

Expand Down Expand Up @@ -198,10 +202,20 @@ func run(kongCtx *kong.Context, flags flags) error {
return fmt.Errorf("initiate upload for %q with Build ID %q: %w", upload.path, upload.buildID, err)
}

if flags.LogLevel == LogLevelDebug {
fmt.Fprintf(os.Stdout, "Upload instructions\nBuildID: %s\nUploadID: %s\nUploadStrategy: %s\nSignedURL: %s\n", initiationResp.UploadInstructions.BuildId, initiationResp.UploadInstructions.UploadId, initiationResp.UploadInstructions.UploadStrategy.String(), initiationResp.UploadInstructions.SignedUrl)
}

switch initiationResp.UploadInstructions.UploadStrategy {
case debuginfopb.UploadInstructions_UPLOAD_STRATEGY_GRPC:
if flags.LogLevel == LogLevelDebug {
fmt.Fprintf(os.Stdout, "Performing a gRPC upload for %q with Build ID %q.", upload.path, upload.buildID)
}
_, err = grpcUploadClient.Upload(ctx, initiationResp.UploadInstructions, upload.reader)
case debuginfopb.UploadInstructions_UPLOAD_STRATEGY_SIGNED_URL:
if flags.LogLevel == LogLevelDebug {
fmt.Fprintf(os.Stdout, "Performing a signed URL upload for %q with Build ID %q.", upload.path, upload.buildID)
}
err = uploadViaSignedURL(ctx, initiationResp.UploadInstructions.SignedUrl, upload.reader)
case debuginfopb.UploadInstructions_UPLOAD_STRATEGY_UNSPECIFIED:
err = errors.New("no upload strategy specified")
Expand Down

0 comments on commit 498b6b5

Please sign in to comment.