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

Benchmark env #631

Merged
merged 4 commits into from
Sep 29, 2020
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
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,20 @@ gateway/testdata/recordings/

# Docs
/docs/_site/

# terraform
# Local .terraform directories
**/.terraform/*
# .tfstate files
*.tfstate
*.tfstate.*
# Crash log files
crash.log
# Exclude all .tfvars files, which are likely to contain sentitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
# Ignore CLI configuration files
.terraformrc
terraform.rc
55 changes: 55 additions & 0 deletions benchmarks/terraform/lb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# ALB Security Group: Edit to restrict access to the application
resource "aws_security_group" "aws-lb" {
name = "benchmark-load-balancer"
description = "Controls access to the ALB"
vpc_id = aws_security_group.benchmark_sg.vpc_id

ingress {
protocol = "tcp"
from_port = 8000
to_port = 8000
cidr_blocks = [for s in data.aws_subnet.all : s.cidr_block]
}

egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "benchmark-load-balancer"
}
}

resource "aws_alb" "main" {
name = "benchmark-load-balancer"
subnets = [for s in data.aws_subnet.all : s.id]
security_groups = [aws_security_group.aws-lb.id]
internal = true
tags = {
Name = "benchmark-alb"
}
}

resource "aws_alb_target_group" "benchmark" {
name = "benchmark-target-group"
port = 8000
protocol = "HTTP"
vpc_id = aws_security_group.benchmark_sg.vpc_id
target_type = "ip"
tags = {
Name = "benchmark-alb-target-group"
}
}

# Redirect all traffic from the ALB to the target group
resource "aws_alb_listener" "benchmark" {
load_balancer_arn = aws_alb.main.id
port = 8000
protocol = "HTTP"
default_action {
target_group_arn = aws_alb_target_group.benchmark.id
type = "forward"
}
}
238 changes: 238 additions & 0 deletions benchmarks/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
variable "password" {
type = string
description = "The password to the postgres DB."
}

variable "dockerReg" {
type = string
description = "docker registry to pull the image from"
}

variable "tag" {
type = string
description = "lakeFS docker image tag"
}

provider "aws" {
region = "us-east-1"
}

//##############################################################
//# Data sources to get VPC, subnets and security group details
//##############################################################
data "aws_subnet_ids" "all" {
vpc_id = "vpc-04b176d1264698ffc"
tags = {"Type":"private"}
itaiad200 marked this conversation as resolved.
Show resolved Hide resolved
}

data "aws_subnet" "all" {
for_each = data.aws_subnet_ids.all.ids
id = each.value
}

data "aws_ami" "ubuntu" {
most_recent = true

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = ["099720109477"] # Canonical
}

data "aws_arn" "BENCHMARK_VM" {
arn = "arn:aws:iam::977611293394:role/BENCHMARK_VM"
}

//##############################################################
//# Resources to create sg, postgres db, and Fargate service
//##############################################################
resource "aws_security_group" "benchmark_sg" {
name = "benchmark_sg-${var.tag}"
description = "Allow benchmark traffic"
vpc_id = "vpc-04b176d1264698ffc"

ingress {
description = "postgres"
from_port = 5432
to_port = 5432
protocol = "tcp"
cidr_blocks = [for s in data.aws_subnet.all : s.cidr_block]
}

ingress {
description = "lakeFS"
from_port = 8000
to_port = 8000
protocol = "tcp"
cidr_blocks = [for s in data.aws_subnet.all : s.cidr_block]
}

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

tags = {
Name = "allow_benchmark"
}
}

#####
# DB
#####
module "db" {
source = "github.com/terraform-aws-modules/terraform-aws-rds"

identifier = "benchmarks-postgres-${var.tag}"

engine = "postgres"
engine_version = "11"
instance_class = "db.t2.medium"
allocated_storage = 5
storage_encrypted = false

name = "BenchmarksDB"

# Do NOT use 'user' as the value for 'username' as it throws:
# "Error creating DB Instance: InvalidParameterValue: MasterUsername
# user cannot be used as it is a reserved word used by the engine"
username = "benchmarks"

password = var.password
port = "5432"

vpc_security_group_ids = [aws_security_group.benchmark_sg.id]

maintenance_window = "Mon:00:00-Mon:03:00"
backup_window = "03:00-06:00"

# disable backups to create DB faster
backup_retention_period = 0

enabled_cloudwatch_logs_exports = ["postgresql", "upgrade"]

# DB subnet group
subnet_ids = data.aws_subnet_ids.all.ids

# DB parameter group
family = "postgres11"

# DB option group
major_engine_version = "11"

# Snapshot name upon DB deletion
final_snapshot_identifier = "demodb"

# Database Deletion Protection
deletion_protection = false
}

resource "random_string" "default" {
length = 16
}

resource "aws_launch_configuration" "benchmark" {
name = "benchmark-launch-${var.tag}"
image_id = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
}

resource "aws_autoscaling_group" "benchmark" {
vpc_zone_identifier = [for s in data.aws_subnet.all : s.id]
min_size = 1
max_size = 1
launch_configuration = aws_launch_configuration.benchmark.id

tag {
key = "AmazonECSManaged"
value = "true"
propagate_at_launch = true
}
}

resource "aws_ecs_cluster" "benchmark" {
name = "benchmark-${var.tag}"
capacity_providers = ["FARGATE"]
}

resource "aws_cloudwatch_log_group" "benchmark" {
name = "/ecs/benchmark/${var.tag}"

tags = {
Benchmark = var.tag
}
}

resource "aws_ecs_task_definition" "benchmark" {
family = "benchmark-${var.tag}"
requires_compatibilities = ["FARGATE"]
cpu = "2048"
memory = "8192"
network_mode = "awsvpc"
execution_role_arn = data.aws_arn.BENCHMARK_VM.arn
itaiad200 marked this conversation as resolved.
Show resolved Hide resolved
task_role_arn = data.aws_arn.BENCHMARK_VM.arn

container_definitions = <<TASK_DEFINITION
[
{
"name": "lakeFS",
"image": "${var.dockerReg}/lakefs:${var.tag}",
"entryPoint": ["/app/lakefs", "run"],
"environment": [
{"name": "LAKEFS_AUTH_ENCRYPT_SECRET_KEY", "value": "${random_string.default.result}"},
{"name": "LAKEFS_DATABASE_CONNECTION_STRING", "value": "postgres://benchmarks:${var.password}@${module.db.this_db_instance_endpoint}/postgres?sslmode=disable"},
{"name": "LAKEFS_BLOCKSTORE_TYPE", "value": "s3"},
{"name": "LAKEFS_LOGGING_LEVEL", "value": "DEBUG"}
],
"essential": true,
"cpu": 2048,
"memory": 8192,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/benchmark/${var.tag}",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ecs"
}
},
"portMappings": [
itaiad200 marked this conversation as resolved.
Show resolved Hide resolved
{
"containerPort": 8000,
"hostPort": 8000
}
]
}
]
TASK_DEFINITION
}

resource "aws_ecs_service" "lakefs" {
name = "lakeFS-${var.tag}"
cluster = aws_ecs_cluster.benchmark.id
task_definition = aws_ecs_task_definition.benchmark.id
desired_count = 1
launch_type = "FARGATE"

network_configuration {
subnets = [for s in data.aws_subnet.all : s.id]
assign_public_ip = false
security_groups = [ aws_security_group.benchmark_sg.id ]
}

load_balancer {
target_group_arn = aws_alb_target_group.benchmark.id
container_name = "lakeFS"
container_port = 8000
}
depends_on = [aws_alb_listener.benchmark]
}

Loading