Skip to content

Commit 4349c1e

Browse files
authored
feat(profilecli): Allow to use different protocols (#3368)
* profilecli: Allow to use different procotols This allows to switch out the connect protocol for either json or grpc-web. * Also use the selected protocol for uploading
1 parent e74f3b8 commit 4349c1e

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

cmd/profilecli/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type phlareClient struct {
2323
}
2424
defaultTransport http.RoundTripper
2525
client *http.Client
26+
protocol protocolType
2627
}
2728

2829
type authRoundTripper struct {
@@ -69,5 +70,6 @@ func addPhlareClient(cmd commander) *phlareClient {
6970
cmd.Flag("tenant-id", "The tenant ID to be used for the X-Scope-OrgID header.").Default("").Envar(envPrefix + "TENANT_ID").StringVar(&client.TenantID)
7071
cmd.Flag("username", "The username to be used for basic auth.").Default("").Envar(envPrefix + "USERNAME").StringVar(&client.BasicAuth.Username)
7172
cmd.Flag("password", "The password to be used for basic auth.").Default("").Envar(envPrefix + "PASSWORD").StringVar(&client.BasicAuth.Password)
73+
cmd.Flag("protocol", "The protocol to be used for communicating with the server.").Default(protocolTypeGRPC).EnumVar(&client.BasicAuth.Password, protocolTypeGRPC, protocolTypeGRPCWeb, protocolTypeJSON)
7274
return client
7375
}

cmd/profilecli/query.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,61 @@ import (
2828
"github.com/pkg/errors"
2929
)
3030

31+
type protocolType string
32+
3133
const (
3234
outputConsole = "console"
3335
outputRaw = "raw"
3436
outputPprof = "pprof="
37+
38+
protocolTypeGRPC = "grpc"
39+
protocolTypeGRPCWeb = "grpc-web"
40+
protocolTypeJSON = "json"
3541
)
3642

43+
func (c *phlareClient) protocolOption() connect.ClientOption {
44+
switch c.protocol {
45+
case protocolTypeGRPC:
46+
return connect.WithGRPC()
47+
case protocolTypeGRPCWeb:
48+
return connect.WithGRPCWeb()
49+
case protocolTypeJSON:
50+
return connect.WithProtoJSON()
51+
default:
52+
return connect.WithGRPC()
53+
}
54+
}
55+
3756
func (c *phlareClient) queryClient() querierv1connect.QuerierServiceClient {
3857
return querierv1connect.NewQuerierServiceClient(
3958
c.httpClient(),
4059
c.URL,
41-
connectapi.DefaultClientOptions()...,
60+
append(
61+
connectapi.DefaultClientOptions(),
62+
c.protocolOption(),
63+
)...,
4264
)
4365
}
4466

4567
func (c *phlareClient) storeGatewayClient() storegatewayv1connect.StoreGatewayServiceClient {
4668
return storegatewayv1connect.NewStoreGatewayServiceClient(
4769
c.httpClient(),
4870
c.URL,
49-
connectapi.DefaultClientOptions()...,
71+
append(
72+
connectapi.DefaultClientOptions(),
73+
c.protocolOption(),
74+
)...,
5075
)
5176
}
5277

5378
func (c *phlareClient) ingesterClient() ingesterv1connect.IngesterServiceClient {
5479
return ingesterv1connect.NewIngesterServiceClient(
5580
c.httpClient(),
5681
c.URL,
57-
connectapi.DefaultClientOptions()...,
82+
append(
83+
connectapi.DefaultClientOptions(),
84+
c.protocolOption(),
85+
)...,
5886
)
5987
}
6088

cmd/profilecli/upload.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ func (c *phlareClient) pusherClient() pushv1connect.PusherServiceClient {
2020
return pushv1connect.NewPusherServiceClient(
2121
c.httpClient(),
2222
c.URL,
23-
connectapi.DefaultClientOptions()...,
23+
append(
24+
connectapi.DefaultClientOptions(),
25+
c.protocolOption(),
26+
)...,
2427
)
2528
}
2629

0 commit comments

Comments
 (0)