-
Notifications
You must be signed in to change notification settings - Fork 403
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
chore(tests): refactor E2E tracer to ease maintenance, writing tests and parallelization #1457
chore(tests): refactor E2E tracer to ease maintenance, writing tests and parallelization #1457
Conversation
Test differences Besides data builders, I've encapsulated trace fetching and manipulation of different views in its own class. The logic is largely the same, what changed is that we have more flexibility in the type of trace we want (origin, segment name, etc.) and have getters to ease assertion. Beforedef test_basic_lambda_async_trace_visible(execute_lambda: conftest.InfrastructureOutput, config: conftest.LambdaConfig):
# GIVEN
lambda_name = execute_lambda.get_lambda_function_name(cf_output_name="basichandlerarn")
start_date = execute_lambda.get_lambda_execution_time()
end_date = start_date + datetime.timedelta(minutes=5)
trace_filter_exporession = f'service("{lambda_name}")'
# WHEN
trace = helpers.get_traces(
start_date=start_date,
end_date=end_date,
filter_expression=trace_filter_exporession,
xray_client=boto3.client("xray"),
)
# THEN
info = helpers.find_trace_additional_info(trace=trace)
print(info)
handler_trace_segment = [trace_segment for trace_segment in info if trace_segment.name == "## lambda_handler"][0]
collect_payment_trace_segment = [
trace_segment for trace_segment in info if trace_segment.name == "## collect_payment"
][0]
annotation_key = config["environment_variables"]["ANNOTATION_KEY"]
expected_value = config["environment_variables"]["ANNOTATION_VALUE"]
expected_async_value = config["environment_variables"]["ANNOTATION_ASYNC_VALUE"]
assert handler_trace_segment.annotations["Service"] == "e2e-tests-app"
assert handler_trace_segment.metadata["e2e-tests-app"][annotation_key] == expected_value
assert collect_payment_trace_segment.metadata["e2e-tests-app"][annotation_key] == expected_async_value Afterdef test_lambda_handler_trace_is_visible(basic_handler_fn_arn: str, basic_handler_fn: str):
# GIVEN
handler_name = basic_handler.lambda_handler.__name__
handler_subsegment = f"## {handler_name}"
handler_metadata_key = f"{handler_name} response"
trace_query = data_builder.build_trace_default_query(function_name=basic_handler_fn)
# WHEN
_, execution_time = helpers.trigger_lambda(lambda_arn=basic_handler_fn_arn)
helpers.trigger_lambda(lambda_arn=basic_handler_fn_arn)
# THEN
trace = data_fetcher.get_traces(start_date=execution_time, filter_expression=trace_query, minimum_traces=2)
assert len(trace.get_annotation(key="ColdStart", value=True)) == 1
assert len(trace.get_metadata(key=handler_metadata_key, namespace=TracerStack.SERVICE_NAME)) == 2
assert len(trace.get_subsegment(name=handler_subsegment)) == 2 |
Huge improvement in readability and code quality @heitorlessa. Too easy to understand now 🎸 |
Codecov Report
@@ Coverage Diff @@
## develop #1457 +/- ##
========================================
Coverage 99.89% 99.89%
========================================
Files 121 121
Lines 5479 5479
Branches 627 627
========================================
Hits 5473 5473
Misses 2 2
Partials 4 4 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@mploski @rubenfonseca could either of you review before I start Logger and complete the refactoring? Thanks a lot! |
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.
All feedback addressed @mploski - when you're ready |
I'm gonna simplify |
* develop: chore(deps): bump release-drafter/release-drafter from 5.20.0 to 5.20.1 (aws-powertools#1458)
Thanks a lot for the review and suggested changes @mploski @rubenfonseca ! Merging. |
Issue number: #1440
Summary
This PR refactors Tracer E2E test following the new Infrastructure and explicit tests. Unrelated to Tracer, it also breaks up the various helpers into their own respective modules (
data_fetcher/traces.py
anddata_builder/metrics.py
).Tasks
TraceFetcher
get_traces
factory to returnTraceFetcher
TracerStack
and use new infrastructurePOWERTOOLS_SERVICE_NAME
as Env Var;Tracer
needs changing to allow dynamic service injectionChanges
User experience
Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change?
RFC issue number:
Checklist:
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.