compose-runner 0.6.4rc2__py2.py3-none-any.whl → 0.6.6__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- compose_runner/_version.py +2 -2
- compose_runner/aws_lambda/cost_check_handler.py +71 -0
- compose_runner/run.py +4 -0
- {compose_runner-0.6.4rc2.dist-info → compose_runner-0.6.6.dist-info}/METADATA +1 -1
- {compose_runner-0.6.4rc2.dist-info → compose_runner-0.6.6.dist-info}/RECORD +8 -7
- {compose_runner-0.6.4rc2.dist-info → compose_runner-0.6.6.dist-info}/WHEEL +1 -1
- {compose_runner-0.6.4rc2.dist-info → compose_runner-0.6.6.dist-info}/entry_points.txt +0 -0
- {compose_runner-0.6.4rc2.dist-info → compose_runner-0.6.6.dist-info}/licenses/LICENSE +0 -0
compose_runner/_version.py
CHANGED
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '0.6.
|
|
32
|
-
__version_tuple__ = version_tuple = (0, 6,
|
|
31
|
+
__version__ = version = '0.6.6'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 6, 6)
|
|
33
33
|
|
|
34
34
|
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import datetime as _dt
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
from decimal import Decimal
|
|
7
|
+
from typing import Any, Dict
|
|
8
|
+
|
|
9
|
+
import boto3
|
|
10
|
+
from botocore.exceptions import BotoCoreError, ClientError
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
logger.setLevel(logging.INFO)
|
|
14
|
+
|
|
15
|
+
_CE_CLIENT = boto3.client("ce", region_name=os.environ.get("AWS_REGION", "us-east-1"))
|
|
16
|
+
|
|
17
|
+
COST_LIMIT_ENV = "COST_LIMIT_USD"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _month_range(today: _dt.date) -> Dict[str, str]:
|
|
21
|
+
start = today.replace(day=1)
|
|
22
|
+
# Cost Explorer end date is exclusive; add a day to include today.
|
|
23
|
+
end = today + _dt.timedelta(days=1)
|
|
24
|
+
return {"Start": start.isoformat(), "End": end.isoformat()}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _current_month_cost() -> Dict[str, Any]:
|
|
28
|
+
period = _month_range(_dt.date.today())
|
|
29
|
+
response = _CE_CLIENT.get_cost_and_usage(
|
|
30
|
+
TimePeriod=period,
|
|
31
|
+
Granularity="MONTHLY",
|
|
32
|
+
Metrics=["UnblendedCost"],
|
|
33
|
+
)
|
|
34
|
+
results = response.get("ResultsByTime", [])
|
|
35
|
+
total = results[0]["Total"]["UnblendedCost"] if results else {"Amount": "0", "Unit": "USD"}
|
|
36
|
+
amount = float(Decimal(total.get("Amount", "0")))
|
|
37
|
+
currency = total.get("Unit", "USD")
|
|
38
|
+
return {"amount": amount, "currency": currency, "time_period": period}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def handler(event: Dict[str, Any], context: Any) -> Dict[str, Any]:
|
|
42
|
+
limit_raw = os.environ.get(COST_LIMIT_ENV)
|
|
43
|
+
if not limit_raw:
|
|
44
|
+
raise RuntimeError(f"{COST_LIMIT_ENV} environment variable must be set.")
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
limit = float(limit_raw)
|
|
48
|
+
except ValueError as exc: # noqa: PERF203
|
|
49
|
+
raise RuntimeError(f"Invalid {COST_LIMIT_ENV}: {limit_raw}") from exc
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
cost = _current_month_cost()
|
|
53
|
+
except (ClientError, BotoCoreError) as exc:
|
|
54
|
+
logger.error("Failed to query Cost Explorer: %s", exc)
|
|
55
|
+
return {
|
|
56
|
+
"status": "ERROR",
|
|
57
|
+
"allowed": False,
|
|
58
|
+
"error": "cost_explorer_unavailable",
|
|
59
|
+
"limit": limit,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
amount = cost["amount"]
|
|
63
|
+
allowed = amount < limit
|
|
64
|
+
return {
|
|
65
|
+
"status": "OK",
|
|
66
|
+
"allowed": allowed,
|
|
67
|
+
"current_spend": amount,
|
|
68
|
+
"limit": limit,
|
|
69
|
+
"currency": cost.get("currency", "USD"),
|
|
70
|
+
"time_period": cost.get("time_period"),
|
|
71
|
+
}
|
compose_runner/run.py
CHANGED
|
@@ -198,6 +198,10 @@ class Runner:
|
|
|
198
198
|
weights = self.cached_specification.get("weights", [])
|
|
199
199
|
weight_conditions = {w: c for c, w in zip(conditions, weights)}
|
|
200
200
|
|
|
201
|
+
# since we added "order" to annotations
|
|
202
|
+
if isinstance(column_type, dict):
|
|
203
|
+
column_type = column_type.get("type")
|
|
204
|
+
|
|
201
205
|
if not (conditions or weights) and column_type != "boolean":
|
|
202
206
|
raise ValueError(
|
|
203
207
|
f"Column type {column_type} requires a conditions and weights."
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
compose_runner/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
compose_runner/_version.py,sha256=
|
|
2
|
+
compose_runner/_version.py,sha256=36Xr9Xxe1YvCx4D9dhOO3FJ9uBAofY81kJm_SZPwDIQ,704
|
|
3
3
|
compose_runner/cli.py,sha256=1tkxFgEe8Yk7VkzE8qxGmCGqLU7UbGin2VaP0AiZkVg,1101
|
|
4
4
|
compose_runner/ecs_task.py,sha256=15CyLsaf2xrvWM-gGPDOXj_Hq8eJJPiH7xyRas93zn0,5352
|
|
5
|
-
compose_runner/run.py,sha256=
|
|
5
|
+
compose_runner/run.py,sha256=wNAm8_fKoBJElMVlY7GTODqjZJG8S6y8K-QCUljL6Ko,18666
|
|
6
6
|
compose_runner/sentry.py,sha256=pjqwsZrXrKB0cCy-TL-_2eYJIqUU0aV-8e0SWUk-9Xw,320
|
|
7
7
|
compose_runner/aws_lambda/__init__.py,sha256=yZNXXv7gCPSrtLCEX5Qf4cnzSTS3fHPV6k-SyZwiZIA,48
|
|
8
8
|
compose_runner/aws_lambda/common.py,sha256=cA2G5lO4P8uVBqJaYcU6Y3P3t3syoTmk4SpLKZhAFo8,1688
|
|
9
|
+
compose_runner/aws_lambda/cost_check_handler.py,sha256=TjzlnXLOT7kW6RfYfXuFFpmusIckGjOeUM6y0_NztBw,2213
|
|
9
10
|
compose_runner/aws_lambda/log_poll_handler.py,sha256=eEU-Ra_-17me3e4eqSTd2Nv_qoaOl7zi3kIxD58Tbek,1905
|
|
10
11
|
compose_runner/aws_lambda/results_handler.py,sha256=vSxs4nbWyBmkFFKRGIp5-T4W2hPh9zgj7uNH-e18aW8,2107
|
|
11
12
|
compose_runner/aws_lambda/run_handler.py,sha256=WbaoRp5hsWNqAgDamW9BPihp1tfVVTM94_HKHL4Uawg,6562
|
|
@@ -22,8 +23,8 @@ compose_runner/tests/cassettes/test_run/test_run_database_workflow.yaml,sha256=a
|
|
|
22
23
|
compose_runner/tests/cassettes/test_run/test_run_group_comparison_workflow.yaml,sha256=FaZpMdcaM7TMgyueyZBGftm6ywUh1HhtGmCegXUmRFA,4029712
|
|
23
24
|
compose_runner/tests/cassettes/test_run/test_run_string_group_comparison_workflow.yaml,sha256=pcn6tQwrimhDtP8yJ3jFlsfEOnk8FWybYQr9IQ5A_KA,3233839
|
|
24
25
|
compose_runner/tests/cassettes/test_run/test_run_workflow.yaml,sha256=0Nk7eJWAmgYALG2ODrezbRhpYsc00JiuYVjXt3TUm5c,3857234
|
|
25
|
-
compose_runner-0.6.
|
|
26
|
-
compose_runner-0.6.
|
|
27
|
-
compose_runner-0.6.
|
|
28
|
-
compose_runner-0.6.
|
|
29
|
-
compose_runner-0.6.
|
|
26
|
+
compose_runner-0.6.6.dist-info/METADATA,sha256=rL0VGkiWKExkNpJhLq4_Kh5ZfbezoVUIeo5d_ein7lc,3432
|
|
27
|
+
compose_runner-0.6.6.dist-info/WHEEL,sha256=aha0VrrYvgDJ3Xxl3db_g_MDIW-ZexDdrc_m-Hk8YY4,105
|
|
28
|
+
compose_runner-0.6.6.dist-info/entry_points.txt,sha256=TyPmB9o2tSWw8L3mcach9r2EL7inRVXE9ew3_XReMIY,55
|
|
29
|
+
compose_runner-0.6.6.dist-info/licenses/LICENSE,sha256=PeiWxrrRme2rIpPMV9vjgGe7UHEKCIcTb0KagYhnyqo,1313
|
|
30
|
+
compose_runner-0.6.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|