-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ddm): Add new metrics/query endpoint base code (#64785)
- Loading branch information
1 parent
bd5b3c7
commit f4541c8
Showing
15 changed files
with
1,422 additions
and
14 deletions.
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
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
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
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,3 @@ | ||
from .api import run_metrics_queries_plan | ||
|
||
__all__ = ["run_metrics_queries_plan"] |
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,61 @@ | ||
from collections.abc import Sequence | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
from enum import Enum | ||
from typing import Union | ||
|
||
from sentry.models.environment import Environment | ||
from sentry.models.organization import Organization | ||
from sentry.models.project import Project | ||
|
||
|
||
# TODO: lift out types in `types.py` once endpoint is finished. | ||
class FormulaOrder(Enum): | ||
ASC = "asc" | ||
DESC = "desc" | ||
|
||
@classmethod | ||
# Used `Union` because `|` conflicts with the parser. | ||
def from_string(cls, value: str) -> Union["FormulaOrder", None]: | ||
for v in cls: | ||
if v.value == value: | ||
return v | ||
|
||
return None | ||
|
||
|
||
@dataclass(frozen=True) | ||
class FormulaDefinition: | ||
mql: str | ||
order: FormulaOrder | None | ||
limit: int | None | ||
|
||
|
||
class MetricsQueriesPlan: | ||
def __init__(self): | ||
self._queries: dict[str, str] = {} | ||
self._formulas: list[FormulaDefinition] = [] | ||
|
||
def declare_query(self, name: str, mql: str) -> "MetricsQueriesPlan": | ||
self._queries[name] = mql | ||
return self | ||
|
||
def apply_formula( | ||
self, mql: str, order: FormulaOrder | None = None, limit: int | None = None | ||
) -> "MetricsQueriesPlan": | ||
self._formulas.append(FormulaDefinition(mql=mql, order=order, limit=limit)) | ||
return self | ||
|
||
|
||
def run_metrics_queries_plan( | ||
metrics_queries_plan: MetricsQueriesPlan, | ||
start: datetime, | ||
end: datetime, | ||
interval: int, | ||
organization: Organization, | ||
projects: Sequence[Project], | ||
environments: Sequence[Environment], | ||
referrer: str, | ||
): | ||
# TODO: implement new querying logic. | ||
return None |
Oops, something went wrong.