diff --git a/pkg/aggregator/README.md b/pkg/aggregator/README.md new file mode 100644 index 00000000000..5bae5b94698 --- /dev/null +++ b/pkg/aggregator/README.md @@ -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' +``` \ No newline at end of file diff --git a/pkg/aggregator/apiserver/apiserver.go b/pkg/aggregator/apiserver/apiserver.go index 700de90aa84..61b088cadd1 100644 --- a/pkg/aggregator/apiserver/apiserver.go +++ b/pkg/aggregator/apiserver/apiserver.go @@ -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 + "/") } diff --git a/pkg/aggregator/apiserver/plugin/query.go b/pkg/aggregator/apiserver/plugin/query.go index 44a3fcb19a7..b790514ef31 100644 --- a/pkg/aggregator/apiserver/plugin/query.go +++ b/pkg/aggregator/apiserver/plugin/query.go @@ -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 } diff --git a/pkg/aggregator/examples/datasource-query.json b/pkg/aggregator/examples/datasource-query.json new file mode 100644 index 00000000000..a8803dab3ca --- /dev/null +++ b/pkg/aggregator/examples/datasource-query.json @@ -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" +} \ No newline at end of file diff --git a/pkg/aggregator/examples/prometheus.yml b/pkg/aggregator/examples/datasource.yml similarity index 81% rename from pkg/aggregator/examples/prometheus.yml rename to pkg/aggregator/examples/datasource.yml index 06e137f7cc7..85adbe6f89d 100644 --- a/pkg/aggregator/examples/prometheus.yml +++ b/pkg/aggregator/examples/datasource.yml @@ -3,6 +3,8 @@ kind: DataPlaneService metadata: name: v0alpha1.prometheus.grafana.app spec: + pluginID: prometheus + pluginType: datasource group: prometheus.grafana.app version: v0alpha1 services: