Skip to content

Commit ee25652

Browse files
committed
update usage doc
1 parent 799ec8d commit ee25652

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

lib/superset/services/dashboard_report.rb

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
# providing count of charts, datasets, and databases used in each dashboard
33
# as well as optional data sovereignty information
44

5+
# Data Sovereignty in this context requires that all datasets used in a dashboard are from one database schema only.
6+
# Primarily used to identify potential issues with embedded dashboards where data sovereignty is a concern.
7+
8+
# Usage:
9+
# Superset::Services::DashboardReport.new(dashboard_ids: [1,2,3]).perform
10+
511
module Superset
612
module Services
713
class DashboardReport
@@ -36,27 +42,29 @@ def display_data_sovereignty_report
3642

3743
# possible data sovereignty issues
3844
def data_sovereignty_issues
39-
@report.map do |dashboard|
40-
reasons = []
41-
chart_dataset_ids = dashboard[:datasets][:chart_datasets].map{|d| d[:id]}
42-
43-
# invalid if any filters datasets are not part of the chart datasets
44-
unknown_datasets = dashboard[:filters][:filter_dataset_ids] - chart_dataset_ids
45-
if unknown_datasets.any?
46-
reasons << "WARNING: One or more filter datasets is not included in chart datasets for " \
47-
"filter dataset ids: #{unknown_datasets.join(', ')}."
48-
reasons << "DETAILS: #{unknown_dataset_details(unknown_datasets)}"
49-
end
50-
51-
# invalid if any filters datasets are not part of the chart datasets
52-
chart_dataset_schemas = dashboard[:datasets][:chart_datasets].map{|d| d[:schema]}.uniq
53-
if chart_dataset_schemas.count > 1
54-
reasons << "ERROR: Multiple distinct chart dataset schemas found. Expected 1. Found #{chart_dataset_schemas.count}. " \
55-
"schema names: #{chart_dataset_schemas.join(', ') }"
56-
end
57-
58-
{ reasons: reasons, dashboard: dashboard } if reasons.any?
59-
end.compact
45+
@data_sovereignty_issues ||= begin
46+
@report.map do |dashboard|
47+
reasons = []
48+
chart_dataset_ids = dashboard[:datasets][:chart_datasets].map{|d| d[:id]}
49+
50+
# invalid if any filters datasets are not part of the chart datasets
51+
unknown_datasets = dashboard[:filters][:filter_dataset_ids] - chart_dataset_ids
52+
if unknown_datasets.any?
53+
reasons << "WARNING: One or more filter datasets is not included in chart datasets for " \
54+
"filter dataset ids: #{unknown_datasets.join(', ')}."
55+
reasons << "DETAILS: #{unknown_dataset_details(unknown_datasets)}"
56+
end
57+
58+
# invalid if any filters datasets are not part of the chart datasets
59+
chart_dataset_schemas = dashboard[:datasets][:chart_datasets].map{|d| d[:schema]}.uniq
60+
if chart_dataset_schemas.count > 1
61+
reasons << "ERROR: Multiple distinct chart dataset schemas found. Expected 1. Found #{chart_dataset_schemas.count}. " \
62+
"schema names: #{chart_dataset_schemas.join(', ') }"
63+
end
64+
65+
{ reasons: reasons, dashboard: dashboard } if reasons.any?
66+
end.compact
67+
end
6068
end
6169

6270
def unknown_dataset_details(unknown_datasets)
@@ -66,8 +74,6 @@ def unknown_dataset_details(unknown_datasets)
6674
{ id: d.id, name: d.title }
6775
rescue Happi::Error::NotFound => e
6876
{ id: dataset_id, name: '>>>> ERROR: DATASET DOES NOT EXIST <<<<' }
69-
rescue => e
70-
{ id: dataset_id, name: '>>>> ERROR: #{e} <<<<' }
7177
end
7278
end
7379

0 commit comments

Comments
 (0)