Skip to content

Commit 8468b50

Browse files
committed
Introduce AWS EC2 metadata instance_life cycle
1 parent 3ab18b4 commit 8468b50

File tree

10 files changed

+99
-30
lines changed

10 files changed

+99
-30
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: processor/resourcedetectionprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Introduce instance life cycle metadata to resourcedetectionprocessor AWS EC2.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [40191]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
As instance life cycle is not part of `cloud` or `host` namespace of semantic conventions,
20+
add it to resource specified namespace `aws.ec2`.
21+
22+
# If your change doesn't affect end users or the exported elements of any package,
23+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
24+
# Optional: The change log or logs in which this entry should be included.
25+
# e.g. '[user]' or '[user, api]'
26+
# Include 'user' if the change is relevant to end users.
27+
# Include 'api' if there is a change to a library API.
28+
# Default: '[user]'
29+
change_logs: [user, api]

internal/metadataproviders/aws/ec2/metadata.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Provider interface {
1616
Get(ctx context.Context) (imds.InstanceIdentityDocument, error)
1717
Hostname(ctx context.Context) (string, error)
1818
InstanceID(ctx context.Context) (string, error)
19+
InstanceLifeCycle(ctx context.Context) (string, error)
1920
}
2021

2122
type metadataClient struct {
@@ -53,6 +54,10 @@ func (c *metadataClient) Hostname(ctx context.Context) (string, error) {
5354
return c.getMetadata(ctx, "hostname")
5455
}
5556

57+
func (c *metadataClient) InstanceLifeCycle(ctx context.Context) (string, error) {
58+
return c.getMetadata(ctx, "instance-life-cycle")
59+
}
60+
5661
func (c *metadataClient) Get(ctx context.Context) (imds.InstanceIdentityDocument, error) {
5762
output, err := c.client.GetInstanceIdentityDocument(ctx, &imds.GetInstanceIdentityDocumentInput{})
5863
if err != nil {

processor/resourcedetectionprocessor/internal/aws/ec2/documentation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
| Name | Description | Values | Enabled |
1010
| ---- | ----------- | ------ | ------- |
11+
| aws.ec2.instance_life_cycle | The EC2 instance life cycle | Any Str | true |
1112
| cloud.account.id | The cloud account id | Any Str | true |
1213
| cloud.availability_zone | The cloud availability zone | Any Str | true |
1314
| cloud.platform | The cloud platform | Any Str | true |

processor/resourcedetectionprocessor/internal/aws/ec2/ec2.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ func (d *Detector) Detect(ctx context.Context) (resource pcommon.Resource, schem
105105
return pcommon.NewResource(), "", fmt.Errorf("failed getting hostname: %w", err)
106106
}
107107

108+
instanceLifeCycle, err := d.metadataProvider.InstanceLifeCycle(ctx)
109+
if err != nil {
110+
return pcommon.NewResource(), "", fmt.Errorf("failed getting instance life cycle: %w", err)
111+
}
112+
113+
d.rb.SetAwsEc2InstanceLifeCycle(instanceLifeCycle)
108114
d.rb.SetCloudProvider(conventions.CloudProviderAWS.Value.AsString())
109115
d.rb.SetCloudPlatform(conventions.CloudPlatformAWSEC2.Value.AsString())
110116
d.rb.SetCloudRegion(meta.Region)

processor/resourcedetectionprocessor/internal/aws/ec2/internal/metadata/generated_config.go

Lines changed: 13 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/resourcedetectionprocessor/internal/aws/ec2/internal/metadata/generated_config_test.go

Lines changed: 21 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/resourcedetectionprocessor/internal/aws/ec2/internal/metadata/generated_resource.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/resourcedetectionprocessor/internal/aws/ec2/internal/metadata/generated_resource_test.go

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/resourcedetectionprocessor/internal/aws/ec2/internal/metadata/testdata/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
default:
22
all_set:
33
resource_attributes:
4+
aws.ec2.instance_life_cycle:
5+
enabled: true
46
cloud.account.id:
57
enabled: true
68
cloud.availability_zone:
@@ -21,6 +23,8 @@ all_set:
2123
enabled: true
2224
none_set:
2325
resource_attributes:
26+
aws.ec2.instance_life_cycle:
27+
enabled: false
2428
cloud.account.id:
2529
enabled: false
2630
cloud.availability_zone:

processor/resourcedetectionprocessor/internal/aws/ec2/metadata.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ type: resourcedetectionprocessor/ec2
33
parent: resourcedetection
44

55
resource_attributes:
6+
aws.ec2.instance_life_cycle:
7+
description: The EC2 instance life cycle
8+
type: string
9+
enabled: true
610
host.name:
711
description: The hostname
812
type: string

0 commit comments

Comments
 (0)