Skip to content

Commit 9b90b83

Browse files
committed
Merge remote-tracking branch 'origin/master' into stackdriver-plugin
2 parents d11f67e + fda8a08 commit 9b90b83

File tree

68 files changed

+1966
-189
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1966
-189
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ jobs:
8383
- checkout
8484
- run: 'go get -u github.com/alecthomas/gometalinter'
8585
- run: 'go get -u github.com/tsenart/deadcode'
86+
- run: 'go get -u github.com/jgautheron/goconst/cmd/goconst'
8687
- run: 'go get -u github.com/gordonklaus/ineffassign'
8788
- run: 'go get -u github.com/opennota/check/cmd/structcheck'
8889
- run: 'go get -u github.com/mdempsky/unconvert'
8990
- run: 'go get -u github.com/opennota/check/cmd/varcheck'
9091
- run:
9192
name: run linters
92-
command: 'gometalinter --enable-gc --vendor --deadline 10m --disable-all --enable=deadcode --enable=ineffassign --enable=structcheck --enable=unconvert --enable=varcheck ./...'
93+
command: 'gometalinter --enable-gc --vendor --deadline 10m --disable-all --enable=deadcode --enable=goconst --enable=ineffassign --enable=structcheck --enable=unconvert --enable=varcheck ./...'
9394
- run:
9495
name: run go vet
9596
command: 'go vet ./pkg/...'

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66

77
### Minor
88

9+
* **Provisioning**: Dashboard Provisioning now support symlinks that changes target [#12534](https://github.com/grafana/grafana/issues/12534), thx [@auhlig](https://github.com/auhlig)
910
* **OAuth**: Allow oauth email attribute name to be configurable [#12986](https://github.com/grafana/grafana/issues/12986), thx [@bobmshannon](https://github.com/bobmshannon)
1011
* **Tags**: Default sort order for GetDashboardTags [#11681](https://github.com/grafana/grafana/pull/11681), thx [@Jonnymcc](https://github.com/Jonnymcc)
1112
* **Prometheus**: Label completion queries respect dashboard time range [#12251](https://github.com/grafana/grafana/pull/12251), thx [@mtanda](https://github.com/mtanda)
1213
* **Prometheus**: Allow to display annotations based on Prometheus series value [#10159](https://github.com/grafana/grafana/issues/10159), thx [@mtanda](https://github.com/mtanda)
1314
* **Prometheus**: Adhoc-filtering for Prometheus dashboards [#13212](https://github.com/grafana/grafana/issues/13212)
1415
* **Singlestat**: Fix gauge display accuracy for percents [#13270](https://github.com/grafana/grafana/issues/13270), thx [@tianon](https://github.com/tianon)
16+
* **Dashboard**: Prevent auto refresh from starting when loading dashboard with absolute time range [#12030](https://github.com/grafana/grafana/issues/12030)
17+
* **Templating**: New templating variable type `Text box` that allows free text input [#3173](https://github.com/grafana/grafana/issues/3173)
1518

1619
# 5.3.0 (unreleased)
1720

build.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ import (
2222
"time"
2323
)
2424

25+
const (
26+
windows = "windows"
27+
linux = "linux"
28+
)
29+
2530
var (
2631
//versionRe = regexp.MustCompile(`-[0-9]{1,3}-g[0-9a-f]{5,10}`)
2732
goarch string
@@ -110,13 +115,13 @@ func main() {
110115
case "package":
111116
grunt(gruntBuildArg("build")...)
112117
grunt(gruntBuildArg("package")...)
113-
if goos == "linux" {
118+
if goos == linux {
114119
createLinuxPackages()
115120
}
116121

117122
case "package-only":
118123
grunt(gruntBuildArg("package")...)
119-
if goos == "linux" {
124+
if goos == linux {
120125
createLinuxPackages()
121126
}
122127

@@ -378,7 +383,7 @@ func ensureGoPath() {
378383
}
379384

380385
func grunt(params ...string) {
381-
if runtime.GOOS == "windows" {
386+
if runtime.GOOS == windows {
382387
runPrint(`.\node_modules\.bin\grunt`, params...)
383388
} else {
384389
runPrint("./node_modules/.bin/grunt", params...)
@@ -420,7 +425,7 @@ func build(binaryName, pkg string, tags []string) {
420425
binary = fmt.Sprintf("./bin/%s", binaryName)
421426
}
422427

423-
if goos == "windows" {
428+
if goos == windows {
424429
binary += ".exe"
425430
}
426431

@@ -484,11 +489,11 @@ func clean() {
484489

485490
func setBuildEnv() {
486491
os.Setenv("GOOS", goos)
487-
if goos == "windows" {
492+
if goos == windows {
488493
// require windows >=7
489494
os.Setenv("CGO_CFLAGS", "-D_WIN32_WINNT=0x0601")
490495
}
491-
if goarch != "amd64" || goos != "linux" {
496+
if goarch != "amd64" || goos != linux {
492497
// needed for all other archs
493498
cgo = true
494499
}

devenv/docker/ha_test/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
grafana/provisioning/dashboards/alerts/alert-*

devenv/docker/ha_test/README.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Grafana High Availability (HA) test setup
2+
3+
A set of docker compose services which together creates a Grafana HA test setup with capability of easily
4+
scaling up/down number of Grafana instances.
5+
6+
Included services
7+
8+
* Grafana
9+
* Mysql - Grafana configuration database and session storage
10+
* Prometheus - Monitoring of Grafana and used as datasource of provisioned alert rules
11+
* Nginx - Reverse proxy for Grafana and Prometheus. Enables browsing Grafana/Prometheus UI using a hostname
12+
13+
## Prerequisites
14+
15+
### Build grafana docker container
16+
17+
Build a Grafana docker container from current branch and commit and tag it as grafana/grafana:dev.
18+
19+
```bash
20+
$ cd <grafana repo>
21+
$ make build-docker-full
22+
```
23+
24+
### Virtual host names
25+
26+
#### Alternative 1 - Use dnsmasq
27+
28+
```bash
29+
$ sudo apt-get install dnsmasq
30+
$ echo 'address=/loc/127.0.0.1' | sudo tee /etc/dnsmasq.d/dnsmasq-loc.conf > /dev/null
31+
$ sudo /etc/init.d/dnsmasq restart
32+
$ ping whatever.loc
33+
PING whatever.loc (127.0.0.1) 56(84) bytes of data.
34+
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.076 ms
35+
--- whatever.loc ping statistics ---
36+
1 packet transmitted, 1 received, 0% packet loss, time 1998ms
37+
```
38+
39+
#### Alternative 2 - Manually update /etc/hosts
40+
41+
Update your `/etc/hosts` to be able to access Grafana and/or Prometheus UI using a hostname.
42+
43+
```bash
44+
$ cat /etc/hosts
45+
127.0.0.1 grafana.loc
46+
127.0.0.1 prometheus.loc
47+
```
48+
49+
## Start services
50+
51+
```bash
52+
$ docker-compose up -d
53+
```
54+
55+
Browse
56+
* http://grafana.loc/
57+
* http://prometheus.loc/
58+
59+
Check for any errors
60+
61+
```bash
62+
$ docker-compose logs | grep error
63+
```
64+
65+
### Scale Grafana instances up/down
66+
67+
Scale number of Grafana instances to `<instances>`
68+
69+
```bash
70+
$ docker-compose up --scale grafana=<instances> -d
71+
# for example 3 instances
72+
$ docker-compose up --scale grafana=3 -d
73+
```
74+
75+
## Test alerting
76+
77+
### Create notification channels
78+
79+
Creates default notification channels, if not already exists
80+
81+
```bash
82+
$ ./alerts.sh setup
83+
```
84+
85+
### Slack notifications
86+
87+
Disable
88+
89+
```bash
90+
$ ./alerts.sh slack -d
91+
```
92+
93+
Enable and configure url
94+
95+
```bash
96+
$ ./alerts.sh slack -u https://hooks.slack.com/services/...
97+
```
98+
99+
Enable, configure url and enable reminders
100+
101+
```bash
102+
$ ./alerts.sh slack -u https://hooks.slack.com/services/... -r -e 10m
103+
```
104+
105+
### Provision alert dashboards with alert rules
106+
107+
Provision 1 dashboard/alert rule (default)
108+
109+
```bash
110+
$ ./alerts.sh provision
111+
```
112+
113+
Provision 10 dashboards/alert rules
114+
115+
```bash
116+
$ ./alerts.sh provision -a 10
117+
```
118+
119+
Provision 10 dashboards/alert rules and change condition to `gt > 100`
120+
121+
```bash
122+
$ ./alerts.sh provision -a 10 -c 100
123+
```
124+
125+
### Pause/unpause all alert rules
126+
127+
Pause
128+
129+
```bash
130+
$ ./alerts.sh pause
131+
```
132+
133+
Unpause
134+
135+
```bash
136+
$ ./alerts.sh unpause
137+
```

devenv/docker/ha_test/alerts.sh

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/bin/bash
2+
3+
requiresJsonnet() {
4+
if ! type "jsonnet" > /dev/null; then
5+
echo "you need you install jsonnet to run this script"
6+
echo "follow the instructions on https://github.com/google/jsonnet"
7+
exit 1
8+
fi
9+
}
10+
11+
setup() {
12+
STATUS=$(curl -s -o /dev/null -w '%{http_code}' http://admin:[email protected]/api/alert-notifications/1)
13+
if [ $STATUS -eq 200 ]; then
14+
echo "Email already exists, skipping..."
15+
else
16+
curl -H "Content-Type: application/json" \
17+
-d '{
18+
"name": "Email",
19+
"type": "email",
20+
"isDefault": false,
21+
"sendReminder": false,
22+
"uploadImage": true,
23+
"settings": {
24+
"addresses": "[email protected]"
25+
}
26+
}' \
27+
http://admin:[email protected]/api/alert-notifications
28+
fi
29+
30+
STATUS=$(curl -s -o /dev/null -w '%{http_code}' http://admin:[email protected]/api/alert-notifications/2)
31+
if [ $STATUS -eq 200 ]; then
32+
echo "Slack already exists, skipping..."
33+
else
34+
curl -H "Content-Type: application/json" \
35+
-d '{
36+
"name": "Slack",
37+
"type": "slack",
38+
"isDefault": false,
39+
"sendReminder": false,
40+
"uploadImage": true
41+
}' \
42+
http://admin:[email protected]/api/alert-notifications
43+
fi
44+
}
45+
46+
slack() {
47+
enabled=true
48+
url=''
49+
remind=false
50+
remindEvery='10m'
51+
52+
while getopts ":e:u:dr" o; do
53+
case "${o}" in
54+
e)
55+
remindEvery=${OPTARG}
56+
;;
57+
u)
58+
url=${OPTARG}
59+
;;
60+
d)
61+
enabled=false
62+
;;
63+
r)
64+
remind=true
65+
;;
66+
esac
67+
done
68+
shift $((OPTIND-1))
69+
70+
curl -X PUT \
71+
-H "Content-Type: application/json" \
72+
-d '{
73+
"id": 2,
74+
"name": "Slack",
75+
"type": "slack",
76+
"isDefault": '$enabled',
77+
"sendReminder": '$remind',
78+
"frequency": "'$remindEvery'",
79+
"uploadImage": true,
80+
"settings": {
81+
"url": "'$url'"
82+
}
83+
}' \
84+
http://admin:[email protected]/api/alert-notifications/2
85+
}
86+
87+
provision() {
88+
alerts=1
89+
condition=65
90+
while getopts ":a:c:" o; do
91+
case "${o}" in
92+
a)
93+
alerts=${OPTARG}
94+
;;
95+
c)
96+
condition=${OPTARG}
97+
;;
98+
esac
99+
done
100+
shift $((OPTIND-1))
101+
102+
requiresJsonnet
103+
104+
rm -rf grafana/provisioning/dashboards/alerts/alert-*.json
105+
jsonnet -m grafana/provisioning/dashboards/alerts grafana/provisioning/alerts.jsonnet --ext-code alerts=$alerts --ext-code condition=$condition
106+
}
107+
108+
pause() {
109+
curl -H "Content-Type: application/json" \
110+
-d '{"paused":true}' \
111+
http://admin:[email protected]/api/admin/pause-all-alerts
112+
}
113+
114+
unpause() {
115+
curl -H "Content-Type: application/json" \
116+
-d '{"paused":false}' \
117+
http://admin:[email protected]/api/admin/pause-all-alerts
118+
}
119+
120+
usage() {
121+
echo -e "Usage: ./alerts.sh COMMAND [OPTIONS]\n"
122+
echo -e "Commands"
123+
echo -e " setup\t\t creates default alert notification channels"
124+
echo -e " slack\t\t configure slack notification channel"
125+
echo -e " [-d]\t\t\t disable notifier, default enabled"
126+
echo -e " [-u]\t\t\t url"
127+
echo -e " [-r]\t\t\t send reminders"
128+
echo -e " [-e <remind every>]\t\t default 10m\n"
129+
echo -e " provision\t provision alerts"
130+
echo -e " [-a <alert rule count>]\t default 1"
131+
echo -e " [-c <condition value>]\t default 65\n"
132+
echo -e " pause\t\t pause all alerts"
133+
echo -e " unpause\t unpause all alerts"
134+
}
135+
136+
main() {
137+
local cmd=$1
138+
139+
if [[ $cmd == "setup" ]]; then
140+
setup
141+
elif [[ $cmd == "slack" ]]; then
142+
slack "${@:2}"
143+
elif [[ $cmd == "provision" ]]; then
144+
provision "${@:2}"
145+
elif [[ $cmd == "pause" ]]; then
146+
pause
147+
elif [[ $cmd == "unpause" ]]; then
148+
unpause
149+
fi
150+
151+
if [[ -z "$cmd" ]]; then
152+
usage
153+
fi
154+
}
155+
156+
main "$@"

0 commit comments

Comments
 (0)