Skip to content

Add provider info to service request counter #12740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions localstack-core/localstack/aws/handlers/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ def __call__(self, chain: HandlerChain, context: RequestContext, response: Respo
err_type = self._get_err_type(context, response) if response.status_code >= 400 else None
service_name = context.operation.service_model.service_name
operation_name = context.operation.name
provider = config.SERVICE_PROVIDER_CONFIG.get_provider(service_name)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line seems to suggest that there's a 1:1 relationship of service_name to provider, which I think is not true - did I misread the function or the 1:1 relationship actually is true in the community version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a running instance the relation is 1:1. Only one provider can be active at once. The active provider is defined in the config


self.aggregator.add_request(
ServiceRequestInfo(
service_name,
operation_name,
response.status_code,
err_type=err_type,
provider=provider,
)
)

Expand Down
29 changes: 29 additions & 0 deletions localstack-core/localstack/utils/analytics/service_providers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from localstack.runtime import hooks


@hooks.on_runtime_ready()
def publish_provider_assignment():
"""
Publishes the service provider assignment to the analytics service.
"""
from datetime import datetime

from localstack.config import SERVICE_PROVIDER_CONFIG
from localstack.utils.analytics import get_session_id
from localstack.utils.analytics.events import Event, EventMetadata

provider_assignment = {
service: f"localstack.aws.provider/{service}:{provider}"
for service, provider in SERVICE_PROVIDER_CONFIG.items()
if provider
}
metadata = EventMetadata(
session_id=get_session_id(),
client_time=str(datetime.now()),
)

event = Event(
name="ls_service_provider_assignment", metadata=metadata, payload=provider_assignment
)

print("Would publish event:", event.asdict())
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ServiceRequestInfo(NamedTuple):
operation: str
status_code: int
err_type: Optional[str] = None
provider: Optional[str] = None


class ServiceRequestAggregator:
Expand Down
Loading