Skip to content

Commit 0c49b66

Browse files
author
Michal Ploski
committed
Add PR suggestions
1 parent 3034041 commit 0c49b66

File tree

7 files changed

+13
-31
lines changed

7 files changed

+13
-31
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ addopts = "-ra -vv"
138138
testpaths = "./tests"
139139
markers = [
140140
"perf: marks perf tests to be deselected (deselect with '-m \"not perf\"')",
141-
"e2e: marks e2e tests to be deselected (deselect with '-m \"not e2e\"')",
142141
]
143142

144143
[build-system]

tests/e2e/logger/test_logger.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def config() -> conftest.LambdaConfig:
1717
}
1818

1919

20-
@pytest.mark.e2e
2120
def test_basic_lambda_logs_visible(execute_lambda: conftest.InfrastructureOutput, config: conftest.LambdaConfig):
2221
# GIVEN
2322
lambda_arn = execute_lambda.get_lambda_arn(name="basichandlerarn")
@@ -37,7 +36,6 @@ def test_basic_lambda_logs_visible(execute_lambda: conftest.InfrastructureOutput
3736
)
3837

3938

40-
@pytest.mark.e2e
4139
def test_basic_lambda_no_debug_logs_visible(
4240
execute_lambda: conftest.InfrastructureOutput, config: conftest.LambdaConfig
4341
):
@@ -57,7 +55,6 @@ def test_basic_lambda_no_debug_logs_visible(
5755
)
5856

5957

60-
@pytest.mark.e2e
6158
def test_basic_lambda_contextual_data_logged(execute_lambda: conftest.InfrastructureOutput):
6259
# GIVEN
6360
required_keys = (
@@ -82,7 +79,6 @@ def test_basic_lambda_contextual_data_logged(execute_lambda: conftest.Infrastruc
8279
assert all(keys in logs.dict(exclude_unset=True) for logs in filtered_logs for keys in required_keys)
8380

8481

85-
@pytest.mark.e2e
8682
def test_basic_lambda_additional_key_persistence_basic_lambda(
8783
execute_lambda: conftest.InfrastructureOutput, config: conftest.LambdaConfig
8884
):
@@ -105,7 +101,6 @@ def test_basic_lambda_additional_key_persistence_basic_lambda(
105101
)
106102

107103

108-
@pytest.mark.e2e
109104
def test_basic_lambda_empty_event_logged(execute_lambda: conftest.InfrastructureOutput):
110105

111106
# GIVEN
@@ -122,7 +117,6 @@ def test_basic_lambda_empty_event_logged(execute_lambda: conftest.Infrastructure
122117
assert any(log.message == {} for log in filtered_logs)
123118

124119

125-
@pytest.mark.e2e
126120
def test_no_context_lambda_contextual_data_not_logged(execute_lambda: conftest.InfrastructureOutput):
127121

128122
# GIVEN
@@ -147,7 +141,6 @@ def test_no_context_lambda_contextual_data_not_logged(execute_lambda: conftest.I
147141
assert not any(keys in logs.dict(exclude_unset=True) for logs in filtered_logs for keys in required_missing_keys)
148142

149143

150-
@pytest.mark.e2e
151144
def test_no_context_lambda_event_not_logged(execute_lambda: conftest.InfrastructureOutput):
152145

153146
# GIVEN

tests/e2e/metrics/test_metrics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ def config() -> conftest.LambdaConfig:
1414
"parameters": {},
1515
"environment_variables": {
1616
"POWERTOOLS_METRICS_NAMESPACE": "powertools-e2e-metric",
17-
"POWERTOOLS_SERVICE_NAME": f"test-powertools-service",
17+
"POWERTOOLS_SERVICE_NAME": "test-powertools-service",
1818
"METRIC_NAME": f"business-metric-{uuid.uuid4()}",
1919
},
2020
}
2121

2222

23-
@pytest.mark.e2e
2423
def test_basic_lambda_metric_visible(execute_lambda: conftest.InfrastructureOutput, config: conftest.LambdaConfig):
2524
# GIVEN
2625
start_date = execute_lambda.get_lambda_execution_time()

tests/e2e/tracer/handlers/basic_handler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313

1414
@tracer.capture_lambda_handler
1515
def lambda_handler(event: dict, context: LambdaContext):
16-
# tracer.put_annotation(key=ANNOTATION_KEY, value=ANNOTATION_VALUE)
1716
tracer.put_metadata(key=ANNOTATION_KEY, value=ANNOTATION_VALUE)
1817
return asyncio.run(collect_payment())
1918

2019

2120
@tracer.capture_method
2221
async def collect_payment() -> str:
23-
# tracer.put_annotation(key=ANNOTATION_KEY, value=ANNOTATION_ASYNC_VALUE)
2422
tracer.put_metadata(key=ANNOTATION_KEY, value=ANNOTATION_ASYNC_VALUE)
2523
return "success"

tests/e2e/tracer/test_tracer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import datetime
2-
import json
32
import uuid
43

54
import boto3
@@ -21,18 +20,18 @@ def config():
2120
}
2221

2322

24-
@pytest.mark.e2e
2523
def test_basic_lambda_async_trace_visible(execute_lambda: conftest.InfrastructureOutput, config: conftest.LambdaConfig):
2624
# GIVEN
2725
lambda_arn = execute_lambda.get_lambda_arn(name="basichandlerarn")
2826
start_date = execute_lambda.get_lambda_execution_time()
2927
end_date = start_date + datetime.timedelta(minutes=5)
28+
trace_filter_exporession = f'service("{lambda_arn.split(":")[-1]}")'
3029

3130
# WHEN
3231
trace = helpers.get_traces(
3332
start_date=start_date,
3433
end_date=end_date,
35-
lambda_function_name=lambda_arn.split(":")[-1],
34+
filter_expression=trace_filter_exporession,
3635
xray_client=boto3.client("xray"),
3736
)
3837

tests/e2e/utils/helpers.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,27 @@ def get_logs(lambda_function_name: str, log_client: CloudWatchClient, start_time
5555

5656

5757
@lru_cache(maxsize=10, typed=False)
58-
@retry(ValueError, delay=1, jitter=1, tries=10)
58+
@retry(ValueError, delay=1, jitter=1, tries=20)
5959
def get_metrics(
6060
namespace: str,
6161
cw_client: CloudWatchClient,
6262
start_date: datetime,
63-
end_date: datetime,
6463
metric_name: str,
6564
service_name: str,
65+
end_date: Optional[datetime] = None,
6666
):
6767
response = cw_client.get_metric_data(
6868
MetricDataQueries=[
6969
{
7070
"Id": "m1",
71-
"MetricStat": {
72-
"Metric": {
73-
"Namespace": namespace,
74-
"MetricName": metric_name,
75-
"Dimensions": [{"Name": "service", "Value": service_name}],
76-
},
77-
"Period": 600,
78-
"Stat": "Maximum",
79-
},
71+
"Expression": f'SELECT MAX("{metric_name}") from SCHEMA("{namespace}",service) \
72+
where service=\'{service_name}\'',
8073
"ReturnData": True,
74+
"Period": 600,
8175
},
8276
],
8377
StartTime=start_date,
84-
EndTime=end_date,
78+
EndTime=end_date if end_date else datetime.utcnow(),
8579
)
8680
result = response["MetricDataResults"][0]
8781
if not result["Values"]:
@@ -90,14 +84,14 @@ def get_metrics(
9084

9185

9286
@retry(ValueError, delay=1, jitter=1, tries=10)
93-
def get_traces(lambda_function_name: str, xray_client: XRayClient, start_date: datetime, end_date: datetime) -> Dict:
87+
def get_traces(filter_expression: str, xray_client: XRayClient, start_date: datetime, end_date: datetime) -> Dict:
9488
paginator = xray_client.get_paginator("get_trace_summaries")
9589
response_iterator = paginator.paginate(
9690
StartTime=start_date,
9791
EndTime=end_date,
9892
TimeRangeType="Event",
9993
Sampling=False,
100-
FilterExpression=f'service("{lambda_function_name}")',
94+
FilterExpression=filter_expression,
10195
)
10296

10397
traces = [trace["TraceSummaries"][0]["Id"] for trace in response_iterator if trace["TraceSummaries"]]

tests/e2e/utils/infrastructure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ def _create_layer(self, stack: Stack):
5555
command=[
5656
"bash",
5757
"-c",
58-
f"poetry export --with-credentials --format requirements.txt --output /tmp/requirements.txt &&\
58+
rf"poetry export --with-credentials --format requirements.txt --output /tmp/requirements.txt &&\
5959
pip install -r /tmp/requirements.txt -t {output_dir} &&\
6060
cp -R {input_dir} {output_dir} &&\
61-
find {output_dir}/ -regex '^.*__pycache__.*' -delete",
61+
find {output_dir}/ -type d -name __pycache__ -prune -exec rm -rf {{}} \;",
6262
],
6363
),
6464
),

0 commit comments

Comments
 (0)