Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support jwt and trusted cert for pulsar perf client #428

Merged
merged 2 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions perf/perf-consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ func consume(consumeArgs *ConsumeArgs, stop <-chan struct{}) {
b, _ = json.MarshalIndent(consumeArgs, "", " ")
log.Info("Consumer config: ", string(b))

client, err := pulsar.NewClient(pulsar.ClientOptions{
URL: clientArgs.ServiceURL,
})
client, err := NewClient()

if err != nil {
log.Fatal(err)
Expand All @@ -92,6 +90,7 @@ func consume(consumeArgs *ConsumeArgs, stop <-chan struct{}) {

// Print stats of the consume rate
tick := time.NewTicker(10 * time.Second)
defer tick.Stop()

for {
select {
Expand Down
1 change: 1 addition & 0 deletions perf/perf-producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func produce(produceArgs *ProduceArgs, stop <-chan struct{}) {

// Print stats of the publish rate and latencies
tick := time.NewTicker(10 * time.Second)
defer tick.Stop()
q := quantile.NewTargeted(0.50, 0.95, 0.99, 0.999, 1.0)
messagesPublished := 0

Expand Down
21 changes: 20 additions & 1 deletion perf/pulsar-perf-go.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"net/http"
_ "net/http/pprof"
"os"
Expand All @@ -40,7 +41,9 @@ var flagDebug bool
var PrometheusPort int

type ClientArgs struct {
ServiceURL string
ServiceURL string
TokenFile string
TLSTrustCertFile string
}

var clientArgs ClientArgs
Expand All @@ -49,6 +52,20 @@ func NewClient() (pulsar.Client, error) {
clientOpts := pulsar.ClientOptions{
URL: clientArgs.ServiceURL,
}

if clientArgs.TokenFile != "" {
// read JWT from the file
tokenBytes, err := ioutil.ReadFile(clientArgs.TokenFile)
if err != nil {
log.WithError(err).Errorf("failed to read Pulsar JWT from a file %s", clientArgs.TokenFile)
os.Exit(1)
}
clientOpts.Authentication = pulsar.NewAuthenticationToken(string(tokenBytes))
}

if clientArgs.TLSTrustCertFile != "" {
clientOpts.TLSTrustCertsFilePath = clientArgs.TLSTrustCertFile
}
return pulsar.NewClient(clientOpts)
}

Expand Down Expand Up @@ -78,6 +95,8 @@ func main() {
flags.BoolVar(&flagDebug, "debug", false, "enable debug output")
flags.StringVarP(&clientArgs.ServiceURL, "service-url", "u",
"pulsar://localhost:6650", "The Pulsar service URL")
flags.StringVar(&clientArgs.TokenFile, "token-file", "", "file path to the Pulsar JWT file")
flags.StringVar(&clientArgs.TLSTrustCertFile, "trust-cert-file", "", "file path to the trusted certificate file")

rootCmd.AddCommand(newProducerCommand())
rootCmd.AddCommand(newConsumerCommand())
Expand Down