Skip to content

Commit

Permalink
feat(profilecli): Allow to use different protocols (#3368)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
simonswine committed Jun 19, 2024
1 parent e74f3b8 commit 4349c1e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmd/profilecli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type phlareClient struct {
}
defaultTransport http.RoundTripper
client *http.Client
protocol protocolType
}

type authRoundTripper struct {
Expand Down Expand Up @@ -69,5 +70,6 @@ func addPhlareClient(cmd commander) *phlareClient {
cmd.Flag("tenant-id", "The tenant ID to be used for the X-Scope-OrgID header.").Default("").Envar(envPrefix + "TENANT_ID").StringVar(&client.TenantID)
cmd.Flag("username", "The username to be used for basic auth.").Default("").Envar(envPrefix + "USERNAME").StringVar(&client.BasicAuth.Username)
cmd.Flag("password", "The password to be used for basic auth.").Default("").Envar(envPrefix + "PASSWORD").StringVar(&client.BasicAuth.Password)
cmd.Flag("protocol", "The protocol to be used for communicating with the server.").Default(protocolTypeGRPC).EnumVar(&client.BasicAuth.Password, protocolTypeGRPC, protocolTypeGRPCWeb, protocolTypeJSON)
return client
}
34 changes: 31 additions & 3 deletions cmd/profilecli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,61 @@ import (
"github.com/pkg/errors"
)

type protocolType string

const (
outputConsole = "console"
outputRaw = "raw"
outputPprof = "pprof="

protocolTypeGRPC = "grpc"
protocolTypeGRPCWeb = "grpc-web"
protocolTypeJSON = "json"
)

func (c *phlareClient) protocolOption() connect.ClientOption {
switch c.protocol {
case protocolTypeGRPC:
return connect.WithGRPC()
case protocolTypeGRPCWeb:
return connect.WithGRPCWeb()
case protocolTypeJSON:
return connect.WithProtoJSON()
default:
return connect.WithGRPC()
}
}

func (c *phlareClient) queryClient() querierv1connect.QuerierServiceClient {
return querierv1connect.NewQuerierServiceClient(
c.httpClient(),
c.URL,
connectapi.DefaultClientOptions()...,
append(
connectapi.DefaultClientOptions(),
c.protocolOption(),
)...,
)
}

func (c *phlareClient) storeGatewayClient() storegatewayv1connect.StoreGatewayServiceClient {
return storegatewayv1connect.NewStoreGatewayServiceClient(
c.httpClient(),
c.URL,
connectapi.DefaultClientOptions()...,
append(
connectapi.DefaultClientOptions(),
c.protocolOption(),
)...,
)
}

func (c *phlareClient) ingesterClient() ingesterv1connect.IngesterServiceClient {
return ingesterv1connect.NewIngesterServiceClient(
c.httpClient(),
c.URL,
connectapi.DefaultClientOptions()...,
append(
connectapi.DefaultClientOptions(),
c.protocolOption(),
)...,
)
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/profilecli/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ func (c *phlareClient) pusherClient() pushv1connect.PusherServiceClient {
return pushv1connect.NewPusherServiceClient(
c.httpClient(),
c.URL,
connectapi.DefaultClientOptions()...,
append(
connectapi.DefaultClientOptions(),
c.protocolOption(),
)...,
)
}

Expand Down

0 comments on commit 4349c1e

Please sign in to comment.