feat: per-db add metrics (#20990)

* feat: per-db add metrics

* Add unit tests
This commit is contained in:
Beto Dealmeida
2022-08-08 12:07:16 -07:00
committed by GitHub
parent 846529a500
commit bb3871ddaf
5 changed files with 135 additions and 10 deletions

View File

@@ -154,6 +154,21 @@ class LimitMethod: # pylint: disable=too-few-public-methods
FORCE_LIMIT = "force_limit"
class MetricType(TypedDict, total=False):
"""
Type for metrics return by `get_metrics`.
"""
metric_name: str
expression: str
verbose_name: Optional[str]
metric_type: Optional[str]
description: Optional[str]
d3format: Optional[str]
warning_text: Optional[str]
extra: Optional[str]
class BaseEngineSpec: # pylint: disable=too-many-public-methods
"""Abstract class for database engine specific configurations
@@ -1054,6 +1069,26 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
"""
return inspector.get_columns(table_name, schema)
@classmethod
def get_metrics( # pylint: disable=unused-argument
cls,
database: "Database",
inspector: Inspector,
table_name: str,
schema: Optional[str],
) -> List[MetricType]:
"""
Get all metrics from a given schema and table.
"""
return [
{
"metric_name": "count",
"verbose_name": "COUNT(*)",
"metric_type": "count",
"expression": "COUNT(*)",
}
]
@classmethod
def where_latest_partition( # pylint: disable=too-many-arguments,unused-argument
cls,