Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion henry/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.0"
__version__ = "0.3.2"
37 changes: 22 additions & 15 deletions henry/commands/pulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from textwrap import fill
from typing import Sequence, cast

from looker_sdk import models
from looker_sdk.sdk.api40 import models
from looker_sdk.error import SDKError

from henry.modules import exceptions, fetcher, spinner
Expand All @@ -28,7 +28,7 @@ def check_db_connections(self):
"""Gets all db connections and runs all supported tests against them."""
print("\bTest 1/6: Checking connections")

reserved_names = ["looker__internal__analytics", "looker", "looker__ilooker"]
reserved_names = ["looker__internal__analytics__replica", "looker__internal__analytics", "looker", "looker__ilooker"]
db_connections: Sequence[models.DBConnection] = list(
filter(lambda c: c.name not in reserved_names, self.sdk.all_connections())
)
Expand All @@ -40,16 +40,20 @@ def check_db_connections(self):
for connection in db_connections:
assert connection.dialect
assert isinstance(connection.name, str)
resp = self.sdk.test_connection(
connection.name,
models.DelimSequence(connection.dialect.connection_tests),
)
results = list(filter(lambda r: r.status == "error", resp))
errors = [f"- {fill(cast(str, e.message), width=100)}" for e in results]
try:
resp = self.sdk.test_connection(
connection.name,
models.DelimSequence(connection.dialect.connection_tests),
)
results = list(filter(lambda r: r.status == "error", resp))
errors = [f"- {fill(cast(str, e.message), width=100)}" for e in results]
except SDKError:
results = []
errors = ["API JSONDecode Error"]
resp = self.sdk.run_inline_query(
"json",
models.WriteQuery(
model="i__looker",
model="system__activity",
view="history",
fields=["history.query_run_count"],
filters={"history.connection_name": connection.name},
Expand All @@ -76,7 +80,7 @@ def check_dashboard_performance(self):
"30 seconds in the last 7 days"
)
request = models.WriteQuery(
model="i__looker",
model="system__activity",
view="history",
fields=["dashboard.title, query.count"],
filters={
Expand All @@ -99,7 +103,7 @@ def check_dashboard_errors(self):
"\bTest 3/6: Checking for dashboards with erroring queries in the last 7 days" # noqa: B950
)
request = models.WriteQuery(
model="i__looker",
model="system__activity",
view="history",
fields=["dashboard.title", "history.query_run_count"],
filters={
Expand All @@ -120,7 +124,7 @@ def check_explore_performance(self):
"""Prints a list of the slowest running explores."""
print("\bTest 4/6: Checking for the slowest explores in the past 7 days")
request = models.WriteQuery(
model="i__looker",
model="system__activity",
view="history",
fields=["query.model", "query.view", "history.average_runtime"],
filters={
Expand Down Expand Up @@ -148,7 +152,7 @@ def check_schedule_failures(self):
"""Prints a list of schedules that have failed in the past 7 days."""
print("\bTest 5/6: Checking for failing schedules")
request = models.WriteQuery(
model="i__looker",
model="system__activity",
view="scheduled_plan",
fields=["scheduled_job.name", "scheduled_job.count"],
filters={
Expand All @@ -166,6 +170,9 @@ def check_schedule_failures(self):
def check_legacy_features(self):
"""Prints a list of enabled legacy features."""
print("\bTest 6/6: Checking for enabled legacy features")
lf = list(filter(lambda f: f.enabled, self.sdk.all_legacy_features()))
legacy_features = [{"Feature": cast(str, f.name)} for f in lf]
try:
lf = list(filter(lambda f: f.enabled, self.sdk.all_legacy_features()))
legacy_features = [{"Feature": cast(str, f.name)} for f in lf]
except SDKError:
legacy_features = [["Unable to pull legacy features due to SDK error"]]
self._tabularize_and_print(legacy_features)
18 changes: 9 additions & 9 deletions henry/modules/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ def get_used_models(self) -> Dict[str, int]:
resp = self.sdk.run_inline_query(
"json",
models.WriteQuery(
model="i__looker",
model="system__activity",
view="history",
fields=["history.query_run_count, query.model"],
fields=["history.query_run_count", "query.model"],
filters={
"history.created_date": self.timeframe,
"query.model": "-system^_^_activity, -i^_^_looker",
"history.query_run_count": ">0",
"user.dev_mode": "No",
"user.dev_branch_name": "NULL",
},
limit="5000",
),
Expand Down Expand Up @@ -177,15 +177,15 @@ def get_used_explores(
resp = self.sdk.run_inline_query(
"json",
models.WriteQuery(
model="i__looker",
model="system__activity",
view="history",
fields=["query.view", "history.query_run_count"],
filters={
"history.created_date": self.timeframe,
"query.model": model.replace("_", "^_") if model else "",
"history.query_run_count": ">0",
"query.view": explore,
"user.dev_mode": "No",
"user.dev_branch_name": "NULL",
},
limit="5000",
),
Expand Down Expand Up @@ -225,13 +225,13 @@ def get_used_explore_fields(
resp = self.sdk.run_inline_query(
"json",
models.WriteQuery(
model="i__looker",
model="system__activity",
view="history",
fields=[
"query.model",
"query.view",
"query.formatted_fields",
"query.formatted_filters",
"query.filters",
"history.query_run_count",
],
filters={
Expand Down Expand Up @@ -261,9 +261,9 @@ def get_used_explore_fields(
# A field used as a filter in a query is not listed in
# query.formatted_fields BUT if the field is used as both a filter
# and a dimension/measure, it's listed in both query.formatted_fields
# and query.formatted_filters. The recorded variable keeps track of
# and query.filters. The recorded variable keeps track of
# this, so that no double counting occurs.
filters = row["query.formatted_filters"]
filters = row["query.filters"]
if filters:
parsed_filters = re.findall(r"(\w+\.\w+)+", filters)
for f in parsed_filters:
Expand Down