Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.

Commit ebdd328

Browse files
authored
Feat/support variables in queries (#2)
feat: support queries with variables
1 parent 2f40056 commit ebdd328

File tree

12 files changed

+1426
-50
lines changed

12 files changed

+1426
-50
lines changed

docker-compose.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
version: '3.9'
3+
services:
4+
grafana:
5+
image: grafana/grafana:8.1.1
6+
volumes:
7+
- ./dist:/var/lib/grafana/plugins/pyroscope-datasource
8+
- ./grafana.ini:/etc/grafana/grafana.ini
9+
- ./grafana-provisioning:/etc/grafana/provisioning
10+
environment:
11+
- GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=pyroscope-datasource,pyroscope-panel
12+
- GF_INSTALL_PLUGINS=https://github.com/pyroscope-io/grafana-panel-plugin/releases/download/v1.1.0/pyroscope-panel-1.1.0.zip;pyroscope-panel
13+
ports:
14+
- 3000:3000
15+
16+
pyroscope:
17+
image:
18+
'pyroscope/pyroscope:latest'
19+
ports:
20+
- 4040:4040
21+
command:
22+
- server
23+
environment:
24+
- PYROSCOPE_LOG_LEVEL=info
25+
26+
# an app with tags
27+
app:
28+
build: golang-example
29+
environment:
30+
- PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040

golang-example/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM golang:1.15.6
2+
3+
WORKDIR /go/src/app
4+
5+
COPY main.go ./main.go
6+
7+
RUN go get -d ./
8+
RUN go build -o main .
9+
10+
RUN adduser --disabled-password --gecos --quiet pyroscope
11+
USER pyroscope
12+
13+
CMD ["./main"]

golang-example/main.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"os"
6+
"runtime/pprof"
7+
8+
"github.com/pyroscope-io/client/pyroscope"
9+
)
10+
11+
//go:noinline
12+
func work(n int) {
13+
// revive:disable:empty-block this is fine because this is a example app, not real production code
14+
for i := 0; i < n; i++ {
15+
}
16+
// revive:enable:empty-block
17+
}
18+
19+
func fastFunction(c context.Context) {
20+
pyroscope.TagWrapper(c, pyroscope.Labels("function", "fast"), func(c context.Context) {
21+
work(20000000)
22+
})
23+
}
24+
25+
func slowFunction(c context.Context) {
26+
// standard pprof.Do wrappers work as well
27+
pprof.Do(c, pprof.Labels("function", "slow"), func(c context.Context) {
28+
work(80000000)
29+
})
30+
}
31+
32+
func main() {
33+
serverAddress := os.Getenv("PYROSCOPE_SERVER_ADDRESS")
34+
if serverAddress == "" {
35+
serverAddress = "http://localhost:4040"
36+
}
37+
pyroscope.Start(pyroscope.Config{
38+
ApplicationName: "simple.golang.app",
39+
ServerAddress: serverAddress,
40+
Logger: pyroscope.StandardLogger,
41+
})
42+
pyroscope.TagWrapper(context.Background(), pyroscope.Labels("foo", "bar"), func(c context.Context) {
43+
for {
44+
fastFunction(c)
45+
slowFunction(c)
46+
}
47+
})
48+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: 1
2+
3+
providers:
4+
- name: dashboards
5+
type: file
6+
updateIntervalSeconds: 5
7+
options:
8+
path: /etc/grafana/provisioning/dashboards
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"annotations": {
3+
"list": [
4+
{
5+
"builtIn": 1,
6+
"datasource": "-- Grafana --",
7+
"enable": true,
8+
"hide": true,
9+
"iconColor": "rgba(0, 211, 255, 1)",
10+
"name": "Annotations & Alerts",
11+
"target": {
12+
"limit": 100,
13+
"matchAny": false,
14+
"tags": [],
15+
"type": "dashboard"
16+
},
17+
"type": "dashboard"
18+
}
19+
]
20+
},
21+
"editable": true,
22+
"gnetId": null,
23+
"graphTooltip": 0,
24+
"iteration": 1641309987641,
25+
"links": [],
26+
"panels": [
27+
{
28+
"datasource": "Pyroscope",
29+
"gridPos": {
30+
"h": 17,
31+
"w": 24,
32+
"x": 0,
33+
"y": 0
34+
},
35+
"id": 2,
36+
"options": {
37+
"showToolbar": false
38+
},
39+
"targets": [
40+
{
41+
"format": "json",
42+
"from": "now-1h",
43+
"name": "simple.golang.app.cpu{function=\"$function\"}",
44+
"queryType": "randomWalk",
45+
"refId": "A",
46+
"until": "now"
47+
}
48+
],
49+
"title": "simple.golang.app.cpu",
50+
"type": "pyroscope-panel"
51+
}
52+
],
53+
"schemaVersion": 30,
54+
"style": "dark",
55+
"tags": [],
56+
"templating": {
57+
"list": [
58+
{
59+
"allValue": null,
60+
"current": {
61+
"selected": true,
62+
"text": "fast",
63+
"value": "fast"
64+
},
65+
"description": null,
66+
"error": null,
67+
"hide": 0,
68+
"includeAll": false,
69+
"label": null,
70+
"multi": false,
71+
"name": "function",
72+
"options": [
73+
{
74+
"selected": false,
75+
"text": "slow",
76+
"value": "slow"
77+
},
78+
{
79+
"selected": true,
80+
"text": "fast",
81+
"value": "fast"
82+
}
83+
],
84+
"query": "slow,fast",
85+
"queryValue": "",
86+
"skipUrlSync": false,
87+
"type": "custom"
88+
}
89+
]
90+
},
91+
"time": {
92+
"from": "now-30m",
93+
"to": "now"
94+
},
95+
"timepicker": {},
96+
"timezone": "",
97+
"title": "Panel with variable for tags",
98+
"uid": "panel-with-tag-variable",
99+
"version": 2
100+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"annotations": {
3+
"list": [
4+
{
5+
"builtIn": 1,
6+
"datasource": "-- Grafana --",
7+
"enable": true,
8+
"hide": true,
9+
"iconColor": "rgba(0, 211, 255, 1)",
10+
"name": "Annotations & Alerts",
11+
"target": {
12+
"limit": 100,
13+
"matchAny": false,
14+
"tags": [],
15+
"type": "dashboard"
16+
},
17+
"type": "dashboard"
18+
}
19+
]
20+
},
21+
"editable": true,
22+
"gnetId": null,
23+
"graphTooltip": 0,
24+
"iteration": 1641304888885,
25+
"links": [],
26+
"panels": [
27+
{
28+
"datasource": "Pyroscope",
29+
"gridPos": {
30+
"h": 9,
31+
"w": 12,
32+
"x": 0,
33+
"y": 0
34+
},
35+
"id": 2,
36+
"options": {
37+
"showToolbar": false
38+
},
39+
"targets": [
40+
{
41+
"format": "json",
42+
"from": "now-1h",
43+
"name": "$query",
44+
"queryType": "randomWalk",
45+
"refId": "A",
46+
"until": "now"
47+
}
48+
],
49+
"title": "$query",
50+
"type": "pyroscope-panel"
51+
}
52+
],
53+
"schemaVersion": 30,
54+
"style": "dark",
55+
"tags": [],
56+
"templating": {
57+
"list": [
58+
{
59+
"allValue": null,
60+
"current": {
61+
"selected": true,
62+
"text": "pyroscope.server.inuse_objects",
63+
"value": "pyroscope.server.inuse_objects"
64+
},
65+
"description": null,
66+
"error": null,
67+
"hide": 0,
68+
"includeAll": false,
69+
"label": null,
70+
"multi": false,
71+
"name": "query",
72+
"options": [
73+
{
74+
"selected": false,
75+
"text": "pyroscope.server.cpu",
76+
"value": "pyroscope.server.cpu"
77+
},
78+
{
79+
"selected": false,
80+
"text": "pyroscope.server.alloc_objects",
81+
"value": "pyroscope.server.alloc_objects"
82+
},
83+
{
84+
"selected": false,
85+
"text": "pyroscope.server.alloc_space",
86+
"value": "pyroscope.server.alloc_space"
87+
},
88+
{
89+
"selected": true,
90+
"text": "pyroscope.server.inuse_objects",
91+
"value": "pyroscope.server.inuse_objects"
92+
}
93+
],
94+
"query": "pyroscope.server.cpu,pyroscope.server.alloc_objects,pyroscope.server.alloc_space,pyroscope.server.inuse_objects",
95+
"queryValue": "",
96+
"skipUrlSync": false,
97+
"type": "custom"
98+
}
99+
]
100+
},
101+
"time": {
102+
"from": "now-5m",
103+
"to": "now"
104+
},
105+
"timepicker": {},
106+
"timezone": "",
107+
"title": "Panel with variable",
108+
"uid": "panel-with-variable",
109+
"version": 1
110+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"annotations": {
3+
"list": [
4+
{
5+
"builtIn": 1,
6+
"datasource": "-- Grafana --",
7+
"enable": true,
8+
"hide": true,
9+
"iconColor": "rgba(0, 211, 255, 1)",
10+
"name": "Annotations & Alerts",
11+
"target": {
12+
"limit": 100,
13+
"matchAny": false,
14+
"tags": [],
15+
"type": "dashboard"
16+
},
17+
"type": "dashboard"
18+
}
19+
]
20+
},
21+
"editable": true,
22+
"gnetId": null,
23+
"graphTooltip": 0,
24+
"links": [],
25+
"panels": [
26+
{
27+
"datasource": "Pyroscope",
28+
"gridPos": {
29+
"h": 17,
30+
"w": 24,
31+
"x": 0,
32+
"y": 0
33+
},
34+
"id": 2,
35+
"options": {
36+
"showToolbar": false
37+
},
38+
"pluginVersion": "7.3.6",
39+
"targets": [
40+
{
41+
"format": "json",
42+
"from": "now-1h",
43+
"name": "pyroscope.server.cpu",
44+
"queryType": "randomWalk",
45+
"refId": "A",
46+
"until": "now"
47+
}
48+
],
49+
"timeFrom": null,
50+
"timeShift": null,
51+
"title": "Pyroscope Server CPU",
52+
"type": "pyroscope-panel"
53+
}
54+
],
55+
"refresh": "",
56+
"schemaVersion": 30,
57+
"style": "dark",
58+
"tags": [],
59+
"templating": {
60+
"list": []
61+
},
62+
"time": {
63+
"from": "now-5m",
64+
"to": "now"
65+
},
66+
"timepicker": {},
67+
"timezone": "",
68+
"title": "Single Panel Dashboard",
69+
"uid": "single-panel",
70+
"version": 3
71+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
apiVersion: 1
3+
4+
datasources:
5+
- name: Pyroscope
6+
type: pyroscope-datasource
7+
access: proxy
8+
orgId: 1
9+
uid: pyroscope
10+
jsonData:
11+
path: http://pyroscope:4040

0 commit comments

Comments
 (0)