-
-
Notifications
You must be signed in to change notification settings - Fork 317
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
Xray initial support #273
base: master
Are you sure you want to change the base?
Xray initial support #273
Conversation
It's not clear how to test it properly. I tested it with uploading to my personal AWS account and running from it. There were no any EC2 instances in it, but first AWS request |
Regarding codeclimate issue. It doesn't like then function accepting 5 arguments... |
Is is really needed to pass the ctx as argument to all the functions? Can't we set it as a field in the structs and take it from there? |
@cristim According to https://github.com/golang/go/wiki/CodeReviewComments#contexts it's the best practice... |
Does this PR requires a review? Whether yes or no, I guess it could be great to label it based on its status |
@xlr-8 I added some, but feel free to add more if you think that this is necessary. |
@artemnikitin fair enough, I guess codeclimate should not count contexts in the argument list of this check |
@cristim anything else from your side? |
@artemnikitin tomorrow is my 20% day, I'll look at it in more depth. |
I tried run this locally and got panics because of the missing context segments.
|
Forgot to mention: It also fails if I tried to make the
|
@cristim I will look into that. Didn't try to run it locally... |
@cristim I added change with the fix for a panic. For me locally everything works. Please check it when you will have time. |
autospotting.go
Outdated
@@ -58,7 +59,10 @@ func run(ctx context.Context) { | |||
conf.TagFilteringMode, | |||
conf.SpotProductDescription) | |||
|
|||
xray.Configure(xray.Config{LogLevel: "error"}) | |||
xray.Configure(xray.Config{ | |||
ContextMissingStrategy: ctxmissing.NewDefaultLogErrorStrategy(), |
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.
Thanks, this looks much better than I had attempted... I'm just sorry I wasted a few hours trying to fix this myself without any results.
I'll try it out tomorrow.
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.
Worked like a charm!
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 confirm the panics are fixed, but I'd leave the final verdict to @xlr-8
@xlr-8 will you have time to look on it? |
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.
Nice work! I wonder however if it shouldn't be made optional as X-Ray isn't free, we currently have very little view on how much it would cost depending on the setups.
Traces are pretty cheap for sure, but if one is generated at each method call, and then runs of lambda every 2min or so I wouldn't like to leave users with a significant cost increase.
On top of that, X-Ray is mostly for the profiling of the application. So it might be worth enabling it by default on all installs.
WDYS?
autospotting.go
Outdated
xray.Configure(xray.Config{ | ||
ContextMissingStrategy: ctxmissing.NewDefaultLogErrorStrategy(), | ||
LogLevel: "error", | ||
}) |
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.
Can this be configurable from an env variable?
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.
What exactly do you want to configure in this place? Log level?
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 made log level configurable via flag, but it looks like there is a bug in X-Ray SDK. aws/aws-xray-sdk-go#60. At the moment, it will post a particular error message ignoring log level...
core/region.go
Outdated
@@ -79,25 +81,25 @@ func (r *region) processRegion() { | |||
r.setupAsgFilters() | |||
|
|||
logger.Println("Scanning for enabled AutoScaling groups in ", r.name) | |||
r.scanForEnabledAutoScalingGroups() | |||
r.scanForEnabledAutoScalingGroups(context.Background()) |
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.
The context.Background
is usually used for empty context (test/main), so I'm a bit surprised to see it invoked various times. What's the reason behind this?
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.
Hmm... context.Background()
should be used in tests... I will check, there shouldn't be such things in code
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.
Thanks for catching
@xlr-8 to enable it you need to check |
Now log level for X-Ray configured via |
Isn't it something that can be enabled via terraform / cloudformation directly? EDIT: Also, the IAM permission of the lambda function might need to be enriched for the tracing |
Yes, it should be possible to do with these tools. I will check it... |
@artemnikitin please consider rebasing this PR on top of the recent state of the code. |
Initial implementation of #169
Issue Type
Summary
Added initial support for X-Ray tracing.
To be enabled it requires to enable option
Enable active tracing
for Lambda. See https://docs.aws.amazon.com/xray/latest/devguide/xray-services-lambda.html for details.Current implementation only trace calls to AWS API.
Code contribution checklist
to it.
guidelines.
test coverage doesn't decrease.
make full-test
.variables which are also passed as parameters to the
CloudFormation
and
Terraform
stacks defined as infrastructure code.
support per-group overrides using tags.
configurations.
proven to work using log output from various test runs.
appropriate) and formatted consistently to the existing log output.
new configuration options for both stack parameters and tag overrides.
contribution actually resolves it.