Add tests for opmon dashboard generation.

This commit is contained in:
Marina Samuel 2021-10-18 20:36:41 -04:00
Родитель 98ef40718a
Коммит 7b58489d7c
3 изменённых файлов: 162 добавлений и 1 удалений

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

@ -25,7 +25,7 @@ DEFAULT_SPOKE = "looker-spoke-default"
OPMON_BUCKET_NAME = "operational_monitoring"
PROD_PROJECT = "moz-fx-data-shared-prod"
PROJECTS_FOLDER = "projects/"
DATA_TYPES = {"histogram", "scalar"}
DATA_TYPES = ["histogram", "scalar"]
def _normalize_slug(name):

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

@ -384,6 +384,21 @@ def test_namespaces_full(
},
},
"operational_monitoring": {
"dashboards": {
"op_mon": {
"tables": [
{
"explore": "op_mon_histogram",
"table": "moz-fx-data-shared-prod.operational_monitoring.test_histogram",
},
{
"explore": "op_mon_scalar",
"table": "moz-fx-data-shared-prod.operational_monitoring.test_scalar",
},
],
"type": "operational_monitoring_dashboard",
}
},
"explores": {
"op_mon_histogram": {
"branches": ["enabled", "disabled"],

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

@ -1,10 +1,13 @@
import re
from textwrap import dedent
import lkml
import pandas as pd
import pytest
from google.cloud import bigquery
from google.cloud.bigquery.schema import SchemaField
from generator.dashboards import OperationalMonitoringDashboard
from generator.explores import OperationalMonitoringExplore
from generator.views import (
OperationalMonitoringHistogramView,
@ -29,6 +32,28 @@ TABLE_SCALAR = (
class MockClient:
"""Mock bigquery.Client."""
def query(self, query):
class QueryJob:
def result(self):
class ResultObject:
def to_dataframe(self):
if "probe" in query:
return pd.DataFrame(
[["GC_MS"], ["GC_MS_CONTENT"]], columns=["probe"]
)
pattern = re.compile("SELECT DISTINCT (.*), COUNT")
column = pattern.findall(query)[0]
data = [["Windows", 10]]
if column == "cores_count":
data = [["4", 100]]
return pd.DataFrame(data, columns=[column, "count"])
return ResultObject()
return QueryJob()
def get_table(self, table_ref):
"""Mock bigquery.Client.get_table."""
@ -112,6 +137,17 @@ def operational_monitoring_explore(tmp_path, operational_monitoring_histogram_vi
)
@pytest.fixture()
def operational_monitoring_dashboard():
return OperationalMonitoringDashboard(
"Fission",
"fission",
"newspaper",
"operational_monitoring",
[{"table": TABLE_HISTOGRAM, "explore": "fission_histogram"}],
)
def test_view_from_dict(operational_monitoring_histogram_view):
actual = OperationalMonitoringHistogramView.from_dict(
"operational_monitoring",
@ -237,3 +273,113 @@ def test_explore_lookml(operational_monitoring_explore):
actual = operational_monitoring_explore.to_lookml(None)
print_and_test(expected=expected, actual=actual)
def test_dashboard_lookml(operational_monitoring_dashboard):
mock_bq_client = MockClient()
expected = dedent(
"""\
- dashboard: fission
title: Fission
layout: newspaper
preferred_viewer: dashboards-next
elements:
- title: Gc Ms
name: Gc Ms
explore: fission_histogram
type: "looker_line"
fields: [
fission_histogram.build_id,
fission_histogram.branch,
fission_histogram.high,
fission_histogram.low,
fission_histogram.percentile
]
pivots: [fission_histogram.branch]
filters:
fission_histogram.probe: GC_MS
row: 0
col: 0
width: 12
height: 8
listen:
Percentile: fission_histogram.percentile_conf
Cores Count: fission_histogram.cores_count
Os: fission_histogram.os
- title: Gc Ms Content
name: Gc Ms Content
explore: fission_histogram
type: "looker_line"
fields: [
fission_histogram.build_id,
fission_histogram.branch,
fission_histogram.high,
fission_histogram.low,
fission_histogram.percentile
]
pivots: [fission_histogram.branch]
filters:
fission_histogram.probe: GC_MS_CONTENT
row: 0
col: 12
width: 12
height: 8
listen:
Percentile: fission_histogram.percentile_conf
Cores Count: fission_histogram.cores_count
Os: fission_histogram.os
filters:
- name: Percentile
title: Percentile
type: number_filter
default_value: '50'
allow_multiple_values: false
required: true
ui_config:
type: dropdown_menu
display: inline
options:
- '10'
- '20'
- '30'
- '40'
- '50'
- '60'
- '70'
- '80'
- '90'
- '95'
- '99'
- title: Cores Count
name: Cores Count
type: string_filter
default_value: 4
allow_multiple_values: false
required: true
ui_config:
type: dropdown_menu
display: inline
options:
- 4
- title: Os
name: Os
type: string_filter
default_value: Windows
allow_multiple_values: false
required: true
ui_config:
type: dropdown_menu
display: inline
options:
- Windows
"""
)
actual, _ = operational_monitoring_dashboard.to_lookml(mock_bq_client)
print_and_test(expected=expected, actual=dedent(actual))