Skip to content

Commit

Permalink
chore: misc (#24)
Browse files Browse the repository at this point in the history
* chore: misc changes

* chore: remove noise in migrations

* chore: print flyway logs

* chore: remove load tests

* fix: log trailing

* fix: pause resource cron
  • Loading branch information
mishraomp authored Dec 23, 2024
1 parent a967ad3 commit 872b806
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 19 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,4 @@ jobs:
npm run deploy
aws s3 sync --delete ./dist s3://$(echo "$S3_BUCKET_ARN" | cut -d: -f6)
aws cloudfront create-invalidation --distribution-id $CF_DISTRIBUTION_ID --paths "/*"
load-test:
needs: [deploy-api, build-ui, deploy-cloudfront]
name: Load Test
uses: ./.github/workflows/.load-test.yml
with:
BACKEND_URL: ${{ needs.deploy-api.outputs.API_GW_URL }}/api
FRONTEND_URL: https://${{ needs.deploy-cloudfront.outputs.CF_DOMAIN }}
2 changes: 1 addition & 1 deletion .github/workflows/pause-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Pause AWS Resources

on:
schedule:
- cron: "0 2 * * 1-5" # Runs every day at 6PM PST, Monday to Friday
- cron: "0 2 * * 2-6" # Runs every day at 6PM PST, Monday to Friday
workflow_dispatch:
permissions:
id-token: write # This is required for requesting the JWT
Expand Down
3 changes: 2 additions & 1 deletion backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ function getMiddlewares() {
prismaOptions:{
log: ["error", "warn"],
errorFormat: "pretty",
datasourceUrl: `postgresql://${DB_USER}:${DB_PWD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?schema=${DB_SCHEMA}&connection_limit=5`,
//https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/databases-connections/connection-pool#connection-pool-timeout
datasourceUrl: `postgresql://${DB_USER}:${DB_PWD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?schema=${DB_SCHEMA}&connection_limit=5&pool_timeout=60`,
},
middlewares: getMiddlewares(),
},
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/api/alb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resource "aws_alb_target_group" "app" {

health_check {
healthy_threshold = "2"
interval = "5"
interval = "30"
protocol = "HTTP"
matcher = "200"
timeout = "3"
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/api/autoscaling.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ resource "aws_appautoscaling_policy" "api_up" {

step_adjustment {
metric_interval_lower_bound = 0
scaling_adjustment = 1
scaling_adjustment = 2 # Increase by 2, aggressive scaling
}
}

Expand Down
16 changes: 16 additions & 0 deletions infrastructure/api/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ resource "aws_ecs_task_definition" "flyway_task" {
task_status=$(aws ecs describe-tasks --cluster ${aws_ecs_cluster.ecs_cluster.id} --tasks $task_arn --query 'tasks[0].lastStatus' --output text)
echo "Flyway task status: $task_status at $(date)."
log_stream_name=$(aws logs describe-log-streams \
--log-group-name "/ecs/${var.app_name}/flyway" \
--order-by "LastEventTime" \
--descending \
--limit 1 \
--query 'logStreams[0].logStreamName' \
--output text)
echo "Fetching logs from log stream: $log_stream_name"
aws logs get-log-events \
--log-group-name "/ecs/${var.app_name}/flyway" \
--log-stream-name $log_stream_name \
--limit 1000 \
--no-cli-pager
EOF
}
}
Expand Down
17 changes: 16 additions & 1 deletion infrastructure/api/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,22 @@ variable "min_capacity" {
}
variable "max_capacity" {
type = number
default = 3
default = 5
description = <<EOT
The maximum number of tasks to run, please consider,
connection pooling and other factors when setting this value,
also depends on aurora v2 scaling params
follow this link,
https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-serverless-v2.setting-capacity.html#aurora-serverless-v2.parameter-groups
The max_connections value for Aurora Serverless v2DB instances is based on the memory size
derived from the maximum ACUs.
However, when you specify a minimum capacity of 0 or 0.5 ACUs on PostgreSQL-compatible DB instances,
the maximum value of max_connections is capped at 2,000.
In most cases, 0.5 min and 1 max ACU does the work, which means scaling can be upto 189 max connections,
API contianer has 5 connections per task, so 189/5 = 37 tasks.
if going beyond 37 tasks, consider increasing the max acu from 1 to 2.
EOT
}
## ECR Variables

Expand Down
4 changes: 2 additions & 2 deletions migrations/sql/V1.0.0__init.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
CREATE SCHEMA IF NOT EXISTS ${flyway:defaultSchema};
SET SEARCH_PATH TO ${flyway:defaultSchema};
CREATE EXTENSION IF NOT EXISTS "postgis";
CREATE SEQUENCE IF NOT EXISTS "USER_SEQ"
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 100;
CACHE 1;

CREATE TABLE IF NOT EXISTS USERS
(
Expand All @@ -21,4 +22,3 @@ VALUES ('John', 'John.ipsum@test.com'),
('Jack', 'Jack.ipsum@test.com'),
('Jill', 'Jill.ipsum@test.com'),
('Joe', 'Joe.ipsum@test.com');

2 changes: 0 additions & 2 deletions migrations/sql/V1.0.1__alter_user_seq.sql

This file was deleted.

2 changes: 0 additions & 2 deletions migrations/sql/V1.0.2__postgis.sql

This file was deleted.

0 comments on commit 872b806

Please sign in to comment.