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

Retrieve instance tags at the same time to reduce number of entities in Explore related experience #1474

Merged
merged 13 commits into from
Dec 19, 2024

Conversation

nathalapooja
Copy link
Contributor

@nathalapooja nathalapooja commented Dec 17, 2024

Description of the issue

Describe the problem or feature in addition to a link to the issues.
Currently we have two separate threads for reading the AutoScalingGroup tag and the service name tags (service, application, or app). This causes different entities to be created as a result which can be confusing for the customer. We should have a single thread (and retryer) to retrieve all tags needed for entity population for the Explore related experience.

Description of changes

How does this change address the problem?
Implementation

We get the ASG + Service Name + all tags on init
Get all tags on an interval together until success

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Tests

Describe what tests you have done.
Unit Tests
Manual Tests
Before enabling the instance metadata tags

Field	Value
@entity.Attributes.AWS.ServiceNameSource	ClientIamRole
@entity.Attributes.EC2.InstanceId	i-0b6fe6aab9e76873b
@entity.Attributes.PlatformType	AWS::EC2
@entity.KeyAttributes.Environment	ec2:default
@entity.KeyAttributes.Name	ec2-compass-iam-role
@entity.KeyAttributes.Type	Service
@ingestionTime	1734465217411
@log	957688854012:agent_log_group
@logStream	agent_log_stream
@message	2024-12-17T19:53:35Z D! [logagent] open file count, 1
@timestamp	1734465216354

After enabling the instance metadata tags

Field	Value
@entity.Attributes.AWS.ServiceNameSource	ResourceTags
@entity.Attributes.EC2.AutoScalingGroup	asg-compass
@entity.Attributes.EC2.InstanceId	i-0b6fe6aab9e76873b
@entity.Attributes.PlatformType	AWS::EC2
@entity.KeyAttributes.Environment	ec2:asg-compass
@entity.KeyAttributes.Name	poojardy_test_app
@entity.KeyAttributes.Type	Service
@ingestionTime	1734465495685
@log	957688854012:agent_log_group
@logStream	agent_log_stream
@message	2024-12-17T19:58:14Z D! [logagent] open file count, 1
@timestamp	1734465495195

Agents unlimited retried until successful retrieval of tags based of BackOffSleepArray. Stopped retying after first success
BackoffSleepArray = []time.Duration{0, 1 * time.Minute, 1 * time.Minute, 3 * time.Minute, 3 * time.Minute, 3 * time.Minute, 10 * time.Minute}

[ec2-user@ip-172-31-6-118 ~]$ sudo cat /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log | grep "Scraping"
2024-12-17T19:16:39Z I! {"caller":"entitystore/serviceprovider.go:248","msg":"Scraping IMDS for service name and AutoScalingGroup","kind":"extension","name":"entitystore"}
2024-12-17T19:16:39Z I! {"caller":"entitystore/serviceprovider.go:248","msg":"Scraping IMDS for service name and AutoScalingGroup","kind":"extension","name":"entitystore"}
2024-12-17T19:17:39Z I! {"caller":"entitystore/serviceprovider.go:248","msg":"Scraping IMDS for service name and AutoScalingGroup","kind":"extension","name":"entitystore"}
2024-12-17T19:18:39Z I! {"caller":"entitystore/serviceprovider.go:248","msg":"Scraping IMDS for service name and AutoScalingGroup","kind":"extension","name":"entitystore"}
2024-12-17T19:21:39Z I! {"caller":"entitystore/serviceprovider.go:248","msg":"Scraping IMDS for service name and AutoScalingGroup","kind":"extension","name":"entitystore"}
2024-12-17T19:24:39Z I! {"caller":"entitystore/serviceprovider.go:248","msg":"Scraping IMDS for service name and AutoScalingGroup","kind":"extension","name":"entitystore"}
2024-12-17T19:27:39Z I! {"caller":"entitystore/serviceprovider.go:248","msg":"Scraping IMDS for service name and AutoScalingGroup","kind":"extension","name":"entitystore"}
2024-12-17T19:37:39Z I! {"caller":"entitystore/serviceprovider.go:248","msg":"Scraping IMDS for service name and AutoScalingGroup","kind":"extension","name":"entitystore"}
2024-12-17T19:47:39Z I! {"caller":"entitystore/serviceprovider.go:248","msg":"Scraping IMDS for service name and AutoScalingGroup","kind":"extension","name":"entitystore"}
2024-12-17T19:57:39Z I! {"caller":"entitystore/serviceprovider.go:248","msg":"Scraping IMDS for service name and AutoScalingGroup","kind":"extension","name":"entitystore"}
[ec2-user@ip-172-31-6-118 ~]$ date
Tue Dec 17 20:21:47 UTC 2024

I enabled the instance tags at 19:53 and You can see above there is no retry after 19:57 until 20:21 current time.

2024-12-17T19:57:39Z I! {"caller":"entitystore/serviceprovider.go:248","msg":"Scraping IMDS for service name and AutoScalingGroup","kind":"extension","name":"entitystore"}
2024-12-17T19:57:39Z I! {"caller":"entitystore/serviceprovider.go:261","msg":"Service name retrieved through IMDS","kind":"extension","name":"entitystore"}
2024-12-17T19:57:39Z I! {"caller":"entitystore/serviceprovider.go:274","msg":"AutoScalingGroup retrieved through IMDS","kind":"extension","name":"entitystore"}
2024-12-17T19:57:40Z D! [logagent] open file count, 1
2024-12-17T19:57:40Z D! [outputs.cloudwatchlogs] Pusher published 13 log events to group: agent_log_group stream: agent_log_stream with size 4 KB in 9.93404ms.

Requirements

Before commit the code, please do the following steps.

  1. Run make fmt and make fmt-sh
  2. Run make lint

@nathalapooja nathalapooja requested a review from a team as a code owner December 17, 2024 19:24
extension/entitystore/serviceprovider.go Outdated Show resolved Hide resolved
extension/entitystore/serviceprovider.go Outdated Show resolved Hide resolved
@nathalapooja nathalapooja changed the title Retrieve instance tags at the same time to reduce number of entities in compass experience Retrieve instance tags at the same time to reduce number of entities in Explore related experience Dec 19, 2024
@@ -257,9 +264,25 @@ func (s *serviceprovider) scrapeImdsServiceName() error {
break
}
}
if strings.Contains(tags, ec2tagger.Ec2InstanceTagKeyASG) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this strings.Contains if statement? We end up checking if the instance tag exists anyways in the next line. Seems excessive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only make a call if it exists in the list of tags

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, but in the end we would error out from s.metadataProvider.InstanceTagValue if it doesn't exist right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but its a safety check to avoid additional calls

extension/entitystore/serviceprovider.go Show resolved Hide resolved
extension/entitystore/serviceprovider.go Show resolved Hide resolved
Copy link
Contributor

@lisguo lisguo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving since we are being consistent with existing code -- but worth revisiting removing the ASG char limit and checking for strings.Contains for the entire tags dump

@nathalapooja nathalapooja merged commit 43d475d into main Dec 19, 2024
7 checks passed
@nathalapooja nathalapooja deleted the tags-fix branch December 19, 2024 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants