Skip to content

Commit

Permalink
scale
Browse files Browse the repository at this point in the history
  • Loading branch information
nimeshgarg committed May 6, 2024
1 parent cd54af4 commit 6e28675
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 36 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ instance/
__pycache__/

inputs/
outputs/
outputs/

services/
35 changes: 17 additions & 18 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 37 additions & 11 deletions ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ resource "aws_ecs_task_definition" "spamoverflow" {
family = "spamoverflow"
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = 1024
memory = 2048
cpu = 4096
memory = 16384
execution_role_arn = data.aws_iam_role.lab.arn
depends_on = [docker_image.spamoverflow]

container_definitions = <<DEFINITION
[
{
"image": "${docker_registry_image.spamoverflow.name}",
"cpu": 1024,
"memory": 2048,
"cpu": 4096,
"memory": 16384,
"name": "spamoverflow",
"networkMode": "awsvpc",
"portMappings": [
Expand Down Expand Up @@ -50,7 +50,7 @@ resource "aws_ecs_service" "spamoverflow" {
name = "spamoverflow"
cluster = aws_ecs_cluster.spamoverflow.id
task_definition = aws_ecs_task_definition.spamoverflow.arn
desired_count = 1
desired_count = 2
launch_type = "FARGATE"
depends_on = [aws_ecs_task_definition.spamoverflow]

Expand Down Expand Up @@ -78,12 +78,12 @@ resource "aws_security_group" "spamoverflow" {
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# ingress {
# from_port = 22
# to_port = 22
# protocol = "tcp"
# cidr_blocks = ["0.0.0.0/0"]
# }

egress {
from_port = 0
Expand All @@ -92,3 +92,29 @@ resource "aws_security_group" "spamoverflow" {
cidr_blocks = ["0.0.0.0/0"]
}
}

resource "aws_appautoscaling_target" "ecs_target" {
max_capacity = 200
min_capacity = 2
resource_id = "service/${aws_ecs_cluster.spamoverflow.name}/${aws_ecs_service.spamoverflow.name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"

depends_on = [ aws_ecs_service.spamoverflow ]
}

resource "aws_appautoscaling_policy" "ecs_policy" {
name = "cpu20"
policy_type = "TargetTrackingScaling"
resource_id = aws_appautoscaling_target.ecs_target.resource_id
scalable_dimension = aws_appautoscaling_target.ecs_target.scalable_dimension
service_namespace = aws_appautoscaling_target.ecs_target.service_namespace

target_tracking_scaling_policy_configuration {
predefined_metric_specification {
predefined_metric_type = "ECSServiceAverageCPUUtilization"
}

target_value = 20
}
}
30 changes: 30 additions & 0 deletions k6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import http from "k6/http";
import { sleep, check } from "k6";

export const options = {
stages: [
{ target: 5000, duration: "1m" },
// { target: 5000, duration: '10m' },
],
};

export default function () {
const data = {
metadata: {
spamhammer: "1|14",
},
contents: {
subject: "Important information about your account.",
from: "[email protected]",
to: "[email protected]",
body: "Dear customer,\nWe have noticed some suspicious activity on your account. Please click [here](https://scam-check.uq.edu.au?userId=uqehugh3) to reset your password. and https://scam-check.uq.edu.au?userId=uqehugh3",
},
};
const res = http.post(
"http://spamoverflow-1430562822.us-east-1.elb.amazonaws.com:8080/api/v1/customers/111100005412/emails",
JSON.stringify(data),
{ headers: { "Content-Type": "application/json" } }
);
check(res, { "status was 201": (r) => r.status == 201 });
sleep(1);
}
2 changes: 1 addition & 1 deletion local.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Change to the app folder.
# cd app
# cd services/endpoints

# Buildkit to make sure we know what env
export DOCKER_BUILDKIT=1
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
version = "~> 5.0"
}
docker = {
source = "kreuzwerker/docker"
Expand Down
Loading

0 comments on commit 6e28675

Please sign in to comment.