Skip to content

Commit 6d5a799

Browse files
author
Ariel Ben-Yehuda
committed
feat: add constructors for agent metadata types
we want to allow adding fields to metadata, which requires making them `non_exhaustive`. However, users do create the metadatas, at least for testing. Add constructors to allow that to be done in a back-compat way.
1 parent 4f6bff3 commit 6d5a799

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/metadata/mod.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,59 @@ pub enum AgentMetadata {
5050
NoMetadata,
5151
}
5252

53+
impl AgentMetadata {
54+
/// Create metadata corresponding to an EC2 instance running on AWS.
55+
///
56+
/// This function is versioned to allow for extensibility.
57+
///
58+
/// ```rust
59+
/// # use async_profiler_agent::metadata::AgentMetadata;
60+
/// let _metadata = AgentMetadata::ec2_agent_metadata_v1(
61+
/// "123456789012".to_string(),
62+
/// "us-east-1".to_string(),
63+
/// "i-1234567890abcdef0".to_string(),
64+
/// );
65+
/// ```
66+
pub fn ec2_agent_metadata_v1(
67+
aws_account_id: String,
68+
aws_region_id: String,
69+
ec2_instance_id: String,
70+
) -> Self {
71+
Self::Ec2AgentMetadata {
72+
aws_account_id,
73+
aws_region_id,
74+
ec2_instance_id,
75+
}
76+
}
77+
78+
/// Create metadata corresponding to a Fargate task running on AWS.
79+
///
80+
/// This function is versioned to allow for extensibility.
81+
///
82+
/// ```rust
83+
/// # use async_profiler_agent::metadata::AgentMetadata;
84+
/// let _metadata = AgentMetadata::fargate_agent_metadata_v1(
85+
/// "123456789012".to_string(),
86+
/// "us-east-1".to_string(),
87+
/// "arn:aws:ecs:us-east-1:123456789012:task/cluster/5261e761e0e2a3d92da3f02c8e5bab1f".to_string(),
88+
/// "arn:aws:ecs:us-east-1:123456789012:cluster/profiler-metadata-cluster".to_string(),
89+
/// );
90+
/// ```
91+
pub fn fargate_agent_metadata_v1(
92+
aws_account_id: String,
93+
aws_region_id: String,
94+
ecs_task_arn: String,
95+
ecs_cluster_arn: String,
96+
) -> Self {
97+
Self::FargateAgentMetadata {
98+
aws_account_id,
99+
aws_region_id,
100+
ecs_task_arn,
101+
ecs_cluster_arn,
102+
}
103+
}
104+
}
105+
53106
/// Metadata associated with a specific individual profiling report
54107
#[derive(Debug, Clone, PartialEq, Eq)]
55108
pub struct ReportMetadata<'a> {

0 commit comments

Comments
 (0)