Skip to content
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
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: CI

on:
push:
pull_request:

concurrency:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
__pycache__/
*.pyc
11 changes: 0 additions & 11 deletions .idea/ChatSystem.iml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

105 changes: 0 additions & 105 deletions .idea/workspace.xml

This file was deleted.

3 changes: 0 additions & 3 deletions ApiServer/.idea/.gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions ApiServer/.idea/ApiServer.iml

This file was deleted.

6 changes: 0 additions & 6 deletions ApiServer/.idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

7 changes: 0 additions & 7 deletions ApiServer/.idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions ApiServer/.idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions ApiServer/.idea/vcs.xml

This file was deleted.

Binary file removed ApiServer/__pycache__/main.cpython-314.pyc
Binary file not shown.
Binary file removed ApiServer/app/__pycache__/__init__.cpython-314.pyc
Binary file not shown.
Binary file not shown.
Binary file removed ApiServer/app/__pycache__/config.cpython-314.pyc
Binary file not shown.
Binary file removed ApiServer/app/__pycache__/database.cpython-314.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed ApiServer/app/schemas/__pycache__/token.cpython-314.pyc
Binary file not shown.
Binary file not shown.
13 changes: 12 additions & 1 deletion ApiServer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import sys
from contextlib import asynccontextmanager

from fastapi import FastAPI
from aws_xray_sdk.core import xray_recorder
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from sqlalchemy import text

Expand Down Expand Up @@ -48,6 +49,16 @@ async def lifespan(app: FastAPI):

app = FastAPI(title="ChatSystem API", lifespan=lifespan)


@app.middleware("http")
async def xray_middleware(request: Request, call_next):
xray_recorder.begin_segment(f"{request.method} {request.url.path}")
try:
return await call_next(request)
finally:
xray_recorder.end_segment()


app.add_middleware(
CORSMiddleware,
allow_origins=settings.cors_origins_list,
Expand Down
1 change: 1 addition & 0 deletions ApiServer/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
annotated-doc==0.0.4
aws-xray-sdk
annotated-types==0.7.0
anyio==4.13.0
asyncpg==0.31.0
Expand Down
Binary file removed ApiServer/tests/__pycache__/__init__.cpython-314.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions ChatInfra/environments/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ module "ecs_services" {
execution_role_chatserver_arn = module.ecs.execution_role_chatserver_arn
execution_role_presenceserver_arn = module.ecs.execution_role_presenceserver_arn
chatserver_task_role_arn = module.ecs.chatserver_task_role_arn
apiserver_task_role_arn = module.ecs.apiserver_task_role_arn
presenceserver_task_role_arn = module.ecs.presenceserver_task_role_arn
private_subnet_ids = module.vpc.private_subnets
ecs_tasks_sg_id = module.security_groups.ecs_tasks_sg_id
chatserver_nlb_dns_name = module.alb.chatserver_nlb_dns_name
Expand All @@ -92,5 +94,8 @@ module "ecs_services" {
apiserver_log_group = module.ecs.apiserver_log_group
chatserver_log_group = module.ecs.chatserver_log_group
presenceserver_log_group = module.ecs.presenceserver_log_group
apiserver_xray_log_group = module.ecs.apiserver_xray_log_group
chatserver_xray_log_group = module.ecs.chatserver_xray_log_group
presenceserver_xray_log_group = module.ecs.presenceserver_xray_log_group
cloudfront_domain = module.static_site.cloudfront_domain
}
123 changes: 123 additions & 0 deletions ChatInfra/modules/ecs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,126 @@ resource "aws_iam_role_policy" "chatserver_sqs" {
}]
})
}

resource "aws_iam_role_policy" "chatserver_xray" {
name = "${var.project_name}-chatserver-xray"
role = aws_iam_role.chatserver_task.id

policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Action = [
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets",
"xray:GetSamplingStatisticSummaries",
]
Resource = "*"
}]
})
}

# --- ApiServer task role ---

resource "aws_iam_role" "apiserver_task" {
name = "${var.project_name}-apiserver-task"

assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = { Service = "ecs-tasks.amazonaws.com" }
Action = "sts:AssumeRole"
Condition = {
ArnLike = {
"aws:SourceArn" = "arn:aws:ecs:${var.region}:${data.aws_caller_identity.current.account_id}:*"
}
StringEquals = {
"aws:SourceAccount" = data.aws_caller_identity.current.account_id
}
}
}]
})
}

resource "aws_iam_role_policy" "apiserver_xray" {
name = "${var.project_name}-apiserver-xray"
role = aws_iam_role.apiserver_task.id

policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Action = [
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets",
"xray:GetSamplingStatisticSummaries",
]
Resource = "*"
}]
})
}

# --- PresenceServer task role ---

resource "aws_iam_role" "presenceserver_task" {
name = "${var.project_name}-presenceserver-task"

assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = { Service = "ecs-tasks.amazonaws.com" }
Action = "sts:AssumeRole"
Condition = {
ArnLike = {
"aws:SourceArn" = "arn:aws:ecs:${var.region}:${data.aws_caller_identity.current.account_id}:*"
}
StringEquals = {
"aws:SourceAccount" = data.aws_caller_identity.current.account_id
}
}
}]
})
}

resource "aws_iam_role_policy" "presenceserver_xray" {
name = "${var.project_name}-presenceserver-xray"
role = aws_iam_role.presenceserver_task.id

policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Action = [
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets",
"xray:GetSamplingStatisticSummaries",
]
Resource = "*"
}]
})
}

# --- X-Ray daemon log groups ---

resource "aws_cloudwatch_log_group" "apiserver_xray" {
name = "/ecs/${var.project_name}/apiserver-xray"
retention_in_days = 365
}

resource "aws_cloudwatch_log_group" "chatserver_xray" {
name = "/ecs/${var.project_name}/chatserver-xray"
retention_in_days = 365
}

resource "aws_cloudwatch_log_group" "presenceserver_xray" {
name = "/ecs/${var.project_name}/presenceserver-xray"
retention_in_days = 365
}
Loading
Loading