8000 refactor: metrics instrumentation framework typing and structure (#12… · localstack/localstack@5b623bf · GitHub
[go: up one dir, main page]

Skip to content

Commit 5b623bf

Browse files
refactor: metrics instrumentation framework typing and structure (#12717)
1 parent f6075f6 commit 5b623bf

File tree

16 files changed

+428
-404
lines changed

16 files changed

+428
-404
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from localstack.utils.analytics.metrics import Counter
1+
from localstack.utils.analytics.metrics import LabeledCounter
22

3-
invocation_counter = Counter(
3+
invocation_counter = LabeledCounter(
44
namespace="apigateway", name="rest_api_execute", labels=["invocation_type"]
55
)

localstack-core/localstack/services/apigateway/next_gen/execute_api/handlers/analytics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22

33
from localstack.http import Response
4-
from localstack.utils.analytics.metrics import LabeledCounterMetric
4+
from localstack.utils.analytics.metrics import LabeledCounter
55

66
from ..api import RestApiGatewayHandler, RestApiGatewayHandlerChain
77
from ..context import RestApiInvocationContext
@@ -10,9 +10,9 @@
1010

1111

1212
class IntegrationUsageCounter(RestApiGatewayHandler):
13-
counter: LabeledCounterMetric
13+
counter: LabeledCounter
1414

15-
def __init__(self, counter: LabeledCounterMetric):
15+
def __init__(self, counter: LabeledCounter):
1616
self.counter = counter
1717

1818
def __call__(
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from localstack.utils.analytics.metrics import Counter
1+
from localstack.utils.analytics.metrics import LabeledCounter
22

33
COUNTER_NAMESPACE = "cloudformation"
44

5-
resources = Counter(
5+
resources = LabeledCounter(
66
namespace=COUNTER_NAMESPACE, name="resources", labels=["resource_type", "missing"]
77
)

localstack-core/localstack/services/cloudformation/resource_provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from localstack import config
2121
from localstack.aws.connect import InternalClientFactory, ServiceLevelClientFactory
22-
from localstack.services.cloudformation import usage
22+
from localstack.services.cloudformation import analytics
2323
from localstack.services.cloudformation.deployment_utils import (
2424
check_not_found_exception,
2525
convert_data_types,
@@ -581,7 +581,7 @@ def try_load_resource_provider(resource_type: str) -> ResourceProvider | None:
581581
# 2. try to load community resource provider
582582
try:
583583
plugin = plugin_manager.load(resource_type)
584-
usage.resources.labels(resource_type=resource_type, missing=False).increment()
584+
analytics.resources.labels(resource_type=resource_type, missing=False).increment()
585585
return plugin.factory()
586586
except ValueError:
587587
# could not find a plugin for that name
@@ -600,7 +600,7 @@ def try_load_resource_provider(resource_type: str) -> ResourceProvider | None:
600600
f'No resource provider found for "{resource_type}"',
601601
)
602602

603-
usage.resources.labels(resource_type=resource_type, missing=True).increment()
603+
analytics.resources.labels(resource_type=resource_type, missing=True).increment()
604604

605605
if config.CFN_IGNORE_UNSUPPORTED_RESOURCE_TYPES:
606606
# TODO: figure out a better way to handle non-implemented here?

localstack-core/localstack/services/events/analytics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from enum import StrEnum
22

3-
from localstack.utils.analytics.metrics import Counter
3+
from localstack.utils.analytics.metrics import LabeledCounter
44

55

66
class InvocationStatus(StrEnum):
@@ -11,4 +11,6 @@ class InvocationStatus(StrEnum):
1111
# number of EventBridge rule invocations per target (e.g., aws:lambda)
1212
# - status label can be `success` or `error`, see InvocationStatus
1313
# - service label is the target service name
14-
rule_invocation = Counter(namespace="events", name="rule_invocations", labels=["status", "service"])
14+
rule_invocation = LabeledCounter(
15+
namespace="events", name="rule_invocations", labels=["status", "service"]
16+
)

localstack-core/localstack/services/lambda_/analytics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from enum import StrEnum
22

3-
from localstack.utils.analytics.metrics import Counter
3+
from localstack.utils.analytics.metrics import LabeledCounter
44

55
NAMESPACE = "lambda"
66

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

9-
function_counter = Counter(
9+
function_counter = LabeledCounter(
1010
namespace=NAMESPACE,
1111
name="function",
1212
labels=[
@@ -38,7 +38,7 @@ class FunctionStatus(StrEnum):
3838
invocation_error = "invocation_error"
3939

4040

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

4343

4444
class EsmExecutionStatus(StrEnum):

localstack-core/localstack/services/sns/analytics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
Usage analytics for SNS internal endpoints
33
"""
44

5-
from localstack.utils.analytics.metrics import Counter
5+
from localstack.utils.analytics.metrics import LabeledCounter
66

77
# number of times SNS internal endpoint per resource types
88
# (e.g. PlatformMessage invoked 10x times, SMSMessage invoked 3x times, SubscriptionToken...)
9-
internal_api_calls = Counter(namespace="sns", name="internal_api_call", labels=["resource_type"])
9+
internal_api_calls = LabeledCounter(
10+
namespace="sns", name="internal_api_call", labels=["resource_type"]
11+
)

localstack-core/localstack/services/stepfunctions/usage.py renamed to localstack-core/localstack/services/stepfunctions/analytics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
Usage reporting for StepFunctions service
33
"""
44

5-
from localstack.utils.analytics.metrics import Counter
5+
from localstack.utils.analytics.metrics import LabeledCounter
66

77
# Initialize a counter to record the usage of language features for each state machine.
8-
language_features_counter = Counter(
8+
language_features_counter = LabeledCounter(
99
namespace="stepfunctions",
1010
name="language_features_used",
1111
labels=["query_language", "uses_variables"],

localstack-core/localstack/services/stepfunctions/asl/static_analyser/usage_metrics_static_analyser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
from typing import Final
55

6-
import localstack.services.stepfunctions.usage as UsageMetrics
6+
from localstack.services.stepfunctions import analytics
77
from localstack.services.stepfunctions.asl.antlr.runtime.ASLParser import ASLParser
88
from localstack.services.stepfunctions.asl.component.common.query_language import (
99
QueryLanguageMode,
@@ -40,7 +40,7 @@ def process(definition: str) -> UsageMetricsStaticAnalyser:
4040
uses_variables = analyser.uses_variables
4141

4242
# Count.
43-
UsageMetrics.language_features_counter.labels(
43+
analytics.language_features_counter.labels(
4444
query_language=language_used, uses_variables=uses_variables
4545
).increment()
4646
except Exception as e:

0 commit comments

Comments
 (0)
0