Skip to content

Commit e29b3fa

Browse files
committed
chore: output register_usage response in logs.
1 parent 2301b3d commit e29b3fa

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ lint = [
5050
"stdapi[opentelemetry, uvicorn]",
5151
"mypy",
5252
"ruff",
53-
"types-aioboto3[bedrock, bedrock-runtime, polly, comprehend, s3, transcribe, translate]",
53+
"types-aioboto3[bedrock, bedrock-runtime, polly, comprehend, s3, transcribe, translate, meteringmarketplace]",
5454
"types-PyYAML",
5555
]
5656
docs = [

stdapi/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ async def lifespan(_: FastAPI) -> AsyncGenerator[None]:
8181
register(),
8282
)
8383
auth_enabled = results[0]
84+
register_usage_response = results[-1]
8485
unavailable_models = results[1][1]
8586
update_unified_models_collections()
8687
start_event = EventLog(
@@ -91,6 +92,8 @@ async def lifespan(_: FastAPI) -> AsyncGenerator[None]:
9192
server_version=SERVER_FULL_VERSION,
9293
server_start_time_ms=(time_ns() - start) // 1000000,
9394
)
95+
if register_usage_response:
96+
start_event["register_usage_response"] = register_usage_response
9497
if not auth_enabled:
9598
start_event.setdefault("server_warnings", []).append(
9699
"SECURITY risk: Authentication is not enabled "

stdapi/metering.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""AWS Marketplace Metering."""
22

3+
from typing import TYPE_CHECKING
4+
35
from botocore.exceptions import ClientError as _ClientError
46

57
from stdapi.aws import CONFIG, REGION, SESSION
@@ -10,6 +12,11 @@
1012
)
1113
from stdapi.server import SERVER_ID, SERVER_VERSION
1214

15+
if TYPE_CHECKING:
16+
from types_aiobotocore_meteringmarketplace.type_defs import (
17+
RegisterUsageResultTypeDef,
18+
)
19+
1320
PRODUCT_CODE = ""
1421
LICENCE_INFO = (
1522
{"name": "Commercial License", "url": "https://stdapi.ai/commercial_license"}
@@ -23,7 +30,7 @@
2330
SERVER_FULL_VERSION = f"{SERVER_VERSION}+{'p' if PRODUCT_CODE else 'c'}"
2431

2532

26-
async def register() -> None:
33+
async def register() -> "RegisterUsageResultTypeDef | None":
2734
"""Register AWS Marketplace for the current host.
2835
2936
For ECS, EKS & Fargate hosts running hourly billed products.
@@ -38,7 +45,7 @@ async def register() -> None:
3845
"meteringmarketplace", config=CONFIG, region_name=REGION
3946
) as metering:
4047
try:
41-
await metering.register_usage(
48+
return await metering.register_usage(
4249
ProductCode=PRODUCT_CODE,
4350
PublicKeyVersion=product_public_key_version,
4451
Nonce=SERVER_ID,
@@ -81,3 +88,4 @@ async def register() -> None:
8188
if exc_type:
8289
raise exc_type(exc_msg) from None
8390
raise # pragma: no cover
91+
return None

stdapi/monitoring.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
if TYPE_CHECKING:
1919
from pydantic.main import IncEx
20+
from types_aiobotocore_meteringmarketplace.type_defs import (
21+
RegisterUsageResultTypeDef,
22+
)
2023

2124
from stdapi.monitoring_otel import OpenTelemetryManager
2225

@@ -48,6 +51,7 @@ class EventLog(TypedDict):
4851
# "start" type
4952
server_start_time_ms: NotRequired[int]
5053
server_warnings: NotRequired[list[JsonValue]]
54+
register_usage_response: "NotRequired[RegisterUsageResultTypeDef]"
5155

5256
# "stop" type
5357
server_uptime_ms: NotRequired[int]

stdapi/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
SERVER_NAME = f"{gethostname()}-{getpid()}-{SERVER_ID}"
1313

1414
#: Server version
15-
SERVER_VERSION = "1.0.2"
15+
SERVER_VERSION = "1.0.3"
1616

1717
#: Server user agent
1818
USER_AGENT = f"stdapi.ai/{SERVER_VERSION}/{SERVER_ID}"

0 commit comments

Comments
 (0)