Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from localstack.http import Response
from localstack.utils.analytics.usage import UsageSetCounter
from localstack.utils.analytics.metrics import Counter, LabeledCounterMetric

from ..api import RestApiGatewayHandler, RestApiGatewayHandlerChain
from ..context import RestApiInvocationContext
Expand All @@ -10,10 +10,12 @@


class IntegrationUsageCounter(RestApiGatewayHandler):
counter: UsageSetCounter
counter: LabeledCounterMetric

def __init__(self, counter: UsageSetCounter = None):
self.counter = counter or UsageSetCounter(namespace="apigateway:invokedrest")
def __init__(self, counter: LabeledCounterMetric = None):
self.counter = counter or Counter(
namespace="apigateway", name="rest_api_execute", labels=["invocation_type"]
)

def __call__(
self,
Expand All @@ -31,7 +33,7 @@ def __call__(
# hence we should count it as a NOT_FOUND invocation
invocation_type = "NOT_FOUND"

self.counter.record(invocation_type)
self.counter.labels(invocation_type=invocation_type).increment()

@staticmethod
def _get_aws_integration_service(integration_uri: str) -> str:
Expand All @@ -41,4 +43,8 @@ def _get_aws_integration_service(integration_uri: str) -> str:
if len(split_arn := integration_uri.split(":", maxsplit=5)) < 4:
return "null"

return split_arn[4]
service = split_arn[4]
# the URI can also contain some <api-id>.<service>-api kind of route like `execute-api` or `appsync-api`
# we need to make sure we do not pass the full value back
service = service.split(".")[-1]
return service
Loading