3
0
mirror of https://github.com/grafana/grafana.git synced 2025-02-25 18:55:37 -06:00

Aggregator: Add README and example query ()

This commit is contained in:
Todd Treece 2024-09-13 15:55:26 -04:00 committed by GitHub
parent 3df62c28bb
commit 80795fcfd5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 63 additions and 5 deletions

30
pkg/aggregator/README.md Normal file
View 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'
```

View File

@ -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 + "/")
}

View File

@ -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
}

View 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"
}

View File

@ -3,6 +3,8 @@ kind: DataPlaneService
metadata:
name: v0alpha1.prometheus.grafana.app
spec:
pluginID: prometheus
pluginType: datasource
group: prometheus.grafana.app
version: v0alpha1
services: