Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exported dashboards for sharing, created dashboard export script, upload dashboard github action and updated documentation #641

Merged
merged 12 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
76 changes: 76 additions & 0 deletions config/observability/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,79 @@ In the modal popup click **Export** and then **Save to file**.
Alerting rules can be defined in [PrometheusRules](https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/user-guides/alerting.md#configuring-alertmanager-in-prometheus) resources.
The can be viewed in the Prometheus UI Alerts tab.
Some example alerting rules are available in the [/examples](/examples) folder.

## Exporting a dashboard for use with Grafana Community Platform or other Grafana Instances

Following the steps in [Editing dashboards](#editing-dashboards), we need to make two exports - one where the toggle "Export for sharing manually" is toggled, and one where it isn't.

- In order for Grafana Community Platform to accept the dashboard upon upload, it needs to know what is required (i.e. Grafana version, panels, Prometheus version) for the dashboard to function correctly. Without this information, an error is thrown saying the format of the dashboard JSON is too old.

- However, for the Grafana instance to accept the dashboard upon import, the option for selecting the data source is required, as the generated data source for sharing externally may not be what the data source is for a user's Grafana instance. If the generated data source was used, the user may not have that data source configured, and Grafana will throw an error to that effect.

Therefore, we will be making a "hybrid" dashboard that utilizes specifying what is required (i.e. Grafana version, panels, Prometheus version) but also giving the choice back to the user to decide which data source they would like to use. This results in a dashboard that is compatible with both Grafana instance dashboard imports, and is also compatible with a Grafana Community Platform dashboard upload.

Once both of these JSON files are exported and saved correctly, ensuring their names are differentiable, we can now combine both JSONs to form our "universal" dashboard.

1. Open both JSONs side to side for ease of editing.
ehearneRedHat marked this conversation as resolved.
Show resolved Hide resolved
2. In the "Export for sharing manually" JSON, copy the "__requires" field and paste it in an outermost fashion into the default export JSON near the top. It should look like:

```json
{
"__requires": [
{
"type": "panel",
"id": "dashlist",
"name": "Dashboard list",
"version": ""
},
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "8.5.5"
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "1.0.0"
},
{
"type": "panel",
"id": "stat",
"name": "Stat",
"version": ""
},
{
"type": "panel",
"id": "table",
"name": "Table",
"version": ""
},
{
"type": "panel",
"id": "text",
"name": "Text",
"version": ""
},
{
"type": "panel",
"id": "timeseries",
"name": "Time series",
"version": ""
}
],
"annotations": {
.
.
.
},
.
.
.
"weekStart": ""
}
```
3. Save this file and use as needed.

Note that we have retained the default data source rather than having an abstract one, allowing the user to make the choice of which data source they wish to use. We have also allowed for the requirements to be specified for uploading the dashboard to the Grafana Community Platform.
40 changes: 40 additions & 0 deletions config/observability/universal-dashboard.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Check if two arguments are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <file1.json> <file2.json>"
exit 1
fi

# Assign provided arguments to variables
public_file="$1"
original_file="$2"

# Check if provided files exist
if [ ! -f "$public_file" ]; then
echo "$public_file does not exist."
exit 1
fi

if [ ! -f "$original_file" ]; then
echo "$original_file does not exist."
exit 1
fi

# Load data from a-public.json
public_data=$(<"$public_file")

# Load data from a.json
original_data=$(<"$original_file")

# Extract __requires field from a-public.json
requires_field=$(echo "$public_data" | jq '.__requires')

# Add __requires field to the outermost bracket of a.json
updated_data=$(echo "$original_data" | jq --argjson requires "$requires_field" '. + { "__requires": $requires }')

# Write the updated data back to a.json
echo "$updated_data" > "$original_file"

# Remove the public file
rm $public_file
63 changes: 50 additions & 13 deletions examples/dashboards/app_developer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
{
"__elements": [],
"__requires": [
{
"type": "panel",
"id": "dashlist",
"name": "Dashboard list",
"version": ""
},
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "8.5.5"
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "1.0.0"
},
{
"type": "panel",
"id": "stat",
"name": "Stat",
"version": ""
},
{
"type": "panel",
"id": "table",
"name": "Table",
"version": ""
},
{
"type": "panel",
"id": "text",
"name": "Text",
"version": ""
},
{
"type": "panel",
"id": "timeseries",
"name": "Time series",
"version": ""
}
],
"annotations": {
"list": [
{
Expand Down Expand Up @@ -26,8 +71,8 @@
"fiscalYearStartMonth": 0,
"gnetId": 7630,
"graphTooltip": 1,
"id": 2,
"iteration": 1713209903588,
"id": null,
"iteration": 1715589343999,
"links": [],
"liveNow": false,
"panels": [
Expand Down Expand Up @@ -1229,8 +1274,8 @@
{
"current": {
"selected": false,
"text": "prometheus",
"value": "prometheus"
"text": "Kuadrant-Thanos-Hub",
"value": "Kuadrant-Thanos-Hub"
},
"hide": 0,
"includeAll": false,
Expand All @@ -1246,15 +1291,7 @@
"type": "datasource"
},
{
"current": {
"selected": true,
"text": [
"All"
],
"value": [
"$__all"
]
},
"current": {},
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
Expand Down
73 changes: 51 additions & 22 deletions examples/dashboards/business_user.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
{
"__elements": [],
"__requires": [
{
"type": "panel",
"id": "dashlist",
"name": "Dashboard list",
"version": ""
},
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "8.5.5"
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "1.0.0"
},
{
"type": "panel",
"id": "state-timeline",
"name": "State timeline",
"version": ""
},
{
"type": "panel",
"id": "table",
"name": "Table",
"version": ""
},
{
"type": "panel",
"id": "text",
"name": "Text",
"version": ""
},
{
"type": "panel",
"id": "timeseries",
"name": "Time series",
"version": ""
}
],
"annotations": {
"list": [
{
Expand All @@ -24,8 +69,8 @@
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 1,
"id": 3,
"iteration": 1713210122715,
"id": null,
"iteration": 1715594450345,
"links": [],
"liveNow": false,
"panels": [
Expand Down Expand Up @@ -610,8 +655,8 @@
{
"current": {
"selected": false,
"text": "prometheus",
"value": "prometheus"
"text": "Kuadrant-Thanos-Hub",
"value": "Kuadrant-Thanos-Hub"
},
"hide": 0,
"includeAll": false,
Expand All @@ -626,15 +671,7 @@
"type": "datasource"
},
{
"current": {
"selected": true,
"text": [
"All"
],
"value": [
"$__all"
]
},
"current": {},
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
Expand All @@ -658,15 +695,7 @@
"type": "query"
},
{
"current": {
"selected": true,
"text": [
"All"
],
"value": [
"$__all"
]
},
"current": {},
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
Expand Down
Loading
Loading