Skip to content

Commit

Permalink
feat(generic-metrics): Add generic metrics interface (#46957)
Browse files Browse the repository at this point in the history
This is a draft of the (very initial) interface that product teams would
use for sending the different metrics. The Kafka implementation of this
would actually construct metrics messages and produce them to the ingest
topic via the Producer API.

The use case registry is also included in this, which is just an Enum
currently.

I'm wondering if there's any obvious things I'm missing in this initial
scaffolding code, as well as if there's anything I should look out for
as we build upon this.
  • Loading branch information
ayirr7 committed Apr 13, 2023
1 parent a5f44d6 commit 4ee50b2
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/sentry/sentry_metrics/metrics_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from abc import ABC, abstractmethod
from typing import Mapping, Optional, Sequence, Union

from sentry.sentry_metrics.use_case_id_registry import UseCaseID


class GenericMetricsBackend(ABC):
@abstractmethod
def counter(
self,
use_case_id: UseCaseID,
org_id: int,
project_id: int,
metric_name: str,
value: Union[int, float],
unit: Optional[str],
tags: Mapping[str, str],
) -> None:

"""
Used for emitting a counter metric for internal use cases only.
Ensure that the use_case_id passed in has been registered
in the UseCaseID enum.
"""

raise NotImplementedError()

@abstractmethod
def set(
self,
use_case_id: UseCaseID,
org_id: int,
project_id: int,
metric_name: str,
value: Sequence[int],
unit: Optional[str],
tags: Mapping[str, str],
) -> None:

"""
Used for emitting a set metric for internal use cases only. Can support
a sequence of values. Ensure that the use_case_id passed in has
been registered in the UseCaseID enum.
"""
raise NotImplementedError()

@abstractmethod
def distribution(
self,
use_case_id: UseCaseID,
org_id: int,
project_id: int,
metric_name: str,
value: Sequence[Union[int, float]],
unit: Optional[str],
tags: Mapping[str, str],
) -> None:

"""
Used for emitting a distribution metric for internal use cases only. Can
support a sequence of values. Ensure that the use_case_id passed in
has been registered in the UseCaseID enum.
"""
raise NotImplementedError()
22 changes: 22 additions & 0 deletions src/sentry/sentry_metrics/use_case_id_registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import annotations

from enum import Enum
from typing import Mapping

from sentry.sentry_metrics.configuration import UseCaseKey


class UseCaseID(Enum):
TRANSACTIONS = "transactions"
SESSIONS = "sessions"


# UseCaseKey will be renamed to MetricPathKey
METRIC_PATH_MAPPING: Mapping[UseCaseID, UseCaseKey] = {
UseCaseID.SESSIONS: UseCaseKey.RELEASE_HEALTH,
UseCaseID.TRANSACTIONS: UseCaseKey.PERFORMANCE,
}


def get_metric_path_from_usecase(use_case: UseCaseID) -> UseCaseKey:
return METRIC_PATH_MAPPING[use_case]

0 comments on commit 4ee50b2

Please sign in to comment.