Skip to content

Commit 9c73e31

Browse files
authored
Fix invalid dashboards and add validation (#83)
These dashboards had an invalid combination of the `format` and `format_input` fields. The `format_input` field only works with 'format = size'. Fix this by making them 'size' formats and add a validation for it so this can't happen again.
1 parent 6012b87 commit 9c73e31

5 files changed

Lines changed: 18 additions & 5 deletions

File tree

Rakefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Dashboard
2727
REQUIRED_VISUAL_FIELDS.each do |field|
2828
required_field(*visual_base, field)
2929
end
30+
format_input_only_for_size(visual, visual_base)
3031

3132
visual.fetch("metrics", []).each_with_index do |metric, metric_index|
3233
# Validate base metric fields
@@ -89,6 +90,18 @@ class Dashboard
8990
issues << "No '#{Array(field).join(".")}' field present"
9091
end
9192

93+
# The 'format_input' field declares the unit of an incoming size value. It is
94+
# only used when the visual's 'format' is 'size'; the server unsets it for
95+
# any other format on import.
96+
def format_input_only_for_size(visual, visual_base)
97+
return unless visual.key?("format_input")
98+
return if visual["format"] == "size"
99+
100+
field = [*visual_base, "format_input"].join(".")
101+
issues << "The '#{field}' field is only allowed when 'format' is 'size', " \
102+
"but 'format' is #{visual["format"].inspect}"
103+
end
104+
92105
def dashboard
93106
definition["dashboard"]
94107
end

dashboards/aws/databases_rds.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
{
119119
"type": "timeseries",
120120
"display": "line",
121-
"format": "throughput",
121+
"format": "size",
122122
"format_input": "byte",
123123
"draw_null_as_zero": true,
124124
"title": "Read Throughput vs Write Throughput",
@@ -173,7 +173,7 @@
173173
{
174174
"type": "timeseries",
175175
"display": "line",
176-
"format": "throughput",
176+
"format": "size",
177177
"format_input": "byte",
178178
"draw_null_as_zero": true,
179179
"title": "Network Receive vs Transmit Throughput",

dashboards/aws/databases_redshift.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
{
138138
"type": "timeseries",
139139
"display": "line",
140-
"format": "throughput",
140+
"format": "size",
141141
"format_input": "byte",
142142
"draw_null_as_zero": true,
143143
"title": "Network Throughput",

dashboards/aws/messaging_msk.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
{
6464
"type": "timeseries",
6565
"display": "line",
66-
"format": "throughput",
66+
"format": "size",
6767
"format_input": "byte",
6868
"draw_null_as_zero": true,
6969
"title": "Throughput",

dashboards/aws/storage_efs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
{
3838
"type": "timeseries",
3939
"display": "line",
40-
"format": "throughput",
40+
"format": "size",
4141
"format_input": "byte",
4242
"draw_null_as_zero": false,
4343
"title": "Permitted Throughput",

0 commit comments

Comments
 (0)