Skip to content

Commit ace8012

Browse files
authored
Merge pull request #17 from parca-dev/sources
Allow uploading sources
2 parents 0e912a4 + 3313900 commit ace8012

File tree

3 files changed

+160
-123
lines changed

3 files changed

+160
-123
lines changed

cmd/parca-debuginfo/main.go

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type flags struct {
5757
NoExtract bool `kong:"help='Do not extract debug information from binaries, just upload the binary as is.'"`
5858
NoInitiate bool `kong:"help='Do not initiate the upload, just check if it should be initiated.'"`
5959
Force bool `kong:"help='Force upload even if the Build ID is already uploaded.'"`
60+
Type string `kong:"enum='debuginfo,executable,sources',help='Type of the debug information to upload.',default='debuginfo'"`
61+
BuildID string `kong:"help='Build ID of the binary to upload.'"`
6062

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

111-
if flags.Upload.NoExtract {
112-
for _, path := range flags.Upload.Paths {
113-
ef, err := elf.Open(path)
114-
if err != nil {
115-
return fmt.Errorf("open ELF file: %w", err)
116-
}
117-
defer ef.Close()
118-
119-
buildID, err := buildid.BuildID(&buildid.ElfFile{Path: path, File: ef})
120-
if err != nil {
121-
return fmt.Errorf("get Build ID for %q: %w", path, err)
122-
}
123-
124-
f, err := os.Open(path)
125-
if err != nil {
126-
return fmt.Errorf("open file: %w", err)
127-
}
128-
defer f.Close()
129-
130-
fi, err := f.Stat()
131-
if err != nil {
132-
return fmt.Errorf("stat file: %w", err)
133-
}
134-
135-
uploads = append(uploads, &uploadInfo{
136-
buildID: buildID,
137-
path: path,
138-
reader: f,
139-
size: fi.Size(),
140-
})
141-
}
142-
} else {
113+
if !flags.Upload.NoExtract && flags.Upload.Type == "debuginfo" {
143114
for _, path := range flags.Upload.Paths {
144115
ef, err := elf.Open(path)
145116
if err != nil {
@@ -178,12 +149,48 @@ func run(kongCtx *kong.Context, flags flags) error {
178149
buf.SeekStart()
179150
upload.size = int64(buf.Len())
180151
}
152+
} else {
153+
for _, path := range flags.Upload.Paths {
154+
buildID := flags.Upload.BuildID
155+
156+
if flags.Upload.Type == "debuginfo" {
157+
ef, err := elf.Open(path)
158+
if err != nil {
159+
return fmt.Errorf("open ELF file: %w", err)
160+
}
161+
defer ef.Close()
162+
163+
buildID, err = buildid.BuildID(&buildid.ElfFile{Path: path, File: ef})
164+
if err != nil {
165+
return fmt.Errorf("get Build ID for %q: %w", path, err)
166+
}
167+
}
168+
169+
f, err := os.Open(path)
170+
if err != nil {
171+
return fmt.Errorf("open file: %w", err)
172+
}
173+
defer f.Close()
174+
175+
fi, err := f.Stat()
176+
if err != nil {
177+
return fmt.Errorf("stat file: %w", err)
178+
}
179+
180+
uploads = append(uploads, &uploadInfo{
181+
buildID: buildID,
182+
path: path,
183+
reader: f,
184+
size: fi.Size(),
185+
})
186+
}
181187
}
182188

183189
for _, upload := range uploads {
184190
shouldInitiate, err := debuginfoClient.ShouldInitiateUpload(ctx, &debuginfopb.ShouldInitiateUploadRequest{
185191
BuildId: upload.buildID,
186192
Force: flags.Upload.Force,
193+
Type: debuginfoTypeStringToPb(flags.Upload.Type),
187194
})
188195
if err != nil {
189196
return fmt.Errorf("check if upload should be initiated for %q with Build ID %q: %w", upload.path, upload.buildID, err)
@@ -212,13 +219,14 @@ func run(kongCtx *kong.Context, flags flags) error {
212219
Hash: hash,
213220
Size: upload.size,
214221
Force: flags.Upload.Force,
222+
Type: debuginfoTypeStringToPb(flags.Upload.Type),
215223
})
216224
if err != nil {
217225
return fmt.Errorf("initiate upload for %q with Build ID %q: %w", upload.path, upload.buildID, err)
218226
}
219227

220228
if flags.LogLevel == LogLevelDebug {
221-
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)
229+
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)
222230
}
223231

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

244-
_, err = debuginfoClient.MarkUploadFinished(ctx, &debuginfopb.MarkUploadFinishedRequest{BuildId: upload.buildID, UploadId: initiationResp.UploadInstructions.UploadId})
252+
_, err = debuginfoClient.MarkUploadFinished(ctx, &debuginfopb.MarkUploadFinishedRequest{
253+
BuildId: upload.buildID,
254+
UploadId: initiationResp.UploadInstructions.UploadId,
255+
Type: debuginfoTypeStringToPb(flags.Upload.Type),
256+
})
245257
if err != nil {
246258
return fmt.Errorf("mark upload finished for %q with Build ID %q: %w", upload.path, upload.buildID, err)
247259
}
@@ -317,7 +329,7 @@ func run(kongCtx *kong.Context, flags flags) error {
317329
return errors.New("failed to extract ELF build ID")
318330
}
319331

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

407419
return nil
408420
}
421+
422+
func debuginfoTypeStringToPb(s string) debuginfopb.DebuginfoType {
423+
switch s {
424+
case "executable":
425+
return debuginfopb.DebuginfoType_DEBUGINFO_TYPE_EXECUTABLE
426+
case "sources":
427+
return debuginfopb.DebuginfoType_DEBUGINFO_TYPE_SOURCES
428+
default:
429+
return debuginfopb.DebuginfoType_DEBUGINFO_TYPE_DEBUGINFO_UNSPECIFIED
430+
}
431+
}

go.mod

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ require (
77
github.com/go-kit/log v0.2.1
88
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
99
github.com/oklog/run v1.1.0
10-
github.com/parca-dev/parca v0.18.1-0.20230714102256-04bf3e42dfea
10+
github.com/parca-dev/parca v0.18.1-0.20230816074650-c9b9bed904c3
1111
github.com/parca-dev/parca-agent v0.12.1-0.20230216133018-8dd5ccaeef0f
1212
github.com/prometheus/client_golang v1.16.0
1313
github.com/rzajac/flexbuf v0.14.0
14-
google.golang.org/grpc v1.56.2
14+
google.golang.org/grpc v1.57.0
1515
)
1616

1717
require (
18-
cloud.google.com/go v0.110.2 // indirect
19-
cloud.google.com/go/compute v1.20.1 // indirect
18+
cloud.google.com/go v0.110.6 // indirect
19+
cloud.google.com/go/compute v1.23.0 // indirect
2020
cloud.google.com/go/compute/metadata v0.2.3 // indirect
21-
cloud.google.com/go/iam v1.1.0 // indirect
21+
cloud.google.com/go/iam v1.1.1 // indirect
2222
cloud.google.com/go/storage v1.31.0 // indirect
23-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.3.1 // indirect
24-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.1 // indirect
23+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0 // indirect
24+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 // indirect
2525
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
2626
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.5.1 // indirect
27-
github.com/AzureAD/microsoft-authentication-library-for-go v0.8.1 // indirect
27+
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
2828
github.com/aliyun/aliyun-oss-go-sdk v2.2.2+incompatible // indirect
2929
github.com/aws/aws-sdk-go-v2 v1.16.0 // indirect
3030
github.com/aws/aws-sdk-go-v2/config v1.15.1 // indirect
@@ -41,7 +41,7 @@ require (
4141
github.com/beorn7/perks v1.0.1 // indirect
4242
github.com/cespare/xxhash/v2 v2.2.0 // indirect
4343
github.com/clbanning/mxj v1.8.4 // indirect
44-
github.com/davecgh/go-spew v1.1.1 // indirect
44+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
4545
github.com/dustin/go-humanize v1.0.1 // indirect
4646
github.com/efficientgo/core v1.0.0-rc.2 // indirect
4747
github.com/go-logfmt/logfmt v0.6.0 // indirect
@@ -54,57 +54,57 @@ require (
5454
github.com/golang/protobuf v1.5.3 // indirect
5555
github.com/google/go-cmp v0.5.9 // indirect
5656
github.com/google/go-querystring v1.1.0 // indirect
57-
github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect
58-
github.com/google/s2a-go v0.1.4 // indirect
57+
github.com/google/pprof v0.0.0-20230811205829-9131a7e9cc17 // indirect
58+
github.com/google/s2a-go v0.1.5 // indirect
5959
github.com/google/uuid v1.3.0 // indirect
6060
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
6161
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
62-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
62+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.2 // indirect
6363
github.com/hashicorp/errwrap v1.1.0 // indirect
6464
github.com/hashicorp/go-multierror v1.1.1 // indirect
6565
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.23.3+incompatible // indirect
6666
github.com/json-iterator/go v1.1.12 // indirect
6767
github.com/klauspost/compress v1.16.7 // indirect
68-
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
68+
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
6969
github.com/kylelemons/godebug v1.1.0 // indirect
7070
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
7171
github.com/minio/md5-simd v1.1.2 // indirect
72-
github.com/minio/minio-go/v7 v7.0.45 // indirect
73-
github.com/minio/sha256-simd v1.0.0 // indirect
72+
github.com/minio/minio-go/v7 v7.0.61 // indirect
73+
github.com/minio/sha256-simd v1.0.1 // indirect
7474
github.com/mitchellh/mapstructure v1.5.0 // indirect
7575
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
7676
github.com/modern-go/reflect2 v1.0.2 // indirect
7777
github.com/mozillazg/go-httpheader v0.2.1 // indirect
7878
github.com/ncw/swift v1.0.53 // indirect
79-
github.com/oracle/oci-go-sdk/v65 v65.13.0 // indirect
79+
github.com/oracle/oci-go-sdk/v65 v65.41.1 // indirect
8080
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
8181
github.com/pkg/errors v0.9.1 // indirect
8282
github.com/prometheus/client_model v0.4.0 // indirect
8383
github.com/prometheus/common v0.44.0 // indirect
8484
github.com/prometheus/procfs v0.11.0 // indirect
85-
github.com/rs/xid v1.4.0 // indirect
86-
github.com/sirupsen/logrus v1.9.0 // indirect
85+
github.com/rs/xid v1.5.0 // indirect
86+
github.com/sirupsen/logrus v1.9.3 // indirect
8787
github.com/sony/gobreaker v0.5.0 // indirect
8888
github.com/tencentyun/cos-go-sdk-v5 v0.7.40 // indirect
89-
github.com/thanos-io/objstore v0.0.0-20230713070940-eb01c83b89a4 // indirect
89+
github.com/thanos-io/objstore v0.0.0-20230804084840-c042a6a16c58 // indirect
9090
go.opencensus.io v0.24.0 // indirect
9191
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.42.0 // indirect
9292
go.opentelemetry.io/otel v1.16.0 // indirect
9393
go.opentelemetry.io/otel/metric v1.16.0 // indirect
9494
go.opentelemetry.io/otel/trace v1.16.0 // indirect
95-
golang.org/x/crypto v0.11.0 // indirect
96-
golang.org/x/net v0.12.0 // indirect
97-
golang.org/x/oauth2 v0.10.0 // indirect
95+
golang.org/x/crypto v0.12.0 // indirect
96+
golang.org/x/net v0.14.0 // indirect
97+
golang.org/x/oauth2 v0.11.0 // indirect
9898
golang.org/x/sync v0.3.0 // indirect
99-
golang.org/x/sys v0.10.0 // indirect
100-
golang.org/x/text v0.11.0 // indirect
99+
golang.org/x/sys v0.11.0 // indirect
100+
golang.org/x/text v0.12.0 // indirect
101101
golang.org/x/time v0.3.0 // indirect
102102
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
103-
google.golang.org/api v0.131.0 // indirect
103+
google.golang.org/api v0.137.0 // indirect
104104
google.golang.org/appengine v1.6.7 // indirect
105-
google.golang.org/genproto v0.0.0-20230629202037-9506855d4529 // indirect
106-
google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529 // indirect
107-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect
105+
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
106+
google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5 // indirect
107+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 // indirect
108108
google.golang.org/protobuf v1.31.0 // indirect
109109
gopkg.in/ini.v1 v1.67.0 // indirect
110110
gopkg.in/yaml.v2 v2.4.0 // indirect

0 commit comments

Comments
 (0)