mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: Align Explore with Dashboards and Panels (#16823)
* Wip: Removes queryTransactions from state * Refactor: Adds back query failures * Refactor: Moves error parsing to datasources * Refactor: Adds back hinting for Prometheus * Refactor: removed commented out code * Refactor: Adds back QueryStatus * Refactor: Adds scanning back to Explore * Fix: Fixes prettier error * Fix: Makes sure there is an error * Merge: Merges with master * Fix: Adds safeStringifyValue to error parsing * Fix: Fixes table result calculations * Refactor: Adds ErrorContainer and generic error handling in Explore * Fix: Fixes so refIds remain consistent * Refactor: Makes it possible to return result even when there are errors * Fix: Fixes digest issue with Angular editors * Refactor: Adds tests for explore utils * Refactor: Breakes current behaviour of always returning a result even if Query fails * Fix: Fixes Prettier error * Fix: Adds back console.log for erroneous querys * Refactor: Changes console.log to console.error
This commit is contained in:
@@ -15,10 +15,12 @@ import {
|
||||
SeriesData,
|
||||
DataSourceApi,
|
||||
DataSourceInstanceSettings,
|
||||
DataQueryError,
|
||||
} from '@grafana/ui/src/types';
|
||||
import { LokiQuery, LokiOptions } from './types';
|
||||
import { BackendSrv } from 'app/core/services/backend_srv';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { safeStringifyValue } from 'app/core/utils/explore';
|
||||
|
||||
export const DEFAULT_MAX_LINES = 1000;
|
||||
|
||||
@@ -65,16 +67,18 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
||||
return this.backendSrv.datasourceRequest(req);
|
||||
}
|
||||
|
||||
prepareQueryTarget(target, options) {
|
||||
prepareQueryTarget(target: LokiQuery, options: DataQueryRequest<LokiQuery>) {
|
||||
const interpolated = this.templateSrv.replace(target.expr);
|
||||
const start = this.getTime(options.range.from, false);
|
||||
const end = this.getTime(options.range.to, true);
|
||||
const refId = target.refId;
|
||||
return {
|
||||
...DEFAULT_QUERY_PARAMS,
|
||||
...parseQuery(interpolated),
|
||||
start,
|
||||
end,
|
||||
limit: this.maxLines,
|
||||
refId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -87,16 +91,47 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
||||
return Promise.resolve({ data: [] });
|
||||
}
|
||||
|
||||
const queries = queryTargets.map(target => this._request('/api/prom/query', target));
|
||||
const queries = queryTargets.map(target =>
|
||||
this._request('/api/prom/query', target).catch((err: any) => {
|
||||
if (err.cancelled) {
|
||||
return err;
|
||||
}
|
||||
|
||||
const error: DataQueryError = {
|
||||
message: 'Unknown error during query transaction. Please check JS console logs.',
|
||||
refId: target.refId,
|
||||
};
|
||||
|
||||
if (err.data) {
|
||||
if (typeof err.data === 'string') {
|
||||
error.message = err.data;
|
||||
} else if (err.data.error) {
|
||||
error.message = safeStringifyValue(err.data.error);
|
||||
}
|
||||
} else if (err.message) {
|
||||
error.message = err.message;
|
||||
} else if (typeof err === 'string') {
|
||||
error.message = err;
|
||||
}
|
||||
|
||||
error.status = err.status;
|
||||
error.statusText = err.statusText;
|
||||
|
||||
throw error;
|
||||
})
|
||||
);
|
||||
|
||||
return Promise.all(queries).then((results: any[]) => {
|
||||
const series: SeriesData[] = [];
|
||||
const series: Array<SeriesData | DataQueryError> = [];
|
||||
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
const result = results[i];
|
||||
|
||||
if (result.data) {
|
||||
const refId = queryTargets[i].refId;
|
||||
for (const stream of result.data.streams || []) {
|
||||
const seriesData = logStreamToSeriesData(stream);
|
||||
seriesData.refId = refId;
|
||||
seriesData.meta = {
|
||||
search: queryTargets[i].regexp,
|
||||
limit: this.maxLines,
|
||||
|
||||
Reference in New Issue
Block a user