Errors: support errors with frame data from backend responses (#24176)

This commit is contained in:
Ryan McKinley
2020-05-04 11:05:04 -07:00
committed by GitHub
parent 9e06f9c402
commit 83683d87f8
11 changed files with 276 additions and 202 deletions

View File

@@ -18,6 +18,7 @@ import {
DataFrame,
guessFieldTypes,
} from '@grafana/data';
import { toDataQueryError } from '@grafana/runtime';
import { emitDataRequestEvent } from './analyticsProcessor';
import { ExpressionDatasourceID, expressionDatasource } from 'app/features/expressions/ExpressionDatasource';
@@ -117,7 +118,7 @@ export function runRequest(datasource: DataSourceApi, request: DataQueryRequest)
of({
...state.panelData,
state: LoadingState.Error,
error: processQueryError(err),
error: toDataQueryError(err),
})
),
tap(emitDataRequestEvent(datasource)),
@@ -153,30 +154,6 @@ export function callQueryMethod(datasource: DataSourceApi, request: DataQueryReq
return from(returnVal);
}
export function processQueryError(err: any): DataQueryError {
const error = (err || {}) as DataQueryError;
if (!error.message) {
if (typeof err === 'string' || err instanceof String) {
return { message: err } as DataQueryError;
}
let message = 'Query error';
if (error.message) {
message = error.message;
} else if (error.data && error.data.message) {
message = error.data.message;
} else if (error.data && error.data.error) {
message = error.data.error;
} else if (error.status) {
message = `Query error: ${error.status} ${error.statusText}`;
}
error.message = message;
}
return error;
}
/**
* All panels will be passed tables that have our best guess at colum type set
*

View File

@@ -14,7 +14,6 @@ import {
ScopedVars,
TimeRange,
DataFrame,
resultsToDataFrames,
DataQueryResponse,
LoadingState,
toDataFrame,
@@ -22,7 +21,7 @@ import {
FieldType,
LogRowModel,
} from '@grafana/data';
import { getBackendSrv } from '@grafana/runtime';
import { getBackendSrv, toDataQueryResponse } from '@grafana/runtime';
import { TemplateSrv } from 'app/features/templating/template_srv';
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
import { ThrottlingErrorMessage } from './components/ThrottlingErrorMessage';
@@ -496,6 +495,12 @@ export class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery, CloudWa
);
}
const resultsToDataFrames = (val: any): DataFrame[] => {
// NOTE: this function currently only processes binary results from:
// /api/ds/query -- it will retrun empty results most of the time
return toDataQueryResponse(val).data || [];
};
return from(this.awsRequest(TSDB_QUERY_ENDPOINT, requestParams)).pipe(
map(response => resultsToDataFrames(response)),
catchError(err => {

View File

@@ -14,13 +14,12 @@ import {
DataFrame,
} from '@grafana/data';
import { Scenario, TestDataQuery } from './types';
import { getBackendSrv } from '@grafana/runtime';
import { getBackendSrv, toDataQueryError } from '@grafana/runtime';
import { queryMetricTree } from './metricTree';
import { from, merge, Observable, of } from 'rxjs';
import { runStream } from './runStreams';
import templateSrv from 'app/features/templating/template_srv';
import { getSearchFilterScopedVar } from 'app/features/templating/utils';
import { processQueryError } from 'app/features/dashboard/state/runRequest';
type TestData = TimeSeries | TableData;
@@ -164,7 +163,7 @@ function runArrowFile(target: TestDataQuery, req: DataQueryRequest<TestDataQuery
data = [arrowTableToDataFrame(table)];
} catch (e) {
console.warn('Error reading saved arrow', e);
const error = processQueryError(e);
const error = toDataQueryError(e);
error.refId = target.refId;
return of({ state: LoadingState.Error, error, data });
}