Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 6e00c67

Browse files
committed
Move testnet metrics dashboard management out of the Grafana UI
1 parent f366043 commit 6e00c67

File tree

6 files changed

+5843
-0
lines changed

6 files changed

+5843
-0
lines changed

ci/publish-metrics-dashboard.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
cd "$(dirname "$0")/.."
5+
6+
if [[ -z $BUILDKITE ]]; then
7+
echo BUILDKITE not defined
8+
exit 1
9+
fi
10+
11+
if [[ -z $CHANNEL ]]; then
12+
CHANNEL=$(buildkite-agent meta-data get "channel" --default "")
13+
fi
14+
15+
if [[ -z $CHANNEL ]]; then
16+
(
17+
cat <<EOF
18+
steps:
19+
- block: "Select Dashboard"
20+
fields:
21+
- select: "Channel"
22+
key: "channel"
23+
options:
24+
- label: "stable"
25+
value: "stable"
26+
- label: "edge"
27+
value: "edge"
28+
- label: "beta"
29+
value: "beta"
30+
- command: "ci/$(basename "$0")"
31+
EOF
32+
) | buildkite-agent pipeline upload
33+
exit 0
34+
fi
35+
36+
37+
ci/channel-info.sh
38+
eval "$(ci/channel-info.sh)"
39+
40+
case $CHANNEL in
41+
edge)
42+
CHANNEL_BRANCH=$EDGE_CHANNEL
43+
;;
44+
beta)
45+
CHANNEL_BRANCH=$BETA_CHANNEL
46+
;;
47+
stable)
48+
CHANNEL_BRANCH=$BETA_CHANNEL
49+
;;
50+
*)
51+
echo "Error: Invalid CHANNEL=$CHANNEL"
52+
exit 1
53+
;;
54+
esac
55+
56+
if [[ $BUILDKITE_BRANCH != "$CHANNEL_BRANCH" ]]; then
57+
(
58+
cat <<EOF
59+
steps:
60+
- trigger: "$BUILDKITE_PIPELINE_SLUG"
61+
async: true
62+
build:
63+
message: "$BUILDKITE_MESSAGE"
64+
branch: "$CHANNEL_BRANCH"
65+
env:
66+
CHANNEL: "$CHANNEL"
67+
EOF
68+
) | buildkite-agent pipeline upload
69+
exit 0
70+
fi
71+
72+
set -x
73+
exec metrics/publish-metrics-dashboard.sh "$CHANNEL"

metrics/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Metrics
2+
3+
## Testnet Grafana Dashboard
4+
5+
There are three versions of the testnet dashboard, corresponding to the three
6+
release channels:
7+
* https://metrics.solana.com:3000/d/testnet-edge/testnet-monitor-edge
8+
* https://metrics.solana.com:3000/d/testnet-beta/testnet-monitor-beta
9+
* https://metrics.solana.com:3000/d/testnet/testnet-monitor
10+
11+
The dashboard for each channel is defined from the
12+
`metrics/testnet-monitor.json` source file in the git branch associated with
13+
that channel, and deployed by automation running `ci/publish-metrics-dashboard.sh`.
14+
15+
A deploy can be triggered at any time via the `New Build` button of
16+
https://buildkite.com/solana-labs/publish-metrics-dashboard.
17+
18+
### Modifying a Dashboard
19+
20+
Dashboard updates are accomplished by modifying `metrics/testnet-monitor.json`,
21+
**manual edits made directly in Grafana will be overwritten**.
22+
23+
1. Open the desired dashboard in Grafana
24+
2. Create a development copy of the dashboard by selecting `Save As..` in the
25+
`Settings` menu for the dashboard
26+
3. Edit dashboard as desired
27+
4. Extract the JSON Model by selecting `JSON Model` in the `Settings` menu. Copy the JSON to the clipboard
28+
and paste into `metrics/testnet-monitor.json`
29+
5. Delete your development dashboard: `Settings` => `Delete`
30+
31+
### Deploying a Dashboard Manually
32+
33+
If you need to immediately deploy a dashboard using the contents of
34+
`metrics/testnet-monitor.json` in your local workspace,
35+
```
36+
$ export GRAFANA_API_TOKEN="an API key from https://metrics.solana.com:3000/org/apikeys"
37+
$ metrics/publish-metrics-dashboard.sh (edge|beta|stable)
38+
```
39+
Note that automation will eventually overwrite your manual deploy.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Adjusts the testnet monitor dashboard for the specified release channel
4+
#
5+
6+
import sys
7+
import json
8+
9+
if len(sys.argv) != 3:
10+
print('Error: Dashboard or Channel not specified')
11+
sys.exit(1)
12+
13+
dashboard_json = sys.argv[1]
14+
channel = sys.argv[2]
15+
if channel not in ['edge', 'beta', 'stable']:
16+
print('Error: Unknown channel:', channel)
17+
sys.exit(2)
18+
19+
with open(dashboard_json, 'r') as read_file:
20+
data = json.load(read_file)
21+
22+
if channel == 'stable':
23+
# Stable dashboard only allows the user to select between the stable
24+
# testnet databases
25+
data['title'] = 'Testnet Monitor'
26+
data['uid'] = 'testnet'
27+
data['templating']['list'] = [{'allValue': None,
28+
'current': {'text': 'testnet',
29+
'value': 'testnet'},
30+
'hide': 1,
31+
'includeAll': False,
32+
'label': 'Testnet',
33+
'multi': False,
34+
'name': 'testnet',
35+
'options': [{'selected': False,
36+
'text': 'testnet',
37+
'value': 'testnet'},
38+
{'selected': True,
39+
'text': 'testnet-perf',
40+
'value': 'testnet-perf'}],
41+
'query': 'testnet,testnet-perf',
42+
'type': 'custom'}]
43+
else:
44+
# Non-stable dashboard only allows the user to select between all testnet
45+
# databases
46+
data['title'] = 'Testnet Monitor ({})'.format(channel)
47+
data['uid'] = 'testnet-' + channel
48+
data['templating']['list'] = [{'allValue': None,
49+
'current': {'text': 'testnet',
50+
'value': 'testnet'},
51+
'datasource': 'Solana Metrics (read-only)',
52+
'hide': 1,
53+
'includeAll': False,
54+
'label': 'Testnet',
55+
'multi': False,
56+
'name': 'testnet',
57+
'options': [],
58+
'query': 'show databases',
59+
'refresh': 1,
60+
'regex': 'testnet.*',
61+
'sort': 1,
62+
'tagValuesQuery': '',
63+
'tags': [],
64+
'tagsQuery': '',
65+
'type': 'query',
66+
'useTags': False}]
67+
68+
with open(dashboard_json, 'w') as write_file:
69+
json.dump(data, write_file, indent=2)

metrics/grafcli.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[grafcli]
2+
editor = vim
3+
mergetool = vimdiff
4+
verbose = on
5+
force = on
6+
7+
[resources]
8+
9+
[hosts]
10+
metrics = on
11+
12+
[metrics]
13+
type = api
14+
url = https://metrics.solana.com:3000/api
15+
ssl = off

metrics/publish-metrics-dashboard.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
cd "$(dirname "$0")"
5+
6+
CHANNEL=$1
7+
if [[ -z $CHANNEL ]]; then
8+
echo "usage: $0 [channel]"
9+
exit 1
10+
fi
11+
12+
case $CHANNEL in
13+
edge)
14+
DASHBOARD=testnet-monitor-edge
15+
;;
16+
beta)
17+
DASHBOARD=testnet-monitor-beta
18+
;;
19+
stable)
20+
DASHBOARD=testnet-monitor
21+
;;
22+
*)
23+
echo "Error: Invalid CHANNEL=$CHANNEL"
24+
exit 1
25+
;;
26+
esac
27+
28+
29+
if [[ -z $GRAFANA_API_TOKEN ]]; then
30+
echo Error: GRAFANA_API_TOKEN not defined
31+
exit 1
32+
fi
33+
34+
DASHBOARD_JSON=./testnet-monitor.json
35+
if [[ ! -r $DASHBOARD_JSON ]]; then
36+
echo Error: $DASHBOARD_JSON not found
37+
fi
38+
39+
(
40+
set -x
41+
./adjust-dashboard-for-channel.py "$DASHBOARD_JSON" "$CHANNEL"
42+
)
43+
44+
rm -rf venv
45+
python3 -m venv venv
46+
# shellcheck source=/dev/null
47+
source venv/bin/activate
48+
49+
echo --- Fetch/build grafcli
50+
(
51+
set -x
52+
git clone git@github.com:mvines/grafcli.git -b experimental-v5 venv/grafcli
53+
cd venv/grafcli
54+
python3 setup.py install
55+
)
56+
57+
echo --- Take a backup of existing dashboard if possible
58+
(
59+
set -x +e
60+
grafcli export remote/metrics/$DASHBOARD $DASHBOARD_JSON.org
61+
grafcli rm remote/metrics/$DASHBOARD
62+
:
63+
)
64+
65+
echo --- Publish $DASHBOARD_JSON to $DASHBOARD
66+
(
67+
set -x
68+
grafcli import $DASHBOARD_JSON remote/metrics
69+
)
70+
71+
exit 0

0 commit comments

Comments
 (0)