mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Aggregator: Add README and example query (#93351)
This commit is contained in:
parent
3df62c28bb
commit
80795fcfd5
pkg/aggregator
30
pkg/aggregator/README.md
Normal file
30
pkg/aggregator/README.md
Normal file
@ -0,0 +1,30 @@
|
||||
## Data Plane Aggregator
|
||||
|
||||
### Testing queries
|
||||
|
||||
1. `custom.ini` changes:
|
||||
```ini
|
||||
[feature_toggles]
|
||||
kubernetesAggregator = true
|
||||
dataplaneAggregator = true
|
||||
grafanaAPIServerEnsureKubectlAccess = true
|
||||
```
|
||||
|
||||
2. start grafana:
|
||||
```bash
|
||||
make run
|
||||
```
|
||||
|
||||
3. enable aggregation for prometheus data source:
|
||||
```bash
|
||||
export KUBECONFIG=./data/grafana-apiserver/grafana.kubeconfig
|
||||
kubectl apply -f pkg/aggregator/examples/datasource.yml --validate=false
|
||||
dataplaneservice.aggregation.grafana.app/v0alpha1.prometheus.grafana.app created
|
||||
```
|
||||
|
||||
4. edit `pkg/aggregator/examples/datasource-query.json` and update the datasource UID to match the UID of a prometheus data source.
|
||||
|
||||
5. execute query (replace `example` with the UID of a prometheus data source):
|
||||
```bash
|
||||
curl 'http://admin:admin@localhost:3000/apis/prometheus.grafana.app/v0alpha1/namespaces/default/connections/example/query' -X POST -d '@pkg/aggregator/examples/datasource-query.json'
|
||||
```
|
@ -152,7 +152,7 @@ func (s *GrafanaAggregator) AddDataPlaneService(dataplaneService *v0alpha1.DataP
|
||||
return nil
|
||||
}
|
||||
|
||||
proxyPath := "/apis/dataplane/" + dataplaneService.Spec.Group + "/" + dataplaneService.Spec.Version
|
||||
proxyPath := "/apis/" + dataplaneService.Spec.Group + "/" + dataplaneService.Spec.Version
|
||||
proxyHandler := &dataPlaneServiceHandler{
|
||||
localDelegate: s.delegateHandler,
|
||||
client: s.PluginClient,
|
||||
@ -176,7 +176,7 @@ func (s *GrafanaAggregator) AddDataPlaneService(dataplaneService *v0alpha1.DataP
|
||||
func (s *GrafanaAggregator) RemoveDataPlaneService(dataplaneServiceName string) {
|
||||
version := v0alpha1helper.DataPlaneServiceNameToGroupVersion(dataplaneServiceName)
|
||||
|
||||
proxyPath := "/apis/dataplane/" + version.Group + "/" + version.Version
|
||||
proxyPath := "/apis/" + version.Group + "/" + version.Version
|
||||
s.GenericAPIServer.Handler.NonGoRestfulMux.Unregister(proxyPath)
|
||||
s.GenericAPIServer.Handler.NonGoRestfulMux.Unregister(proxyPath + "/")
|
||||
delete(s.proxyHandlers, dataplaneServiceName)
|
||||
@ -190,7 +190,7 @@ func (s *GrafanaAggregator) RemoveDataPlaneService(dataplaneServiceName string)
|
||||
return
|
||||
}
|
||||
delete(s.handledGroupVersions, version.Group)
|
||||
groupPath := "/apis/dataplane/" + version.Group
|
||||
groupPath := "/apis/" + version.Group
|
||||
s.GenericAPIServer.Handler.NonGoRestfulMux.Unregister(groupPath)
|
||||
s.GenericAPIServer.Handler.NonGoRestfulMux.Unregister(groupPath + "/")
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ func (h *PluginHandler) QueryDataHandler() http.HandlerFunc {
|
||||
// the datasource type in the query body should match the plugin ID
|
||||
if dsRef.Type != dsType {
|
||||
err := errors.New("invalid datasource type")
|
||||
klog.ErrorS(err, "type", dsType, "ref.Type", dsRef.Type)
|
||||
klog.ErrorS(err, err.Error(), "dsType", dsType, "refType", dsRef.Type)
|
||||
responder.Error(w, req, err)
|
||||
return
|
||||
}
|
||||
@ -55,7 +55,7 @@ func (h *PluginHandler) QueryDataHandler() http.HandlerFunc {
|
||||
// the UID in the query body should match the UID in the URL
|
||||
if dsRef.UID != dsUID {
|
||||
err := errors.New("invalid datasource UID")
|
||||
klog.ErrorS(err, "path", dsUID, "ref.UID", dsRef.UID)
|
||||
klog.ErrorS(err, err.Error(), "path", dsUID, "refUID", dsRef.UID)
|
||||
responder.Error(w, req, err)
|
||||
return
|
||||
}
|
||||
|
26
pkg/aggregator/examples/datasource-query.json
Normal file
26
pkg/aggregator/examples/datasource-query.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"queries": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "grafana_environment_info{}",
|
||||
"range": true,
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "example"
|
||||
},
|
||||
"editorMode": "code",
|
||||
"legendFormat": "__auto",
|
||||
"instant": false,
|
||||
"exemplar": false,
|
||||
"utcOffsetSec": 0,
|
||||
"scopes": [],
|
||||
"adhocFilters": [],
|
||||
"interval": "",
|
||||
"datasourceId": 2,
|
||||
"intervalMs": 15000,
|
||||
"maxDataPoints": 969
|
||||
}
|
||||
],
|
||||
"from": "now-1m",
|
||||
"to": "now"
|
||||
}
|
@ -3,6 +3,8 @@ kind: DataPlaneService
|
||||
metadata:
|
||||
name: v0alpha1.prometheus.grafana.app
|
||||
spec:
|
||||
pluginID: prometheus
|
||||
pluginType: datasource
|
||||
group: prometheus.grafana.app
|
||||
version: v0alpha1
|
||||
services:
|
Loading…
Reference in New Issue
Block a user