Skip to content

Commit edcc5fc

Browse files
authored
Merge pull request #3 from parca-dev/headers
Add ability to attach arbitrary headers
2 parents 02fbeec + 39bafa4 commit edcc5fc

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

.github/workflows/container.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
GORELEASER_CURRENT_TAG: "${{ env.goreleaser_current_tag }}"
5252
steps:
5353
- name: Check out the code
54-
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
54+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # tag=v6.0.1
5555

5656
- name: Set up Go
5757
uses: actions/setup-go@84cbf8094393cdc5fe1fe1671ff2647332956b1a # tag=v3.2.1
@@ -63,7 +63,7 @@ jobs:
6363
run: goreleaser release --rm-dist --skip-validate --skip-publish --snapshot --debug
6464

6565
- name: Archive generated artifacts
66-
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # tag=v3.1.0
66+
uses: actions/upload-artifact@v5
6767
with:
6868
name: parca-push-dist-container
6969
if-no-files-found: error
@@ -94,15 +94,15 @@ jobs:
9494
run: dnf install --assumeyes --repo fedora git make jq
9595

9696
- name: Check out code into the Go module directory
97-
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
97+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # tag=v6.0.1
9898

9999
- name: Set up Go
100100
uses: actions/setup-go@84cbf8094393cdc5fe1fe1671ff2647332956b1a # tag=v3.2.1
101101
with:
102102
go-version-file: 'go.mod'
103103
check-latest: true
104104

105-
- uses: actions/download-artifact@v3
105+
- uses: actions/download-artifact@v4
106106
with:
107107
name: parca-push-dist-container
108108
path: goreleaser/dist

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ Flags:
3737
TLS.
3838
--remote-store-insecure-skip-verify
3939
Skip TLS certificate verification.
40+
--remote-store-grpc-headers=KEY=VALUE;...
41+
Additional gRPC headers to send with each
42+
request (key=value pairs).
4043
```

cmd/parca-push/main.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"google.golang.org/grpc"
3333
"google.golang.org/grpc/credentials"
3434
"google.golang.org/grpc/credentials/insecure"
35+
"google.golang.org/grpc/metadata"
3536
)
3637

3738
type flags struct {
@@ -45,11 +46,12 @@ type flags struct {
4546

4647
// FlagsRemoteStore provides remote store configuration flags.
4748
type FlagsRemoteStore struct {
48-
Address string `kong:"help='gRPC address to send profiles and symbols to.'"`
49-
BearerToken string `kong:"help='Bearer token to authenticate with store.'"`
50-
BearerTokenFile string `kong:"help='File to read bearer token from to authenticate with store.'"`
51-
Insecure bool `kong:"help='Send gRPC requests via plaintext instead of TLS.'"`
52-
InsecureSkipVerify bool `kong:"help='Skip TLS certificate verification.'"`
49+
Address string `kong:"help='gRPC address to send profiles and symbols to.'"`
50+
BearerToken string `kong:"help='Bearer token to authenticate with store.'"`
51+
BearerTokenFile string `kong:"help='File to read bearer token from to authenticate with store.'"`
52+
Insecure bool `kong:"help='Send gRPC requests via plaintext instead of TLS.'"`
53+
InsecureSkipVerify bool `kong:"help='Skip TLS certificate verification.'"`
54+
GRPCHeaders map[string]string `kong:"help='Additional gRPC headers to send with each request (key=value pairs).'"`
5355
}
5456

5557
func main() {
@@ -132,16 +134,33 @@ func run(flags flags) error {
132134
return g.Run()
133135
}
134136

137+
func customHeadersUnaryInterceptor(headers map[string]string) grpc.UnaryClientInterceptor {
138+
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
139+
for key, value := range headers {
140+
ctx = metadata.AppendToOutgoingContext(ctx, key, value)
141+
}
142+
return invoker(ctx, method, req, reply, cc, opts...)
143+
}
144+
}
145+
135146
func grpcConn(reg prometheus.Registerer, flags FlagsRemoteStore) (*grpc.ClientConn, error) {
136147
met := grpc_prometheus.NewClientMetrics()
137148
met.EnableClientHandlingTimeHistogram()
138149
reg.MustRegister(met)
139150

140-
opts := []grpc.DialOption{
141-
grpc.WithUnaryInterceptor(
142-
met.UnaryClientInterceptor(),
143-
),
151+
opts := []grpc.DialOption{}
152+
153+
// Add custom headers interceptor first if headers are provided
154+
if len(flags.GRPCHeaders) > 0 {
155+
opts = append(opts, grpc.WithUnaryInterceptor(
156+
customHeadersUnaryInterceptor(flags.GRPCHeaders),
157+
))
144158
}
159+
160+
// Add metrics interceptor
161+
opts = append(opts, grpc.WithUnaryInterceptor(
162+
met.UnaryClientInterceptor(),
163+
))
145164
if flags.Insecure {
146165
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
147166
} else {

0 commit comments

Comments
 (0)