2
2
# providing count of charts, datasets, and databases used in each dashboard
3
3
# as well as optional data sovereignty information
4
4
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
+
5
11
module Superset
6
12
module Services
7
13
class DashboardReport
@@ -36,27 +42,29 @@ def display_data_sovereignty_report
36
42
37
43
# possible data sovereignty issues
38
44
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
60
68
end
61
69
62
70
def unknown_dataset_details ( unknown_datasets )
@@ -66,8 +74,6 @@ def unknown_dataset_details(unknown_datasets)
66
74
{ id : d . id , name : d . title }
67
75
rescue Happi ::Error ::NotFound => e
68
76
{ id : dataset_id , name : '>>>> ERROR: DATASET DOES NOT EXIST <<<<' }
69
- rescue => e
70
- { id : dataset_id , name : '>>>> ERROR: #{e} <<<<' }
71
77
end
72
78
end
73
79
0 commit comments