async_profiler_agent/metadata/mod.rs
1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! This module includes ways to get metadata attached to profiling reports.
5
6pub use std::time::Duration;
7
8/// Host Metadata, which describes a host that runs a profiling agent. The current set of supported agent metadata is
9/// AWS-specific. If you are not running on AWS, you can use [AgentMetadata::NoMetadata].
10#[derive(Debug, Clone, PartialEq, Eq)]
11#[non_exhaustive]
12pub enum AgentMetadata {
13 /// Metadata for an [EC2] instance running on AWS
14 ///
15 /// [EC2]: https://aws.amazon.com/ec2
16 Ec2AgentMetadata {
17 /// The AWS account id
18 aws_account_id: String,
19 /// The AWS region id
20 aws_region_id: String,
21 /// The EC2 instance id
22 ec2_instance_id: String,
23 },
24 /// Metadata for a [Fargate] task running on AWS.
25 ///
26 /// [Fargate]: https://aws.amazon.com/fargate
27 FargateAgentMetadata {
28 /// The AWS account id
29 aws_account_id: String,
30 /// The AWS region id
31 aws_region_id: String,
32 /// The ECS task ARN
33 ///
34 /// For example, `arn:aws:ecs:us-east-1:123456789012:task/profiler-metadata-cluster/5261e761e0e2a3d92da3f02c8e5bab1f`
35 ///
36 /// See the ECS documentation for more details
37 ecs_task_arn: String,
38 /// The ECS cluster ARN
39 ///
40 /// For example, `arn:aws:ecs:us-east-1:123456789012:cluster/profiler-metadata-cluster`
41 ///
42 /// See the ECS documentation for more details
43 ecs_cluster_arn: String,
44 },
45 /// Metadata for a host that is neither an EC2 nor a Fargate
46 #[deprecated = "Use AgentMetadata::NoMetadata"]
47 Other,
48 /// A placeholder when a host has no metadata, or when a reporter does not
49 /// use metadata.
50 NoMetadata,
51}
52
53/// Metadata associated with a specific individual profiling report
54#[derive(Debug, Clone, PartialEq, Eq)]
55pub struct ReportMetadata<'a> {
56 /// The host running the agent
57 pub instance: &'a AgentMetadata,
58 /// The start time of the profiling report, as a duration from the process start
59 pub start: Duration,
60 /// The end time of the profiling report, as a duration from the process start
61 pub end: Duration,
62 /// The desired reporting interval (on average, this should be
63 /// approximately the same as `self.end - self.start`).
64 pub reporting_interval: Duration,
65}
66
67#[cfg(feature = "aws-metadata-no-defaults")]
68pub mod aws;
69
70/// [private] dummy metadata to make testing easier
71#[cfg(test)]
72pub(crate) const DUMMY_METADATA: ReportMetadata<'static> = ReportMetadata {
73 instance: &AgentMetadata::NoMetadata,
74 start: Duration::from_secs(1),
75 end: Duration::from_secs(2),
76 reporting_interval: Duration::from_secs(1),
77};