Skip to content

Commit 7f97b18

Browse files
authored
Events: migrate to new Counter type for Event Rule invocation analytics (#12388)
1 parent cf90cd4 commit 7f97b18

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from enum import StrEnum
2+
3+
from localstack.utils.analytics.metrics import Counter
4+
5+
6+
class InvocationStatus(StrEnum):
7+
success = "success"
8+
error = "error"
9+
10+
11+
# number of EventBridge rule invocations per target (e.g., aws:lambda)
12+
# - status label can be `success` or `error`, see InvocationStatus
13+
# - service label is the target service name
14+
rule_invocation = Counter(namespace="events", name="rule_invocations", labels=["status", "service"])

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@
154154
TargetSenderDict,
155155
TargetSenderFactory,
156156
)
157-
from localstack.services.events.usage import rule_error, rule_invocation
158157
from localstack.services.events.utils import (
159158
TARGET_ID_PATTERN,
160159
extract_connection_name,
@@ -172,6 +171,8 @@
172171
from localstack.utils.strings import long_uid
173172
from localstack.utils.time import TIMESTAMP_FORMAT_TZ, timestamp
174173

174+
from .analytics import InvocationStatus, rule_invocation
175+
175176
LOG = logging.getLogger(__name__)
176177

177178
ARCHIVE_TARGET_ID_NAME_PATTERN = re.compile(r"^Events-Archive-(?P<name>[a-zA-Z0-9_-]+)$")
@@ -1889,9 +1890,16 @@ def _process_rules(
18891890
target_sender = self._target_sender_store[target_unique_id]
18901891
try:
18911892
target_sender.process_event(event_formatted.copy())
1892-
rule_invocation.record(target_sender.service)
1893+
rule_invocation.labels(
1894+
status=InvocationStatus.success,
1895+
service=target_sender.service,
1896+
).increment()
1897+
18931898
except Exception as error:
1894-
rule_error.record(target_sender.service)
1899+
rule_invocation.labels(
1900+
status=InvocationStatus.error,
1901+
service=target_sender.service,
1902+
).increment()
18951903
# Log the error but don't modify the response
18961904
LOG.info(
18971905
json.dumps(

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

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)