Merge pull request #22 from fbertsch/namespaces_explores

Namespaces explores
This commit is contained in:
Frank Bertsch 2021-03-22 15:10:42 -04:00 коммит произвёл GitHub
Родитель 5590def6b5 8c6ad0d6e3
Коммит 674b34adda
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 53 добавлений и 0 удалений

34
generator/explores.py Normal file
Просмотреть файл

@ -0,0 +1,34 @@
"""All possible generated explores."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Dict, Iterator, List
@dataclass
class Explore:
"""A generic explore."""
name: str
type: str
views: Dict[str, str]
def to_dict(self) -> dict:
"""Explore instance represented as a dict."""
return {self.name: {"type": self.type, "views": self.views}}
@dataclass
class PingExplore(Explore):
"""A Ping Table explore."""
@staticmethod
def from_views(views: Dict[str, List[Dict[str, str]]]) -> Iterator[PingExplore]:
"""Generate all possible PingExplores from the views."""
for view, channel_infos in views.items():
is_ping_tbl = all((c.get("is_ping_table", False) for c in channel_infos))
if is_ping_tbl:
yield PingExplore(view, "ping_explore", {"base_view": view})
explore_types = [PingExplore]

Просмотреть файл

@ -10,10 +10,13 @@ from io import BytesIO
from itertools import groupby
from operator import itemgetter
from pathlib import Path
from typing import Dict, List
import click
import yaml
from .explores import explore_types
PROBE_INFO_BASE_URI = "https://probeinfo.telemetry.mozilla.org"
OMIT_VIEWS = {"deletion_request"}
@ -42,6 +45,15 @@ def _get_views(uri):
return views
def _get_explores(views: Dict[str, List[Dict[str, str]]]) -> dict:
explores = {}
for klass in explore_types:
for explore in klass.from_views(views):
explores.update(explore.to_dict())
return explores
@click.command(help=__doc__)
@click.option(
"--custom-namespaces",
@ -100,6 +112,7 @@ def namespaces(custom_namespaces, generated_sql_uri, app_listings_uri):
namespaces[app_name] = {
"canonical_app_name": canonical_app_name,
"views": dict(views),
"explores": _get_explores(dict(views)),
}
if custom_namespaces is not None:

Просмотреть файл

@ -65,6 +65,7 @@ def generated_sql_uri(tmp_path):
)
info.size = len(content)
tar.addfile(info, BytesIO(content.encode()))
return dest.absolute().as_uri()
@ -126,6 +127,11 @@ def test_namespaces(runner, custom_namespaces, generated_sql_uri, app_listings_u
table: mozdata.custom.baseline
glean-app:
canonical_app_name: Glean App
explores:
baseline:
type: ping_explore
views:
base_view: baseline
views:
baseline:
- channel: release