Skip to content

Commit

Permalink
Allow uploading sources
Browse files Browse the repository at this point in the history
  • Loading branch information
brancz committed Aug 16, 2023
1 parent 0e912a4 commit e6fdddc
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 104 deletions.
93 changes: 58 additions & 35 deletions cmd/parca-debuginfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type flags struct {
NoExtract bool `kong:"help='Do not extract debug information from binaries, just upload the binary as is.'"`
NoInitiate bool `kong:"help='Do not initiate the upload, just check if it should be initiated.'"`
Force bool `kong:"help='Force upload even if the Build ID is already uploaded.'"`
Type string `kong:"enum='debuginfo,executable,sources',help='Type of the debug information to upload.',default='debuginfo'"`
BuildID string `kong:"help='Build ID of the binary to upload.'"`

Paths []string `kong:"required,arg,name='path',help='Paths to upload.',type:'path'"`
} `cmd:"" help:"Upload debug information files."`
Expand Down Expand Up @@ -108,38 +110,7 @@ func run(kongCtx *kong.Context, flags flags) error {
srcDst := map[string]io.WriteSeeker{}
uploads := []*uploadInfo{}

if flags.Upload.NoExtract {
for _, path := range flags.Upload.Paths {
ef, err := elf.Open(path)
if err != nil {
return fmt.Errorf("open ELF file: %w", err)
}
defer ef.Close()

buildID, err := buildid.BuildID(&buildid.ElfFile{Path: path, File: ef})
if err != nil {
return fmt.Errorf("get Build ID for %q: %w", path, err)
}

f, err := os.Open(path)
if err != nil {
return fmt.Errorf("open file: %w", err)
}
defer f.Close()

fi, err := f.Stat()
if err != nil {
return fmt.Errorf("stat file: %w", err)
}

uploads = append(uploads, &uploadInfo{
buildID: buildID,
path: path,
reader: f,
size: fi.Size(),
})
}
} else {
if !flags.Upload.NoExtract && flags.Upload.Type == "debuginfo" {
for _, path := range flags.Upload.Paths {
ef, err := elf.Open(path)
if err != nil {
Expand Down Expand Up @@ -178,12 +149,48 @@ func run(kongCtx *kong.Context, flags flags) error {
buf.SeekStart()
upload.size = int64(buf.Len())
}
} else {
for _, path := range flags.Upload.Paths {
buildID := flags.Upload.BuildID

if flags.Upload.Type == "debuginfo" {
ef, err := elf.Open(path)
if err != nil {
return fmt.Errorf("open ELF file: %w", err)
}
defer ef.Close()

buildID, err = buildid.BuildID(&buildid.ElfFile{Path: path, File: ef})
if err != nil {
return fmt.Errorf("get Build ID for %q: %w", path, err)
}
}

f, err := os.Open(path)
if err != nil {
return fmt.Errorf("open file: %w", err)
}
defer f.Close()

fi, err := f.Stat()
if err != nil {
return fmt.Errorf("stat file: %w", err)
}

uploads = append(uploads, &uploadInfo{
buildID: buildID,
path: path,
reader: f,
size: fi.Size(),
})
}
}

for _, upload := range uploads {
shouldInitiate, err := debuginfoClient.ShouldInitiateUpload(ctx, &debuginfopb.ShouldInitiateUploadRequest{
BuildId: upload.buildID,
Force: flags.Upload.Force,
Type: debuginfoTypeStringToPb(flags.Upload.Type),

Check failure on line 193 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Go Build

unknown field Type in struct literal of type debuginfov1alpha1.ShouldInitiateUploadRequest

Check failure on line 193 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Generate documentation

unknown field Type in struct literal of type debuginfov1alpha1.ShouldInitiateUploadRequest

Check failure on line 193 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Build binaries using goreleaser

unknown field Type in struct literal of type debuginfov1alpha1.ShouldInitiateUploadRequest
})
if err != nil {
return fmt.Errorf("check if upload should be initiated for %q with Build ID %q: %w", upload.path, upload.buildID, err)
Expand Down Expand Up @@ -212,13 +219,14 @@ func run(kongCtx *kong.Context, flags flags) error {
Hash: hash,
Size: upload.size,
Force: flags.Upload.Force,
Type: debuginfoTypeStringToPb(flags.Upload.Type),

Check failure on line 222 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Go Build

unknown field Type in struct literal of type debuginfov1alpha1.InitiateUploadRequest

Check failure on line 222 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Generate documentation

unknown field Type in struct literal of type debuginfov1alpha1.InitiateUploadRequest

Check failure on line 222 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Build binaries using goreleaser

unknown field Type in struct literal of type debuginfov1alpha1.InitiateUploadRequest
})
if err != nil {
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)
fmt.Fprintf(os.Stdout, "Upload instructions\nBuildID: %s\nUploadID: %s\nUploadStrategy: %s\nSignedURL: %s\nType: %s\n", initiationResp.UploadInstructions.BuildId, initiationResp.UploadInstructions.UploadId, initiationResp.UploadInstructions.UploadStrategy.String(), initiationResp.UploadInstructions.SignedUrl, initiationResp.UploadInstructions.Type)
}

switch initiationResp.UploadInstructions.UploadStrategy {
Expand All @@ -241,7 +249,11 @@ func run(kongCtx *kong.Context, flags flags) error {
return fmt.Errorf("upload %q with Build ID %q: %w", upload.path, upload.buildID, err)
}

_, err = debuginfoClient.MarkUploadFinished(ctx, &debuginfopb.MarkUploadFinishedRequest{BuildId: upload.buildID, UploadId: initiationResp.UploadInstructions.UploadId})
_, err = debuginfoClient.MarkUploadFinished(ctx, &debuginfopb.MarkUploadFinishedRequest{
BuildId: upload.buildID,
UploadId: initiationResp.UploadInstructions.UploadId,
Type: debuginfoTypeStringToPb(flags.Upload.Type),

Check failure on line 255 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Go Build

unknown field Type in struct literal of type debuginfov1alpha1.MarkUploadFinishedRequest

Check failure on line 255 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Generate documentation

unknown field Type in struct literal of type debuginfov1alpha1.MarkUploadFinishedRequest

Check failure on line 255 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Build binaries using goreleaser

unknown field Type in struct literal of type debuginfov1alpha1.MarkUploadFinishedRequest
})
if err != nil {
return fmt.Errorf("mark upload finished for %q with Build ID %q: %w", upload.path, upload.buildID, err)
}
Expand Down Expand Up @@ -317,7 +329,7 @@ func run(kongCtx *kong.Context, flags flags) error {
return errors.New("failed to extract ELF build ID")
}

fmt.Fprintf(os.Stdout, "Build ID: %s\n", buildID)
fmt.Fprintf(os.Stdout, "%s", buildID)
return nil
}, func(error) {
cancel()
Expand Down Expand Up @@ -406,3 +418,14 @@ func uploadViaSignedURL(ctx context.Context, url string, r io.Reader) error {

return nil
}

func debuginfoTypeStringToPb(s string) debuginfopb.DebuginfoType {

Check failure on line 422 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Go Build

undefined: debuginfopb.DebuginfoType

Check failure on line 422 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Generate documentation

undefined: debuginfopb.DebuginfoType

Check failure on line 422 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Build binaries using goreleaser

undefined: debuginfopb.DebuginfoType
switch s {
case "executable":
return debuginfopb.DebuginfoType_DEBUGINFO_TYPE_EXECUTABLE

Check failure on line 425 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Go Build

undefined: debuginfopb.DebuginfoType_DEBUGINFO_TYPE_EXECUTABLE

Check failure on line 425 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Generate documentation

undefined: debuginfopb.DebuginfoType_DEBUGINFO_TYPE_EXECUTABLE

Check failure on line 425 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Build binaries using goreleaser

undefined: debuginfopb.DebuginfoType_DEBUGINFO_TYPE_EXECUTABLE
case "sources":
return debuginfopb.DebuginfoType_DEBUGINFO_TYPE_SOURCES

Check failure on line 427 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Go Build

undefined: debuginfopb.DebuginfoType_DEBUGINFO_TYPE_SOURCES

Check failure on line 427 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Generate documentation

undefined: debuginfopb.DebuginfoType_DEBUGINFO_TYPE_SOURCES

Check failure on line 427 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Build binaries using goreleaser

undefined: debuginfopb.DebuginfoType_DEBUGINFO_TYPE_SOURCES
default:
return debuginfopb.DebuginfoType_DEBUGINFO_TYPE_DEBUGINFO_UNSPECIFIED

Check failure on line 429 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Go Build

undefined: debuginfopb.DebuginfoType_DEBUGINFO_TYPE_DEBUGINFO_UNSPECIFIED

Check failure on line 429 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Generate documentation

undefined: debuginfopb.DebuginfoType_DEBUGINFO_TYPE_DEBUGINFO_UNSPECIFIED

Check failure on line 429 in cmd/parca-debuginfo/main.go

View workflow job for this annotation

GitHub Actions / Build binaries using goreleaser

undefined: debuginfopb.DebuginfoType_DEBUGINFO_TYPE_DEBUGINFO_UNSPECIFIED
}
}
42 changes: 21 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ require (
github.com/parca-dev/parca-agent v0.12.1-0.20230216133018-8dd5ccaeef0f
github.com/prometheus/client_golang v1.16.0
github.com/rzajac/flexbuf v0.14.0
google.golang.org/grpc v1.56.2
google.golang.org/grpc v1.57.0
)

require (
cloud.google.com/go v0.110.2 // indirect
cloud.google.com/go/compute v1.20.1 // indirect
cloud.google.com/go v0.110.4 // indirect
cloud.google.com/go/compute v1.22.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.0 // indirect
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/storage v1.31.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.3.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.5.1 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v0.8.1 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
github.com/aliyun/aliyun-oss-go-sdk v2.2.2+incompatible // indirect
github.com/aws/aws-sdk-go-v2 v1.16.0 // indirect
github.com/aws/aws-sdk-go-v2/config v1.15.1 // indirect
Expand All @@ -41,7 +41,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/clbanning/mxj v1.8.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/efficientgo/core v1.0.0-rc.2 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
Expand All @@ -54,39 +54,39 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect
github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.23.3+incompatible // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/minio-go/v7 v7.0.45 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/minio/minio-go/v7 v7.0.61 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mozillazg/go-httpheader v0.2.1 // indirect
github.com/ncw/swift v1.0.53 // indirect
github.com/oracle/oci-go-sdk/v65 v65.13.0 // indirect
github.com/oracle/oci-go-sdk/v65 v65.41.1 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.0 // indirect
github.com/rs/xid v1.4.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sony/gobreaker v0.5.0 // indirect
github.com/tencentyun/cos-go-sdk-v5 v0.7.40 // indirect
github.com/thanos-io/objstore v0.0.0-20230713070940-eb01c83b89a4 // indirect
github.com/thanos-io/objstore v0.0.0-20230804084840-c042a6a16c58 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.42.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
Expand All @@ -100,11 +100,11 @@ require (
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.131.0 // indirect
google.golang.org/api v0.134.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230629202037-9506855d4529 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto v0.0.0-20230717213848-3f92550aa753 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit e6fdddc

Please sign in to comment.