-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvoy-bench.rb
More file actions
executable file
·81 lines (70 loc) · 3.02 KB
/
convoy-bench.rb
File metadata and controls
executable file
·81 lines (70 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env ruby
require 'rubygems'
require 'thor'
class ConvoyBench < Thor
def self.exit_on_failure?
true
end
desc "exec", "execute convoy benchmarks"
option :producer, aliases: "-p", default: "http",
desc: "Select a producer to publish events from the following - http, sqs, pubsub or kafka."
option :project, aliases: "-t", default: "outgoing",
desc: "Specify the project type, outgoing or incoming"
option :uri, aliases: "-u", default: "http://localhost:5005",
desc: "For outgoing projects it is base url of your Convoy Cluster. For incoming projects it is the ingest url."
option :vus, aliases: "-v", default: "10",
desc: "Set how many virtual users should execute the test concurrently."
option :rate, aliases: "-r", default: "10",
desc: "Set how many requests should be sent per second."
option :duration, aliases: "-d", default: "1m",
desc: "Set how long the test should run. Use Golang string syntax: 1m, 5s, 10m5s."
option "endpoint-id", aliases: "-e", required: false,
desc: "ID of the endpoint configured on Convoy. Only specify this if the project is outgoing."
option "api-key", aliases: "-a", required: false,
desc: "Convoy Cluster API Key. Specify this if producer is http and the project is outgoing."
option "project-id", aliases: "-pid", required: false,
desc: "Convoy Cluster project ID. Specify this if producer is http and the project is outgoing."
option "queue-url", aliases: "-q", required: false,
desc: "Amazon SQS URL. Specify this if producer is sqs."
option "aws-access-key", aliases: "-aak", required: false,
desc: "AWS Access Key. Specify this if producer is sqs."
option "aws-secret-key", aliases: "-ask", required: false,
desc: "AWS Secret Key. Specify this if producer is sqs."
def exec
ENV["VUS"] = options[:vus]
ENV["RATE"] = options[:rate]
ENV["DURATION"] = options[:duration]
ENV["BASE_URL"] = options[:uri]
ENV["ENDPOINT_ID"] = options["endpoint-id"]
ENV["PROJECT_ID"] = options["project-id"]
ENV["API_KEY"] = options["api-key"]
ENV["QUEUE_URL"] = options["queue-url"]
ENV["AWS_ACCESS_KEY"] = options["aws-access-key"]
ENV["AWS_SECRET_KEY"] = options["aws-secret-key"]
exec_command = "./bin/k6"
producer_command = get_producer_command(options[:producer])
Kernel.system(exec_command, "run", producer_command)
end
default_task :exec
private
def get_producer_command(producer)
case producer
when "http", :http
if options[:project] == "outgoing"
producer_command = "producer/http_test_outgoing.js"
elsif options[:project] == "incoming"
producer_command = "producer/http_test_incoming.js"
end
when "sqs", :sqs
producer_command = "producer/sqs_test.js"
when "pubsub", :pubsub
producer_command = "producer/pubsub_test.js"
when "kafka", :kafka
producer_command = "producer/kafka_test.js"
else
raise ArgumentError.new "Invalid producer type - #{producer}"
end
producer_command
end
end
ConvoyBench.start