Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #767 from meln5674/feature/grafana-operator-726
Add ability to provide compressed JSON for large dashboards
- Loading branch information
Showing
10 changed files
with
332 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"io/ioutil" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// Encoded via cat | gzip | base64 | ||
const encodedCompressedDashboard = ` | ||
H4sIAAAAAAAAA3WQMU/DQAyF9/6KU2aQYAAkVliZqFgQqpzGSaxczief2wqq/nd8l5DAwOb3+dnP | ||
8nnjXEVN9ejCwfurrJTUo4Hqlcbo0T1D6msGaVwrPLonDi117gViNdmhS+Z+/ygq6ec03IAMs4FG | ||
/OJQaC18SihTAxtSqItd5YCF9dSgJaiwz1tb8GlqdAKx3zJ7pWiN2wIjBPS/0nOUqbPVpvK5OTTw | ||
6fq+L5nZwzOrTF+WsUj7wQ5bhjPbcVTisAYYF2wFU7+joChHmNPXVWg/A6XQras8Jf3rghBY4Wf3 | ||
v7Y5K997l6afpX2PI7yhJBvOf3go+LiAm6I9hWG+7LL5BgwYIaHkAQAA | ||
` | ||
|
||
const decodedDashboard = ` | ||
{ | ||
"id": null, | ||
"title": "Simple Dashboard from Config Map", | ||
"tags": [], | ||
"style": "dark", | ||
"timezone": "browser", | ||
"editable": true, | ||
"hideControls": false, | ||
"graphTooltip": 1, | ||
"panels": [], | ||
"time": { | ||
"from": "now-6h", | ||
"to": "now" | ||
}, | ||
"timepicker": { | ||
"time_options": [], | ||
"refresh_intervals": [] | ||
}, | ||
"templating": { | ||
"list": [] | ||
}, | ||
"annotations": { | ||
"list": [] | ||
}, | ||
"refresh": "5s", | ||
"schemaVersion": 17, | ||
"version": 0, | ||
"links": [] | ||
} | ||
` | ||
|
||
func TestDecompress(t *testing.T) { | ||
var expected map[string]interface{} | ||
var actual map[string]interface{} | ||
decoded, err := ioutil.ReadAll(base64.NewDecoder(base64.StdEncoding, strings.NewReader(encodedCompressedDashboard))) | ||
if err != nil { | ||
t.Log("Failed to decode", err) | ||
t.Fail() | ||
} | ||
decompressed, err := Gunzip(decoded) | ||
if err != nil { | ||
t.Log("Failed to decompress", err) | ||
t.Fail() | ||
} | ||
err = json.Unmarshal([]byte(decompressed), &actual) | ||
if err != nil { | ||
t.Log("Failed to parse JSON from decoded", err) | ||
t.Fail() | ||
} | ||
err = json.Unmarshal([]byte(decodedDashboard), &expected) | ||
if err != nil { | ||
t.Log("Failed to parse JSON from ground truth", err) | ||
t.Fail() | ||
} | ||
if !reflect.DeepEqual(expected, actual) { | ||
t.Log("Decoded JSONs were not the same") | ||
t.Fail() | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: integreatly.org/v1alpha1 | ||
kind: GrafanaDashboard | ||
metadata: | ||
name: compressed-dashboard | ||
labels: | ||
app: grafana | ||
spec: | ||
gzipJson: |- | ||
H4sIAAAAAAAAA3WQwU7DMAyG73uKqmeQ4ABIXMcjIC4ITe7iNtbSOLK9TTDt3UnS0sKBm//Pv/1bvmyapiXXPjfxGMJNUUYWMIN2y2MSVEXXvID6jkFcO1lg0Ox4/6hK7XMacCCH2UAjfnGstBM+K8rUQEcGXbWbHLEyTw63HE04lK09BJ0ag0Dyr8zBKOXGfYUJIoZf6SUqq0uus+qFxxIa+Xz76Gtm8fDM2qyvy1ii/SEftgwXtuNkxHENyFywz3/wO4qGcoI5fV2FYwpgFId1VSC1vy6IkQ1+dv9rm7PKvQ86/Uz3Hkd4Q9E8XP7wVPFpAXdVB4qH+bLr5huze+uv2AEAAA== |
23 changes: 23 additions & 0 deletions
23
deploy/examples/dashboards/DashboardFromCompressedConfigMap.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: integreatly.org/v1alpha1 | ||
kind: GrafanaDashboard | ||
metadata: | ||
name: grafana-dashboard-from-compressed-config-map | ||
labels: | ||
app: grafana | ||
spec: | ||
json: "" | ||
gzipConfigMapRef: | ||
name: simple-dashboard-from-compressed-cm | ||
key: foo | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: simple-dashboard-from-compressed-cm | ||
binaryData: | ||
foo: |- | ||
H4sIAAAAAAAAA3VQPU/EMAzd71dEnUGCAZBYYWXixILQyb24jdU0jhLfneB0/x0nLS0MbH7P78Py | ||
eWNMQ7Z5NOHg/VVBQuJRieaVxujRPEN2LUOypks8miceY8Kc0eoYOurNC8RmckKf1fj+UVGWzynH | ||
QhpmAY34xaGybeJTxjQt0JJAW+WSDlg5Rxa1QRL7ktqBz9OiTxDdltkLRV3cVjJCQP+rvVQpOuus | ||
qFxeSgOfru9d7SwanrlG8WWxRdoPethiLtyOoxCHtUD5hJ0+wu0oCKYjzO1rFOr7QCj0a5SnLH9V | ||
EAIL/GT/K5u7yr13efpZ3jsc4Q1TVnP5w0OljwtxU7GnMMyXXTbf/Wift+8BAAA= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.