Skip to content

Commit 316cc48

Browse files
rcohClaude
andcommitted
fix: Include CPU and memory limits in Fargate metadata
- Add FargateTaskLimits struct to capture CPU and memory from metadata endpoint - Include task_cpu and task_memory fields in FargateAgentMetadata - Update metadata conversion to pass resource limits to backend - Remove Eq derive from structs containing f64 (CPU values) - Fix pattern matches and tests to handle new fields This fixes the profiler backend showing 'aws_fargate_0.0vcpu_0mb' instead of actual resource allocation like 'aws_fargate_0.25vcpu_2048mb'. Co-authored-by: Claude <claude@anthropic.com>
1 parent 5b65034 commit 316cc48

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/metadata/aws.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,22 @@ async fn read_ec2_metadata() -> Result<ImdsEc2InstanceMetadata, AwsProfilerMetad
8080
Ok(serde_json::from_str(imds_document.as_ref())?)
8181
}
8282

83-
#[derive(Deserialize, Debug, PartialEq, Eq)]
83+
#[derive(Deserialize, Debug, PartialEq)]
84+
struct FargateTaskLimits {
85+
#[serde(rename = "CPU")]
86+
cpu: f64,
87+
#[serde(rename = "Memory")]
88+
memory: u64,
89+
}
90+
91+
#[derive(Deserialize, Debug, PartialEq)]
8492
struct FargateMetadata {
8593
#[serde(rename = "Cluster")]
8694
cluster: String,
8795
#[serde(rename = "TaskARN")]
8896
task_arn: String,
97+
#[serde(rename = "Limits")]
98+
limits: FargateTaskLimits,
8999
}
90100

91101
async fn read_fargate_metadata(
@@ -144,6 +154,8 @@ impl super::AgentMetadata {
144154
.to_string(),
145155
ecs_task_arn: fargate_metadata.task_arn,
146156
ecs_cluster_arn: fargate_metadata.cluster,
157+
task_cpu: fargate_metadata.limits.cpu,
158+
task_memory: fargate_metadata.limits.memory,
147159
})
148160
}
149161
}
@@ -327,6 +339,10 @@ mod tests {
327339
cluster: "arn:aws:ecs:us-east-1:123456789012:cluster/profiler-metadata-cluster"
328340
.to_owned(),
329341
task_arn: "arn:aws:ecs:us-east-1:123456789012:task/profiler-metadata-cluster/5261e761e0e2a3d92da3f02c8e5bab1f".to_owned(),
342+
limits: FargateTaskLimits {
343+
cpu: 0.25,
344+
memory: 2048,
345+
},
330346
}
331347
);
332348

@@ -339,6 +355,8 @@ mod tests {
339355
aws_region_id: "us-east-1".to_owned(),
340356
ecs_task_arn: "arn:aws:ecs:us-east-1:123456789012:task/profiler-metadata-cluster/5261e761e0e2a3d92da3f02c8e5bab1f".to_owned(),
341357
ecs_cluster_arn: "arn:aws:ecs:us-east-1:123456789012:cluster/profiler-metadata-cluster".to_owned(),
358+
task_cpu: 0.25,
359+
task_memory: 2048,
342360
}
343361
)
344362
}

src/metadata/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub use std::time::Duration;
77

88
/// Host Metadata, which describes a host that runs a profiling agent. The current set of supported agent metadata is
99
/// AWS-specific. If you are not running on AWS, you can use [AgentMetadata::NoMetadata].
10-
#[derive(Debug, Clone, PartialEq, Eq)]
10+
#[derive(Debug, Clone, PartialEq)]
1111
#[non_exhaustive]
1212
pub enum AgentMetadata {
1313
/// Metadata for an [EC2] instance running on AWS
@@ -41,6 +41,10 @@ pub enum AgentMetadata {
4141
///
4242
/// See the ECS documentation for more details
4343
ecs_cluster_arn: String,
44+
/// The task CPU allocation in vCPUs
45+
task_cpu: f64,
46+
/// The task memory allocation in MiB
47+
task_memory: u64,
4448
},
4549
/// Metadata for a host that is neither an EC2 nor a Fargate
4650
#[deprecated = "Use AgentMetadata::NoMetadata"]
@@ -51,7 +55,7 @@ pub enum AgentMetadata {
5155
}
5256

5357
/// Metadata associated with a specific individual profiling report
54-
#[derive(Debug, Clone, PartialEq, Eq)]
58+
#[derive(Debug, Clone, PartialEq)]
5559
pub struct ReportMetadata<'a> {
5660
/// The host running the agent
5761
pub instance: &'a AgentMetadata,

src/reporter/s3.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ fn make_s3_file_name(
141141
aws_region_id: _,
142142
ecs_task_arn,
143143
ecs_cluster_arn: _,
144+
..
144145
} => {
145146
let task_arn = ecs_task_arn.replace("/", "-").replace("_", "-");
146147
format!("ecs_{task_arn}_")
@@ -265,7 +266,9 @@ mod test {
265266
aws_account_id: "1".into(),
266267
aws_region_id: "us-east-1".into(),
267268
ecs_task_arn: "arn:aws:ecs:us-east-1:123456789012:task/profiler-metadata-cluster/5261e761e0e2a3d92da3f02c8e5bab1f".into(),
268-
ecs_cluster_arn: "arn:aws:ecs:us-east-1:123456789012:cluster/profiler-metadata-cluster".into()
269+
ecs_cluster_arn: "arn:aws:ecs:us-east-1:123456789012:cluster/profiler-metadata-cluster".into(),
270+
task_cpu: 0.25,
271+
task_memory: 2048,
269272
}, "profile_pg_ecs_arn:aws:ecs:us-east-1:123456789012:task-profiler-metadata-cluster-5261e761e0e2a3d92da3f02c8e5bab1f__<pid>_<time>.zip"; "ecs")]
270273
fn test_make_s3_file_name(metadata: AgentMetadata, expected: &str) {
271274
let file_name = super::make_s3_file_name(&metadata, "pg", SystemTime::UNIX_EPOCH);

0 commit comments

Comments
 (0)