Skip to content

Commit

Permalink
metrics/grafana: use jsonnet to generate tidb-summary Grafana json fi…
Browse files Browse the repository at this point in the history
…les (#32333)

ref #32194
  • Loading branch information
jackysp authored Feb 20, 2022
1 parent 36a1f84 commit 171a354
Show file tree
Hide file tree
Showing 5 changed files with 2,237 additions and 3,071 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,6 @@ dumpling_bins:

tools/bin/gotestsum: tools/check/go.mod
cd tools/check && $(GO) build -o ../bin/gotestsum gotest.tools/gotestsum

generate_grafana_scripts:
@cd metrics/grafana && mv tidb_summary.json tidb_summary.json.committed && ./generate_json.sh && diff -u tidb_summary.json.committed tidb_summary.json && rm tidb_summary.json.committed
14 changes: 14 additions & 0 deletions metrics/grafana/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## About

Use [jsonnet](https://github.com/google/go-jsonnet) to generate Grafana-compliant json scripts for use with TiDB.

Why jsonnet?

1. jsonnet is a DSL created by Google for json, which is good for advanced json editing work.
2. Grafana provides the [jsonnet library](https://grafana.github.io/grafonnet-lib/) specifically for generating Grafana json, which makes maintaining TiDB's json scripts much easier.

## Usage

1. Modify the jsonnet files (e.g. tidb_summary.jsonnet).
2. Run `generate_json.sh` to generate the json files by the jsonnet files.
3. Commit the modifications.
22 changes: 22 additions & 0 deletions metrics/grafana/generate_json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Copyright 2022 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

go install github.com/google/go-jsonnet/cmd/jsonnet@latest
git clone https://github.com/grafana/grafonnet-lib.git

export JSONNET_PATH=grafonnet-lib
jsonnet tidb_summary.jsonnet > tidb_summary.json
rm -rf $JSONNET_PATH

Loading

0 comments on commit 171a354

Please sign in to comment.