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() { ...@@ -327,11 +327,13 @@ func (hs *HTTPServer) registerRoutes() {
// metrics // metrics
apiRoute.Post("/tsdb/query", bind(dtos.MetricRequest{}), Wrap(hs.QueryMetrics)) 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/scenarios", Wrap(GetTestDataScenarios))
apiRoute.Get("/tsdb/testdata/gensql", reqGrafanaAdmin, Wrap(GenerateSQLTestData)) apiRoute.Get("/tsdb/testdata/gensql", reqGrafanaAdmin, Wrap(GenerateSQLTestData))
apiRoute.Get("/tsdb/testdata/random-walk", Wrap(GetTestDataRandomWalk)) 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) { apiRoute.Group("/alerts", func(alertsRoute routing.RouteRegister) {
alertsRoute.Post("/test", bind(dtos.AlertTestCommand{}), Wrap(AlertTest)) alertsRoute.Post("/test", bind(dtos.AlertTestCommand{}), Wrap(AlertTest))
alertsRoute.Post("/:alertId/pause", reqEditorRole, bind(dtos.PauseAlertCommand{}), Wrap(PauseAlert)) alertsRoute.Post("/:alertId/pause", reqEditorRole, bind(dtos.PauseAlertCommand{}), Wrap(PauseAlert))
......
...@@ -16,7 +16,7 @@ import ( ...@@ -16,7 +16,7 @@ import (
"github.com/grafana/grafana/pkg/util" "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 { func (hs *HTTPServer) QueryMetricsV2(c *m.ReqContext, reqDto dtos.MetricRequest) Response {
if !setting.IsExpressionsEnabled() { if !setting.IsExpressionsEnabled() {
return Error(404, "Expressions feature toggle is not enabled", nil) return Error(404, "Expressions feature toggle is not enabled", nil)
......
...@@ -137,8 +137,6 @@ function cancelNetworkRequestsOnUnsubscribe(req: DataQueryRequest) { ...@@ -137,8 +137,6 @@ function cancelNetworkRequestsOnUnsubscribe(req: DataQueryRequest) {
} }
export function callQueryMethod(datasource: DataSourceApi, request: DataQueryRequest) { export function callQueryMethod(datasource: DataSourceApi, request: DataQueryRequest) {
console.log('CALL', request.targets);
// If any query has an expression, use the expression endpoint // If any query has an expression, use the expression endpoint
for (const target of request.targets) { for (const target of request.targets) {
if (target.datasource === ExpressionDatasourceID) { if (target.datasource === ExpressionDatasourceID) {
......
...@@ -12,7 +12,7 @@ import { config } from '@grafana/runtime'; ...@@ -12,7 +12,7 @@ import { config } from '@grafana/runtime';
import { getBackendSrv } from 'app/core/services/backend_srv'; 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> { export class ExpressionDatasourceApi extends DataSourceApi<ExpressionQuery> {
constructor(instanceSettings: DataSourceInstanceSettings) { constructor(instanceSettings: DataSourceInstanceSettings) {
...@@ -26,30 +26,37 @@ export class ExpressionDatasourceApi extends DataSourceApi<ExpressionQuery> { ...@@ -26,30 +26,37 @@ export class ExpressionDatasourceApi extends DataSourceApi<ExpressionQuery> {
query(request: DataQueryRequest): Observable<DataQueryResponse> { query(request: DataQueryRequest): Observable<DataQueryResponse> {
const { targets, intervalMs, maxDataPoints, range } = request; const { targets, intervalMs, maxDataPoints, range } = request;
let expressionCount = 0;
const orgId = (window as any).grafanaBootData.user.orgId; const orgId = (window as any).grafanaBootData.user.orgId;
const queries = targets.map(q => { const queries = targets.map(q => {
if (q.datasource === ExpressionDatasourceID) { if (q.datasource === ExpressionDatasourceID) {
expressionCount++;
return { return {
...q, ...q,
datasourceId: this.id, datasourceId: this.id,
orgId, 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 { return {
...q, ...q,
datasourceId: ds.id, datasourceId: ds.id,
intervalMs, intervalMs,
maxDataPoints, maxDataPoints,
orgId, orgId,
// ?? alias: templateSrv.replace(q.alias || ''),
}; };
}); });
const req: Promise<DataQueryResponse> = getBackendSrv() const req: Promise<DataQueryResponse> = getBackendSrv()
.post('/api/tsdb/query/v2', { .post('/api/ds/query', {
from: range.from.valueOf().toString(), from: range.from.valueOf().toString(),
to: range.to.valueOf().toString(), to: range.to.valueOf().toString(),
queries: queries, queries: queries,
range,
expressionCount,
}) })
.then((rsp: any) => { .then((rsp: any) => {
return this.toDataQueryResponse(rsp); 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