Skip to content

Commit

Permalink
feat: add storage load scripts to examples (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
egor-romanov authored Sep 23, 2024
1 parent 7f66c1b commit 10a6475
Show file tree
Hide file tree
Showing 35 changed files with 1,288 additions and 129 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export { handleSummary } from './summary.js'
const serviceToken = __ENV.SERVICE_TOKEN
const baseUri = __ENV.BASE_URI
? __ENV.BASE_URI
: 'https://jjqwaskwktqjmyyuqrix.supabase.red'
: 'https://proj.supabase.com'
const imageURI = __ENV.IMAGE_URI
? __ENV.IMAGE_URI
: `${baseUri}/storage/v1/object/public/images/` // 3mb.jpg?time=
Expand Down Expand Up @@ -45,23 +45,7 @@ export default () => {
apikey: serviceToken,
}

// cp image to use for resize
sleep(randomIntBetween(100, 5000) / 1000)
// const res = http.post(
// `${storageUploadUri}/copy`,
// JSON.stringify({
// sourceKey: '3mb.jpg',
// destinationKey: path,
// bucketId: 'images',
// }),
// {
// headers: Object.assign(headers, { 'Content-Type': 'application/json' }),
// }
// )

// check(res, {
// 'upload is status 200': (r) => r.status === 200,
// })

for (let i = 1; i <= requests; i++) {
const getImage = http.get(`${imageURI}/${path}?time=${Date.now()}`, {
Expand All @@ -75,20 +59,4 @@ export default () => {

sleep(randomIntBetween(100, 5000) / 1000)
}

// const removeRes = http.del(
// `${storageUploadUri}/images`,
// JSON.stringify({
// prefixes: [path],
// }),
// {
// headers: {
// authorization: `Bearer ${serviceToken}`,
// apikey: serviceToken,
// 'Content-Type': 'application/json',
// },
// }
// )

// check(removeRes, { 'delete status is 200': (r) => r && r.status === 200 })
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,85 @@
# creating ec2 instance that will be used to generate load
# Most likely you will not need to change it

resource "aws_vpc" "ap-southeast-1" {
enable_dns_support = true
enable_dns_hostnames = true
assign_generated_ipv6_cidr_block = true
cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "ap-southeast-1" {
vpc_id = aws_vpc.ap-southeast-1.id
cidr_block = cidrsubnet(aws_vpc.ap-southeast-1.cidr_block, 4, 1)
map_public_ip_on_launch = true

ipv6_cidr_block = cidrsubnet(aws_vpc.ap-southeast-1.ipv6_cidr_block, 8, 1)
assign_ipv6_address_on_creation = true
}

resource "aws_internet_gateway" "ap-southeast-1" {
vpc_id = aws_vpc.ap-southeast-1.id
}

resource "aws_default_route_table" "ap-southeast-1" {
default_route_table_id = aws_vpc.ap-southeast-1.default_route_table_id

route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.ap-southeast-1.id
}

route {
ipv6_cidr_block = "::/0"
gateway_id = aws_internet_gateway.ap-southeast-1.id
}
}

resource "aws_route_table_association" "ap-southeast-1" {
subnet_id = aws_subnet.ap-southeast-1.id
route_table_id = aws_default_route_table.ap-southeast-1.id
}

resource "aws_security_group" "ap-southeast-1" {
name = "supabench-tf-security-group-${aws_vpc.ap-southeast-1.id}"
vpc_id = aws_vpc.ap-southeast-1.id
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 0
to_port = 0
protocol = "-1"
ipv6_cidr_blocks = ["::/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
ipv6_cidr_blocks = ["::/0"]
}
}

resource "aws_instance" "k6" {
count = var.instances_count

ami = var.ami_id
instance_type = var.instance_type
vpc_security_group_ids = [var.security_group_id]
subnet_id = var.subnet_id
vpc_security_group_ids = ["${aws_security_group.ap-southeast-1.id}"]
subnet_id = aws_subnet.ap-southeast-1.id
ipv6_address_count = 1

key_name = var.key_name

Expand All @@ -28,7 +101,7 @@ resource "null_resource" "remote" {
user = var.instance_user
host = aws_instance.k6[count.index].public_ip
private_key = var.private_key_location
timeout = "1m"
timeout = "5m"
}

# upload k6 scripts to remote instance, you likely won't need to change this part
Expand All @@ -41,7 +114,7 @@ resource "null_resource" "remote" {
# specify your custom variables here
provisioner "file" {
destination = "/tmp/k6/entrypoint.sh"

content = templatefile(
"${path.module}/entrypoint.sh.tpl",
{
Expand Down Expand Up @@ -99,4 +172,4 @@ resource "null_resource" "remote" {
depends_on = [
aws_instance.k6,
]
}
}
2 changes: 1 addition & 1 deletion examples/storage/image-resize/terraform/k6/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const token = __ENV.ANON_TOKEN
const serviceToken = __ENV.SERVICE_TOKEN
const baseUri = __ENV.BASE_URI
? __ENV.BASE_URI
: 'https://jjqwaskwktqjmyyuqrix.supabase.red'
: 'https://proj.supabase.com'
const authURI = __ENV.AUTH_URI ? __ENV.AUTH_URI : baseUri + '/auth/v1'
const imageResizerURI = __ENV.IMAGE_RESIZER_URI
? __ENV.IMAGE_RESIZER_URI
Expand Down
83 changes: 78 additions & 5 deletions examples/storage/image-resize/terraform/modules/script/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,85 @@
# creating ec2 instance that will be used to generate load
# Most likely you will not need to change it

resource "aws_vpc" "ap-southeast-1" {
enable_dns_support = true
enable_dns_hostnames = true
assign_generated_ipv6_cidr_block = true
cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "ap-southeast-1" {
vpc_id = aws_vpc.ap-southeast-1.id
cidr_block = cidrsubnet(aws_vpc.ap-southeast-1.cidr_block, 4, 1)
map_public_ip_on_launch = true

ipv6_cidr_block = cidrsubnet(aws_vpc.ap-southeast-1.ipv6_cidr_block, 8, 1)
assign_ipv6_address_on_creation = true
}

resource "aws_internet_gateway" "ap-southeast-1" {
vpc_id = aws_vpc.ap-southeast-1.id
}

resource "aws_default_route_table" "ap-southeast-1" {
default_route_table_id = aws_vpc.ap-southeast-1.default_route_table_id

route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.ap-southeast-1.id
}

route {
ipv6_cidr_block = "::/0"
gateway_id = aws_internet_gateway.ap-southeast-1.id
}
}

resource "aws_route_table_association" "ap-southeast-1" {
subnet_id = aws_subnet.ap-southeast-1.id
route_table_id = aws_default_route_table.ap-southeast-1.id
}

resource "aws_security_group" "ap-southeast-1" {
name = "supabench-tf-security-group-${aws_vpc.ap-southeast-1.id}"
vpc_id = aws_vpc.ap-southeast-1.id
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 0
to_port = 0
protocol = "-1"
ipv6_cidr_blocks = ["::/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
ipv6_cidr_blocks = ["::/0"]
}
}

resource "aws_instance" "k6" {
count = var.instances_count

ami = var.ami_id
instance_type = var.instance_type
vpc_security_group_ids = [var.security_group_id]
subnet_id = var.subnet_id
vpc_security_group_ids = ["${aws_security_group.ap-southeast-1.id}"]
subnet_id = aws_subnet.ap-southeast-1.id
ipv6_address_count = 1

key_name = var.key_name

Expand All @@ -28,7 +101,7 @@ resource "null_resource" "remote" {
user = var.instance_user
host = aws_instance.k6[count.index].public_ip
private_key = var.private_key_location
timeout = "1m"
timeout = "5m"
}

# upload k6 scripts to remote instance, you likely won't need to change this part
Expand All @@ -41,7 +114,7 @@ resource "null_resource" "remote" {
# specify your custom variables here
provisioner "file" {
destination = "/tmp/k6/entrypoint.sh"

content = templatefile(
"${path.module}/entrypoint.sh.tpl",
{
Expand Down Expand Up @@ -101,4 +174,4 @@ resource "null_resource" "remote" {
depends_on = [
aws_instance.k6,
]
}
}
17 changes: 17 additions & 0 deletions examples/storage/upload-multipart/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.PHONY: db_test

MAKEFLAGS += -j2

export

conns ?= 1
rampingduration ?= 5
consecutiveduration ?= 60
requests ?= 1
rand = $(shell bash -c 'echo $$RANDOM')
testrun ?= "random-run-$(rand)"

load:
@RAMPING_DURATION=$(rampingduration) CONSECUTIVE_DURATION=$(consecutiveduration) \
REQUESTS=$(requests) CONNS=$(conns) TEST_RUN=$(testrun) ./k6 run load.js \
--tag testrun=$(testrun) --tag system='storage_api' -o 'prometheus=namespace=k6'
51 changes: 51 additions & 0 deletions examples/storage/upload-multipart/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Return a random integer between the minimum (inclusive)
* and maximum (exclusive) values
* @param {number} min - The minimum value to return.
* @param {number} max - The maximum value you want to return.
* @return {number} The random number between the min and max.
*/
export function getRandomInt(min, max) {
min = Math.ceil(min)
max = Math.floor(max)
// The maximum is exclusive and the minimum is inclusive
return Math.floor(Math.random() * (max - min) + min)
}

/**
* Generate default k6 ramping-vus scenario.
* @param {number} baseDuration - Total duration of the scenario.
* @param {number} conns - max number of vus during the scenario execution.
*
* It starts with 0 VUs, ramps up to half the number of connections in 1/12 of total duration then
* it remains on this number for 1/4 of total duration time.
* Then ramps down to a quarter of the number of connections in 1/12 of total duration.
* Then ramps up to the full number of connections in 1/6 of total duration and
* it remains on this number for 1/3 of total duration time.
* Then ramps down to a quarter of the number of connections in 1/12 of total duration,
* then ramps down to 0 VUs in 10s.
*/
export function scenario(rampingDuration, consecutiveDuration, conns) {
return {
executor: 'ramping-vus',
startVUs: 0,
stages: [
{
duration: `${parseInt(rampingDuration)}s`,
target: parseInt(conns),
},
{
duration: `${parseInt(consecutiveDuration)}s`,
target: parseInt(conns),
},
{
duration: '30s',
target: parseInt(conns),
},
],
gracefulRampDown: '10s',
}
}

/* Exporting an array of default summaryTrendStats to be used in summary result. */
export const trends = ['avg', 'med', 'p(99)', 'p(95)', 'p(0.1)', 'count']
Loading

0 comments on commit 10a6475

Please sign in to comment.