This repository has been archived by the owner on Apr 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/support variables in queries (#2)
feat: support queries with variables
- Loading branch information
Showing
12 changed files
with
1,426 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
version: '3.9' | ||
services: | ||
grafana: | ||
image: grafana/grafana:8.1.1 | ||
volumes: | ||
- ./dist:/var/lib/grafana/plugins/pyroscope-datasource | ||
- ./grafana.ini:/etc/grafana/grafana.ini | ||
- ./grafana-provisioning:/etc/grafana/provisioning | ||
environment: | ||
- GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=pyroscope-datasource,pyroscope-panel | ||
- GF_INSTALL_PLUGINS=https://github.com/pyroscope-io/grafana-panel-plugin/releases/download/v1.1.0/pyroscope-panel-1.1.0.zip;pyroscope-panel | ||
ports: | ||
- 3000:3000 | ||
|
||
pyroscope: | ||
image: | ||
'pyroscope/pyroscope:latest' | ||
ports: | ||
- 4040:4040 | ||
command: | ||
- server | ||
environment: | ||
- PYROSCOPE_LOG_LEVEL=info | ||
|
||
# an app with tags | ||
app: | ||
build: golang-example | ||
environment: | ||
- PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM golang:1.15.6 | ||
|
||
WORKDIR /go/src/app | ||
|
||
COPY main.go ./main.go | ||
|
||
RUN go get -d ./ | ||
RUN go build -o main . | ||
|
||
RUN adduser --disabled-password --gecos --quiet pyroscope | ||
USER pyroscope | ||
|
||
CMD ["./main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"runtime/pprof" | ||
|
||
"github.com/pyroscope-io/client/pyroscope" | ||
) | ||
|
||
//go:noinline | ||
func work(n int) { | ||
// revive:disable:empty-block this is fine because this is a example app, not real production code | ||
for i := 0; i < n; i++ { | ||
} | ||
// revive:enable:empty-block | ||
} | ||
|
||
func fastFunction(c context.Context) { | ||
pyroscope.TagWrapper(c, pyroscope.Labels("function", "fast"), func(c context.Context) { | ||
work(20000000) | ||
}) | ||
} | ||
|
||
func slowFunction(c context.Context) { | ||
// standard pprof.Do wrappers work as well | ||
pprof.Do(c, pprof.Labels("function", "slow"), func(c context.Context) { | ||
work(80000000) | ||
}) | ||
} | ||
|
||
func main() { | ||
serverAddress := os.Getenv("PYROSCOPE_SERVER_ADDRESS") | ||
if serverAddress == "" { | ||
serverAddress = "http://localhost:4040" | ||
} | ||
pyroscope.Start(pyroscope.Config{ | ||
ApplicationName: "simple.golang.app", | ||
ServerAddress: serverAddress, | ||
Logger: pyroscope.StandardLogger, | ||
}) | ||
pyroscope.TagWrapper(context.Background(), pyroscope.Labels("foo", "bar"), func(c context.Context) { | ||
for { | ||
fastFunction(c) | ||
slowFunction(c) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: 1 | ||
|
||
providers: | ||
- name: dashboards | ||
type: file | ||
updateIntervalSeconds: 5 | ||
options: | ||
path: /etc/grafana/provisioning/dashboards |
100 changes: 100 additions & 0 deletions
100
grafana-provisioning/dashboards/panel-with-tag-variables.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"annotations": { | ||
"list": [ | ||
{ | ||
"builtIn": 1, | ||
"datasource": "-- Grafana --", | ||
"enable": true, | ||
"hide": true, | ||
"iconColor": "rgba(0, 211, 255, 1)", | ||
"name": "Annotations & Alerts", | ||
"target": { | ||
"limit": 100, | ||
"matchAny": false, | ||
"tags": [], | ||
"type": "dashboard" | ||
}, | ||
"type": "dashboard" | ||
} | ||
] | ||
}, | ||
"editable": true, | ||
"gnetId": null, | ||
"graphTooltip": 0, | ||
"iteration": 1641309987641, | ||
"links": [], | ||
"panels": [ | ||
{ | ||
"datasource": "Pyroscope", | ||
"gridPos": { | ||
"h": 17, | ||
"w": 24, | ||
"x": 0, | ||
"y": 0 | ||
}, | ||
"id": 2, | ||
"options": { | ||
"showToolbar": false | ||
}, | ||
"targets": [ | ||
{ | ||
"format": "json", | ||
"from": "now-1h", | ||
"name": "simple.golang.app.cpu{function=\"$function\"}", | ||
"queryType": "randomWalk", | ||
"refId": "A", | ||
"until": "now" | ||
} | ||
], | ||
"title": "simple.golang.app.cpu", | ||
"type": "pyroscope-panel" | ||
} | ||
], | ||
"schemaVersion": 30, | ||
"style": "dark", | ||
"tags": [], | ||
"templating": { | ||
"list": [ | ||
{ | ||
"allValue": null, | ||
"current": { | ||
"selected": true, | ||
"text": "fast", | ||
"value": "fast" | ||
}, | ||
"description": null, | ||
"error": null, | ||
"hide": 0, | ||
"includeAll": false, | ||
"label": null, | ||
"multi": false, | ||
"name": "function", | ||
"options": [ | ||
{ | ||
"selected": false, | ||
"text": "slow", | ||
"value": "slow" | ||
}, | ||
{ | ||
"selected": true, | ||
"text": "fast", | ||
"value": "fast" | ||
} | ||
], | ||
"query": "slow,fast", | ||
"queryValue": "", | ||
"skipUrlSync": false, | ||
"type": "custom" | ||
} | ||
] | ||
}, | ||
"time": { | ||
"from": "now-30m", | ||
"to": "now" | ||
}, | ||
"timepicker": {}, | ||
"timezone": "", | ||
"title": "Panel with variable for tags", | ||
"uid": "panel-with-tag-variable", | ||
"version": 2 | ||
} |
110 changes: 110 additions & 0 deletions
110
grafana-provisioning/dashboards/panel-with-variable.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
{ | ||
"annotations": { | ||
"list": [ | ||
{ | ||
"builtIn": 1, | ||
"datasource": "-- Grafana --", | ||
"enable": true, | ||
"hide": true, | ||
"iconColor": "rgba(0, 211, 255, 1)", | ||
"name": "Annotations & Alerts", | ||
"target": { | ||
"limit": 100, | ||
"matchAny": false, | ||
"tags": [], | ||
"type": "dashboard" | ||
}, | ||
"type": "dashboard" | ||
} | ||
] | ||
}, | ||
"editable": true, | ||
"gnetId": null, | ||
"graphTooltip": 0, | ||
"iteration": 1641304888885, | ||
"links": [], | ||
"panels": [ | ||
{ | ||
"datasource": "Pyroscope", | ||
"gridPos": { | ||
"h": 9, | ||
"w": 12, | ||
"x": 0, | ||
"y": 0 | ||
}, | ||
"id": 2, | ||
"options": { | ||
"showToolbar": false | ||
}, | ||
"targets": [ | ||
{ | ||
"format": "json", | ||
"from": "now-1h", | ||
"name": "$query", | ||
"queryType": "randomWalk", | ||
"refId": "A", | ||
"until": "now" | ||
} | ||
], | ||
"title": "$query", | ||
"type": "pyroscope-panel" | ||
} | ||
], | ||
"schemaVersion": 30, | ||
"style": "dark", | ||
"tags": [], | ||
"templating": { | ||
"list": [ | ||
{ | ||
"allValue": null, | ||
"current": { | ||
"selected": true, | ||
"text": "pyroscope.server.inuse_objects", | ||
"value": "pyroscope.server.inuse_objects" | ||
}, | ||
"description": null, | ||
"error": null, | ||
"hide": 0, | ||
"includeAll": false, | ||
"label": null, | ||
"multi": false, | ||
"name": "query", | ||
"options": [ | ||
{ | ||
"selected": false, | ||
"text": "pyroscope.server.cpu", | ||
"value": "pyroscope.server.cpu" | ||
}, | ||
{ | ||
"selected": false, | ||
"text": "pyroscope.server.alloc_objects", | ||
"value": "pyroscope.server.alloc_objects" | ||
}, | ||
{ | ||
"selected": false, | ||
"text": "pyroscope.server.alloc_space", | ||
"value": "pyroscope.server.alloc_space" | ||
}, | ||
{ | ||
"selected": true, | ||
"text": "pyroscope.server.inuse_objects", | ||
"value": "pyroscope.server.inuse_objects" | ||
} | ||
], | ||
"query": "pyroscope.server.cpu,pyroscope.server.alloc_objects,pyroscope.server.alloc_space,pyroscope.server.inuse_objects", | ||
"queryValue": "", | ||
"skipUrlSync": false, | ||
"type": "custom" | ||
} | ||
] | ||
}, | ||
"time": { | ||
"from": "now-5m", | ||
"to": "now" | ||
}, | ||
"timepicker": {}, | ||
"timezone": "", | ||
"title": "Panel with variable", | ||
"uid": "panel-with-variable", | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"annotations": { | ||
"list": [ | ||
{ | ||
"builtIn": 1, | ||
"datasource": "-- Grafana --", | ||
"enable": true, | ||
"hide": true, | ||
"iconColor": "rgba(0, 211, 255, 1)", | ||
"name": "Annotations & Alerts", | ||
"target": { | ||
"limit": 100, | ||
"matchAny": false, | ||
"tags": [], | ||
"type": "dashboard" | ||
}, | ||
"type": "dashboard" | ||
} | ||
] | ||
}, | ||
"editable": true, | ||
"gnetId": null, | ||
"graphTooltip": 0, | ||
"links": [], | ||
"panels": [ | ||
{ | ||
"datasource": "Pyroscope", | ||
"gridPos": { | ||
"h": 17, | ||
"w": 24, | ||
"x": 0, | ||
"y": 0 | ||
}, | ||
"id": 2, | ||
"options": { | ||
"showToolbar": false | ||
}, | ||
"pluginVersion": "7.3.6", | ||
"targets": [ | ||
{ | ||
"format": "json", | ||
"from": "now-1h", | ||
"name": "pyroscope.server.cpu", | ||
"queryType": "randomWalk", | ||
"refId": "A", | ||
"until": "now" | ||
} | ||
], | ||
"timeFrom": null, | ||
"timeShift": null, | ||
"title": "Pyroscope Server CPU", | ||
"type": "pyroscope-panel" | ||
} | ||
], | ||
"refresh": "", | ||
"schemaVersion": 30, | ||
"style": "dark", | ||
"tags": [], | ||
"templating": { | ||
"list": [] | ||
}, | ||
"time": { | ||
"from": "now-5m", | ||
"to": "now" | ||
}, | ||
"timepicker": {}, | ||
"timezone": "", | ||
"title": "Single Panel Dashboard", | ||
"uid": "single-panel", | ||
"version": 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
apiVersion: 1 | ||
|
||
datasources: | ||
- name: Pyroscope | ||
type: pyroscope-datasource | ||
access: proxy | ||
orgId: 1 | ||
uid: pyroscope | ||
jsonData: | ||
path: http://pyroscope:4040 |
Oops, something went wrong.