8000 refactor: metrics instrumentation framework typing and structure by vittoriopolverino · Pull Request #12717 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

refactor: metrics instrumentation framework typing and structure #12717

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions localstack-core/localstack/services/apigateway/analytics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from localstack.utils.analytics.metrics import Counter
from localstack.utils.analytics.metrics import LabeledCounter

invocation_counter = Counter(
invocation_counter = LabeledCounter(
namespace="apigateway", name="rest_api_execute", labels=["invocation_type"]
)
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.metrics import LabeledCounterMetric
from localstack.utils.analytics.metrics import LabeledCounter

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


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

def __init__(self, counter: LabeledCounterMetric):
def __init__(self, counter: LabeledCounter):
self.counter = counter

def __call__(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from localstack.utils.analytics.metrics import Counter
from localstack.utils.analytics.metrics import LabeledCounter

COUNTER_NAMESPACE = "cloudformation"

resources = Counter(
resources = LabeledCounter(
namespace=COUNTER_NAMESPACE, name="resources", labels=["resource_type", "missing"]
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from localstack import config
from localstack.aws.connect import InternalClientFactory, ServiceLevelClientFactory
from localstack.services.cloudformation import usage
from localstack.services.cloudformation import analytics as usage
Copy link
Member

Choose a reason for hiding this comment

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

nit: Since you renamed the module from analytics to usage, would it make sense to also change the name here, i.e. avoid the as usage?

Copy link
Member Author
@vittoriopolverino vittoriopolverino Jun 10, 2025

Choose a reason for hiding this comment

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

Absolutely, that makes total sense. I initially avoided it out of caution, in case I missed some spots during the renaming 😄
I'll do it

from localstack.services.cloudformation.deployment_utils import (
check_not_found_exception,
convert_data_types,
Expand Down
6 changes: 4 additions & 2 deletions localstack-core/localstack/services/events/analytics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import StrEnum

from localstack.utils.analytics.metrics import Counter
from localstack.utils.analytics.metrics import LabeledCounter


class InvocationStatus(StrEnum):
Expand All @@ -11,4 +11,6 @@ class InvocationStatus(StrEnum):
# number of EventBridge rule invocations per target (e.g., aws:lambda)
# - status label can be `success` or `error`, see InvocationStatus
# - service label is the target service name
rule_invocation = Counter(namespace="events", name="rule_invocations", labels=["status", "service"])
rule_invocation = LabeledCounter(
namespace="events", name="rule_invocations", labels=["status", "service"]
)
8 changes: 4 additions & 4 deletions localstack-core/localstack/services/lambda_/analytics.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from enum import StrEnum

from localstack.utils.analytics.metrics import Counter
from localstack.utils.analytics.metrics import LabeledCounter

NAMESPACE = "lambda"

hotreload_counter = Counter(namespace=NAMESPACE, name="hotreload", labels=["operation"])
hotreload_counter = LabeledCounter(namespace=NAMESPACE, name="hotreload", labels=["operation"])

function_counter = Counter(
function_counter = LabeledCounter(
namespace=NAMESPACE,
name="function",
labels=[
Expand Down Expand Up @@ -38,7 +38,7 @@ class FunctionStatus(StrEnum):
invocation_error = "invocation_error"


esm_counter = Counter(namespace=NAMESPACE, name="esm", labels=["source", "status"])
esm_counter = LabeledCounter(namespace=NAMESPACE, name="esm", labels=["source", "status"])


class EsmExecutionStatus(StrEnum):
Expand Down
6 changes: 4 additions & 2 deletions localstack-core/localstack/services/sns/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
Usage analytics for SNS internal endpoints
"""

from localstack.utils.analytics.metrics import Counter
from localstack.utils.analytics.metrics import LabeledCounter

# number of times SNS internal endpoint per resource types
# (e.g. PlatformMessage invoked 10x times, SMSMessage invoked 3x times, SubscriptionToken...)
internal_api_calls = Counter(namespace="sns", name="internal_api_call", labels=["resource_type"])
internal_api_calls = LabeledCounter(
namespace="sns", name="internal_api_call", labels=["resource_type"]
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Usage reporting for StepFunctions service
"""

from localstack.utils.analytics.metrics import Counter
from localstack.utils.analytics.metrics import LabeledCounter

# Initialize a counter to record the usage of language features for each state machine.
language_features_counter = Counter(
language_features_counter = LabeledCounter(
namespace="stepfunctions",
name="language_features_used",
labels=["query_language", "uses_variables"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
from typing import Final

import localstack.services.stepfunctions.usage as UsageMetrics
import localstack.services.stepfunctions.analytics as UsageMetrics
Copy link
Member

Choose a reason for hiding this comment

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

nit: I know this was already the case, but the casing of the import is a bit strange here. Would it make sense to just import analytics here and use it as such without renaming it?

from localstack.services.stepfunctions.asl.antlr.runtime.ASLParser import ASLParser
from localstack.services.stepfunctions.asl.component.common.query_language import (
QueryLanguageMode,
Expand Down
Loading
Loading
0