Commit 4d1b969a by Ryan McKinley Committed by GitHub

GEL: include the expression count in the request (#20114)

parent bbff282b
......@@ -327,11 +327,13 @@ func (hs *HTTPServer) registerRoutes() {
// metrics
apiRoute.Post("/tsdb/query", bind(dtos.MetricRequest{}), Wrap(hs.QueryMetrics))
apiRoute.Post("/tsdb/query/v2", bind(dtos.MetricRequest{}), Wrap(hs.QueryMetricsV2))
apiRoute.Get("/tsdb/testdata/scenarios", Wrap(GetTestDataScenarios))
apiRoute.Get("/tsdb/testdata/gensql", reqGrafanaAdmin, Wrap(GenerateSQLTestData))
apiRoute.Get("/tsdb/testdata/random-walk", Wrap(GetTestDataRandomWalk))
// DataSource w/ expressions
apiRoute.Post("/ds/query", bind(dtos.MetricRequest{}), Wrap(hs.QueryMetricsV2))
apiRoute.Group("/alerts", func(alertsRoute routing.RouteRegister) {
alertsRoute.Post("/test", bind(dtos.AlertTestCommand{}), Wrap(AlertTest))
alertsRoute.Post("/:alertId/pause", reqEditorRole, bind(dtos.PauseAlertCommand{}), Wrap(PauseAlert))
......
......@@ -16,7 +16,7 @@ import (
"github.com/grafana/grafana/pkg/util"
)
// POST /api/tsdb/query/v2
// POST /api/ds/query DataSource query w/ expressions
func (hs *HTTPServer) QueryMetricsV2(c *m.ReqContext, reqDto dtos.MetricRequest) Response {
if !setting.IsExpressionsEnabled() {
return Error(404, "Expressions feature toggle is not enabled", nil)
......
......@@ -137,8 +137,6 @@ function cancelNetworkRequestsOnUnsubscribe(req: DataQueryRequest) {
}
export function callQueryMethod(datasource: DataSourceApi, request: DataQueryRequest) {
console.log('CALL', request.targets);
// If any query has an expression, use the expression endpoint
for (const target of request.targets) {
if (target.datasource === ExpressionDatasourceID) {
......
......@@ -12,7 +12,7 @@ import { config } from '@grafana/runtime';
import { getBackendSrv } from 'app/core/services/backend_srv';
/**
* This is a singleton that is not actually instantiated
* This is a singleton instance that just pretends to be a DataSource
*/
export class ExpressionDatasourceApi extends DataSourceApi<ExpressionQuery> {
constructor(instanceSettings: DataSourceInstanceSettings) {
......@@ -26,30 +26,37 @@ export class ExpressionDatasourceApi extends DataSourceApi<ExpressionQuery> {
query(request: DataQueryRequest): Observable<DataQueryResponse> {
const { targets, intervalMs, maxDataPoints, range } = request;
let expressionCount = 0;
const orgId = (window as any).grafanaBootData.user.orgId;
const queries = targets.map(q => {
if (q.datasource === ExpressionDatasourceID) {
expressionCount++;
return {
...q,
datasourceId: this.id,
orgId,
};
}
const ds = config.datasources[q.datasource || config.defaultDatasource];
const dsName = q.datasource && q.datasource !== 'default' ? q.datasource : config.defaultDatasource;
const ds = config.datasources[dsName];
if (!ds) {
throw new Error('Unknown Datasource: ' + q.datasource);
}
return {
...q,
datasourceId: ds.id,
intervalMs,
maxDataPoints,
orgId,
// ?? alias: templateSrv.replace(q.alias || ''),
};
});
const req: Promise<DataQueryResponse> = getBackendSrv()
.post('/api/tsdb/query/v2', {
.post('/api/ds/query', {
from: range.from.valueOf().toString(),
to: range.to.valueOf().toString(),
queries: queries,
range,
expressionCount,
})
.then((rsp: any) => {
return this.toDataQueryResponse(rsp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment