|
1 | 1 | import datetime
|
2 | 2 | import json
|
3 |
| -import uuid |
4 | 3 | from typing import Dict, Type
|
5 | 4 |
|
6 | 5 | import pytest
|
7 |
| -from e2e import conftest |
8 | 6 | from e2e.utils import helpers
|
9 | 7 |
|
10 | 8 | from tests.e2e.metrics.infrastructure import MetricsStack
|
11 | 9 |
|
12 | 10 |
|
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 |
| - |
25 | 11 | @pytest.fixture
|
26 | 12 | def infra_outputs(infrastructure: Type[MetricsStack]):
|
27 | 13 | return infrastructure.get_stack_outputs()
|
28 | 14 |
|
29 | 15 |
|
30 | 16 | 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" |
34 | 19 | service = "test-metric-is-visible"
|
35 | 20 | namespace = "powertools-e2e-metric"
|
36 | 21 | event = json.dumps({"metric_name": metric_name, "service": service, "namespace": namespace})
|
37 |
| - ret = helpers.trigger_lambda(lambda_arn=infra_outputs.get("basichandlerarn"), payload=event) |
38 | 22 |
|
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) |
40 | 29 |
|
41 |
| - # NOTE: find out why we're getting empty metrics |
42 | 30 | metrics = helpers.get_metrics(
|
43 | 31 | start_date=execution_time,
|
44 | 32 | end_date=execution_time + datetime.timedelta(minutes=2),
|
45 | 33 | namespace=namespace,
|
46 | 34 | service_name=service,
|
47 | 35 | metric_name=metric_name,
|
48 | 36 | )
|
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 |
50 | 47 |
|
51 | 48 |
|
52 |
| -# helpers: create client on the fly if not passed |
53 |
| -# accept payload to be sent as part of invocation |
54 | 49 | # helpers: adjust retries and wait to be much smaller
|
| 50 | +# helpers: make retry config adjustable |
55 | 51 | # Infra: Create dynamic Enum/DataClass to reduce guessing on outputs
|
56 | 52 | # Infra: Fix outputs
|
57 | 53 | # Infra: Add temporary Powertools Layer
|
58 | 54 | # 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