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

feat: Add table to CloudWatch dashboard to show deployed images #328

Merged
merged 2 commits into from
Feb 7, 2025
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
36 changes: 32 additions & 4 deletions monitoring/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,34 @@ resource "aws_cloudwatch_dashboard" "compute" {
y : 0,
x : 0,
type : "log",
properties : {
query : "SOURCE '/aws/ecs/containerinsights/${var.application}-${var.environment}/performance' | fields fromMillis(Timestamp) as Time, ClusterName as Cluster, TaskDefinitionFamily as Service, ContainerName as Container, Image\n| filter @message like 'application:'\n| sort Cluster, Service, Container\n| dedup Service, Container",
region : "eu-west-2",
stacked : false,
title : "Deployed Application Images",
view : "table"
}
},
{
height : 7,
width : 24,
y : 7,
x : 0,
type : "log",
properties : {
query : "SOURCE '/aws/ecs/containerinsights/${var.application}-${var.environment}/performance' | fields fromMillis(Timestamp) as Time, ClusterName as Cluster, TaskDefinitionFamily as Service, ContainerName as Container, Image\n| filter @message like '\"Image\":'\n| filter @message not like 'application:'\n| sort Cluster, Service, Container\n| dedup Service, Container",
region : "eu-west-2",
stacked : false,
title : "Deployed Sidecar Images",
view : "table"
}
},
{
height : 7,
width : 24,
y : 14,
x : 0,
type : "log",
properties : {
query : "SOURCE '/aws/ecs/containerinsights/${var.application}-${var.environment}/performance' | fields @message\n| filter Type=\"Task\"\n| filter @logStream like /FargateTelemetry/\n| stats latest(TaskDefinitionFamily) as TaskDefFamily, \n latest(TaskDefinitionRevision) as Rev, \n max(CpuReserved) as TaskCpuReserved, \n avg(CpuUtilized) as AvgCpuUtilized, \n concat(ceil(avg(CpuUtilized) * 100 / TaskCpuReserved),\" %\") as AvgCpuUtilizedPerc, \n max(CpuUtilized) as PeakCpuUtilized, \n concat(ceil(max(CpuUtilized) * 100 / TaskCpuReserved),\" %\") as PeakCpuUtilizedPerc, \n max(MemoryReserved) as TaskMemReserved, \n ceil(avg(MemoryUtilized)) as AvgMemUtilized, \n concat(ceil(avg(MemoryUtilized) * 100 / TaskMemReserved),\" %\") as AvgMemUtilizedPerc, \n max(MemoryUtilized) as PeakMemUtilized, \n concat(ceil(max(MemoryUtilized) * 100 / TaskMemReserved),\" %\") as PeakMemUtilizedPerc \n by TaskId\n| sort TaskDefFamily asc\n",
region : "eu-west-2",
Expand All @@ -19,7 +47,7 @@ resource "aws_cloudwatch_dashboard" "compute" {
{
height : 6,
width : 15,
y : 7,
y : 21,
x : 0,
type : "log",
properties : {
Expand All @@ -32,7 +60,7 @@ resource "aws_cloudwatch_dashboard" "compute" {
{
height : 6,
width : 15,
y : 13,
y : 27,
x : 0,
type : "log",
properties : {
Expand All @@ -45,7 +73,7 @@ resource "aws_cloudwatch_dashboard" "compute" {
{
height : 6,
width : 9,
y : 7,
y : 21,
x : 15,
type : "log",
properties : {
Expand All @@ -59,7 +87,7 @@ resource "aws_cloudwatch_dashboard" "compute" {
{
height : 6,
width : 9,
y : 13,
y : 27,
x : 15,
type : "log",
properties : {
Expand Down
20 changes: 15 additions & 5 deletions monitoring/tests/unit.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,37 @@ run "test_compute_dashboard_is_created" {
# Test widgets are created
# Not checking the whole queries as we would just have to replicate the code from the manifest, which would not add much value, so we're just going to check that the expected widgets exist.
assert {
condition = jsondecode(aws_cloudwatch_dashboard.compute.dashboard_body).widgets[0].properties.title == "All Fargate Tasks Configuration and Consumption Details (CPU and Memory)"
condition = jsondecode(aws_cloudwatch_dashboard.compute.dashboard_body).widgets[0].properties.title == "Deployed Application Images"
error_message = "Deployed Application Images widget is not created"
}

assert {
condition = jsondecode(aws_cloudwatch_dashboard.compute.dashboard_body).widgets[1].properties.title == "Deployed Sidecar Images"
error_message = "Deployed Sidecar Images widget is not created"
}

assert {
condition = jsondecode(aws_cloudwatch_dashboard.compute.dashboard_body).widgets[2].properties.title == "All Fargate Tasks Configuration and Consumption Details (CPU and Memory)"
error_message = "Configuration and Consumption Details (CPU and Memory) widget is not created"
}

assert {
condition = jsondecode(aws_cloudwatch_dashboard.compute.dashboard_body).widgets[1].properties.title == "Top 10 Fargate Tasks with Optimization Opportunities (CPU)"
condition = jsondecode(aws_cloudwatch_dashboard.compute.dashboard_body).widgets[3].properties.title == "Top 10 Fargate Tasks with Optimization Opportunities (CPU)"
error_message = "Optimization Opportunities (CPU) widget is not created"
}

assert {
condition = jsondecode(aws_cloudwatch_dashboard.compute.dashboard_body).widgets[2].properties.title == "Top 10 Fargate Tasks with Optimization Opportunities (Memory)"
condition = jsondecode(aws_cloudwatch_dashboard.compute.dashboard_body).widgets[4].properties.title == "Top 10 Fargate Tasks with Optimization Opportunities (Memory)"
error_message = "Optimization Opportunities (Memory) widget is not created"
}

assert {
condition = jsondecode(aws_cloudwatch_dashboard.compute.dashboard_body).widgets[3].properties.title == "CPU Reserved Vs Avg Usage (All Fargate Tasks)"
condition = jsondecode(aws_cloudwatch_dashboard.compute.dashboard_body).widgets[5].properties.title == "CPU Reserved Vs Avg Usage (All Fargate Tasks)"
error_message = "CPU Reserved Vs Avg Usage widget is not created"
}

assert {
condition = jsondecode(aws_cloudwatch_dashboard.compute.dashboard_body).widgets[4].properties.title == "Memory Reserved Vs Avg Usage (All Fargate Tasks)"
condition = jsondecode(aws_cloudwatch_dashboard.compute.dashboard_body).widgets[6].properties.title == "Memory Reserved Vs Avg Usage (All Fargate Tasks)"
error_message = "Memory Reserved Vs Avg Usage widget is not created"
}
}
Expand Down
Loading