-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
feat(generic-metrics): Add generic metrics interface #46957
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
a880b35
create starter file
ayirr7 6332cdc
scaffold for interface
ayirr7 a195e70
add use case registry, first attempt
ayirr7 05952a2
create base class for interface
ayirr7 8558b04
update enum class
ayirr7 525049f
stub class for generic metrics backend/interface
ayirr7 2d7b9b6
renames
ayirr7 cf44caf
fix typing
ayirr7 f342ded
fix typing
ayirr7 ce1e05c
fix typing
ayirr7 5fa2aaf
fix typign again
ayirr7 0c21461
make abstract class
ayirr7 565411e
add use case key mapping
ayirr7 c6032fd
add mapping function
ayirr7 dd51b80
fix typing
ayirr7 076c2f3
remove hardcoded dict
ayirr7 faa5db4
use regular ABC
ayirr7 73cb703
remove kafka interface for now
ayirr7 5931748
add sequence, float
ayirr7 63af343
add string to sets
ayirr7 4fb4c29
fix typing
ayirr7 f2dc617
change class to enum
ayirr7 b0d389b
remove str
ayirr7 1cc5cda
add unit and docstring
ayirr7 7486191
fix spacing
ayirr7 240f90e
Merge branch 'master' of github.com:getsentry/sentry into expand-metr…
ayirr7 5db95d7
change docstrings
ayirr7 e6e01f2
remove use case to namespace mapping
ayirr7 7f20f17
change use case id to be the same as namespace always
ayirr7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate from Filippo's comment, I think on the base class we should have docstrings for each method. |
||
@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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
|
||
|
||
john-z-yang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def get_metric_path_from_usecase(use_case: UseCaseID) -> UseCaseKey: | ||
return METRIC_PATH_MAPPING[use_case] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this interface is going to produce on Kafka it will be asynchronous. Still you will likely want to allow the client to wait for the message to be acknowledged (callback). How do you plan to support this use case?
You will likely want an interface that allows you to swap the backend (relay or kafka) but still allow delivery guarantee. How will it look like in relay ? Will the call be synchronous ?
There are multiple ways to achieve this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, to start, maybe we can have an aysnc api and a sync api. I would start working on this while building the Kafka backend, which will be the next PR. Is there anything else specific to this PR that would need to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should figure out how the async interface looks like (how the client receives the callback, is that a
future
?) at this point as you will need such interface immediately for Kafka.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I am thinking about that for the Kafka implementation. Since this PR implements the
UseCaseID
though, it's a bit blocking for some other work. How would it be if we merged the current state of the interface and, in another PR, revisit it as needed + build the Kafka implementation?