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

Add auth token flags for pulsar-perf #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 30 additions & 2 deletions 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 @@ -41,7 +42,10 @@ var flagDebug bool
var PrometheusPort int

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

var clientArgs ClientArgs
Expand All @@ -50,6 +54,25 @@ 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
}

if clientArgs.AuthToken != "" {
clientOpts.Authentication = pulsar.NewAuthenticationToken(clientArgs.AuthToken)
}

return pulsar.NewClient(clientOpts)
}

Expand All @@ -75,10 +98,15 @@ func main() {

flags := rootCmd.PersistentFlags()
flags.BoolVar(&FlagProfile, "profile", false, "enable profiling")
flags.IntVar(&PrometheusPort, "metrics", 8000, "Port to use to export metrics for Prometheus. Use -1 to disable.")
flags.IntVar(&PrometheusPort, "metrics", 8000,
"Port to use to export metrics for Prometheus. Use -1 to disable.")
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.AuthToken, "token-string", "", "string to the Pulsar JWT")
flags.StringVar(&clientArgs.TLSTrustCertFile, "trust-cert-file", "",
"file path to the trusted certificate file")

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