-
Notifications
You must be signed in to change notification settings - Fork 57
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
Add ECS metadata allowing cloudwatch-logs to be linked with traces #93
Add ECS metadata allowing cloudwatch-logs to be linked with traces #93
Conversation
@@ -10,13 +10,80 @@ module ECS | |||
|
|||
ORIGIN = 'AWS::ECS::Container'.freeze | |||
|
|||
# Only compatible with v4! | |||
# The v3 metadata url does not contain cloudwatch informations | |||
METADATA_ENV_KEY = 'ECS_CONTAINER_METADATA_URI_V4' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we have a strong dependency with Fargate 1.4, otherwise this environment variable will not be defined:
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v4-fargate.html
Sadly the necessary information are not exposed with the meta-information of the v3:
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v3-fargate.html
ecs: { | ||
container_arn: data['ContainerARN'], | ||
}, | ||
cloudwatch_logs: { | ||
log_group: data["LogOptions"]['awslogs-group'], | ||
log_region: data["LogOptions"]['awslogs-region'], | ||
arn: data['ContainerARN'] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -43,6 +44,7 @@ def test_ec2_metadata_v2_successful | |||
ami_id: 'ami-03cca83dd001d4666' | |||
} | |||
} | |||
# We should probably use `assert_equal` here ? Always true otherwise... | |||
assert expected, XRay::Plugins::EC2.aws |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to my PR, but assert
is always returning true here... regardless what is passed
We probably want to use assert_equal
if we want to compare something expected
with XRay::Plugins::EC2.aws
"LogOptions"=>{"awslogs-group"=>"/ecs/a_service_name", "awslogs-region"=>"eu-central-1", "awslogs-stream"=>"ecs/a_service_name/a_task_id"}, | ||
} | ||
|
||
ENV[XRay::Plugins::ECS::METADATA_ENV_KEY] = dummy_metadata_uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried a few things to mutate the ENV in a better way...
Could not do it without adding extra dependencies to the project
container: Socket.gethostname, | ||
container_arn: 'arn:aws:ecs:eu-central-1:an_id:container/a_cluster/a_cluster_id/a_task_id', | ||
}, | ||
cloudwatch_logs: {:log_group=>"/ecs/a_service_name", :log_region=>"eu-central-1", :arn=>"arn:aws:ecs:eu-central-1:an_id:container/a_cluster/a_cluster_id/a_task_id"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the key change here, with this information present in the trace, the logs should be linked
# Due to lack of ECS container metadata service, the only host information | ||
# available is the host name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is not anymore relevant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the contribution!
* Add ECS metadata allowing cloudwatch-logs to be linked with traces (aws#93) * First step * Add comment * Typo * Copy logic of EC2 plugin for ECS * Typo * Back to symbols * Copy paste all EC2 tests as starting point for ECS * Comments * Somewhat working ? * Backword compatible with prevous feature when not 1.4 * Add hint for fargate 1.4 in case of errors --------- Co-authored-by: Etienne Chabert <[email protected]> * release 0.15.0 (aws#94) * Update version for 0.15.0 release (aws#95) * Update continuous-build.yml (aws#97) the latest macos-14 supports arm only. This PR using the previous version of macos image to unblock the release. * Fix issue: Wrong duration for DB transaction event on ROR 7.1 aws#92 (aws#96) * Fix issue: Wrong duration for DB transaction event on ROR 7.1 aws#92 * Added unit tests and restructured the code * Fix unit tests * Update continuous-build.yml (aws#97) the latest macos-14 supports arm only. This PR using the previous version of macos image to unblock the release. * Worked on the jj22ee's comment and added logic that convert in seconds only for rails 7.1 versions. * Conditionally handle for ruby 7.1 --------- Co-authored-by: Lei Wang <[email protected]> * Release 0.16.0 (aws#98) --------- Co-authored-by: Chabert Etienne <[email protected]> Co-authored-by: Etienne Chabert <[email protected]> Co-authored-by: Prashant Srivastava <[email protected]> Co-authored-by: Lei Wang <[email protected]> Co-authored-by: Osama Bin Junaid <[email protected]> Co-authored-by: Min Xia <[email protected]>
In this PR
Warning
It will only work for ECS Task running on Fargate 1.4 and above.
Related issue
#90
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.