Skip to content

Commit 0280d9f

Browse files
committed
refactor: update test_metrics to use new verbose infra
1 parent 6de3ce2 commit 0280d9f

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

tests/e2e/metrics/test_metrics.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,55 @@
11
import datetime
22
import json
3-
import uuid
43
from typing import Dict, Type
54

65
import pytest
7-
from e2e import conftest
86
from e2e.utils import helpers
97

108
from tests.e2e.metrics.infrastructure import MetricsStack
119

1210

13-
@pytest.fixture(scope="module")
14-
def config() -> conftest.LambdaConfig:
15-
return {
16-
"parameters": {},
17-
"environment_variables": {
18-
"POWERTOOLS_METRICS_NAMESPACE": "powertools-e2e-metric",
19-
"POWERTOOLS_SERVICE_NAME": "test-powertools-service",
20-
"METRIC_NAME": f"business-metric-{str(uuid.uuid4()).replace('-','_')}",
21-
},
22-
}
23-
24-
2511
@pytest.fixture
2612
def infra_outputs(infrastructure: Type[MetricsStack]):
2713
return infrastructure.get_stack_outputs()
2814

2915

3016
def test_basic_lambda_metric_is_visible(infra_outputs: Dict[str, str]):
31-
# sourcery skip: aware-datetime-for-utc
32-
execution_time = datetime.datetime.utcnow()
33-
metric_name = "test"
17+
# GIVEN
18+
metric_name = "test-two"
3419
service = "test-metric-is-visible"
3520
namespace = "powertools-e2e-metric"
3621
event = json.dumps({"metric_name": metric_name, "service": service, "namespace": namespace})
37-
ret = helpers.trigger_lambda(lambda_arn=infra_outputs.get("basichandlerarn"), payload=event)
3822

39-
assert ret is None # we could test in the actual response now
23+
# NOTE: Need to try creating a dynamic enum/dataclass w/ Literal types to make discovery easier
24+
# it might not be possible
25+
26+
# WHEN
27+
execution_time = datetime.datetime.utcnow()
28+
ret = helpers.trigger_lambda(lambda_arn=infra_outputs.get("basichandlerarn"), payload=event)
4029

41-
# NOTE: find out why we're getting empty metrics
4230
metrics = helpers.get_metrics(
4331
start_date=execution_time,
4432
end_date=execution_time + datetime.timedelta(minutes=2),
4533
namespace=namespace,
4634
service_name=service,
4735
metric_name=metric_name,
4836
)
49-
assert metrics is not None
37+
38+
# THEN
39+
assert len(metrics.get("Timestamps", [])) == 1
40+
metric_data = metrics.get("Values", [])
41+
assert metric_data and metric_data[0] == 1
42+
43+
# for later... we could break the test early if the function failed
44+
# we could extend `trigger_lambda` with a default param to check on that
45+
# making the test less verbose. For explicit invoke failure, we could override
46+
assert ret is not None
5047

5148

52-
# helpers: create client on the fly if not passed
53-
# accept payload to be sent as part of invocation
5449
# helpers: adjust retries and wait to be much smaller
50+
# helpers: make retry config adjustable
5551
# Infra: Create dynamic Enum/DataClass to reduce guessing on outputs
5652
# Infra: Fix outputs
5753
# Infra: Add temporary Powertools Layer
5854
# Powertools: should have a method to set namespace at runtime
55+
# Create separate Infra class so they can live side by side

0 commit comments

Comments
 (0)