From d9d84f45bc103775f0d6133408ea809e7025ad62 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Mon, 3 Dec 2018 16:58:46 +0100 Subject: [PATCH 1/9] only make it possible to scan for older logs if there is at least one non failing selector --- public/app/features/explore/Explore.tsx | 2 ++ public/app/features/explore/Logs.tsx | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index 3e35a68bf84..17ee35fda9b 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -836,6 +836,7 @@ export class Explore extends React.PureComponent { const graphLoading = queryTransactions.some(qt => qt.resultType === 'Graph' && !qt.done); const tableLoading = queryTransactions.some(qt => qt.resultType === 'Table' && !qt.done); const logsLoading = queryTransactions.some(qt => qt.resultType === 'Logs' && !qt.done); + const logExpressionExists = queryTransactions.some(qt => qt.resultType === 'Logs' && qt.query.expr && !qt.error); const loading = queryTransactions.some(qt => !qt.done); return ( @@ -969,6 +970,7 @@ export class Explore extends React.PureComponent { range={range} scanning={scanning} scanRange={scanRange} + logExpressionExists={logExpressionExists} /> )} diff --git a/public/app/features/explore/Logs.tsx b/public/app/features/explore/Logs.tsx index 6447ec895ed..5cadfb13b0d 100644 --- a/public/app/features/explore/Logs.tsx +++ b/public/app/features/explore/Logs.tsx @@ -140,6 +140,7 @@ interface LogsProps { range?: RawTimeRange; scanning?: boolean; scanRange?: RawTimeRange; + logExpressionExists?: boolean; onChangeTime?: (range: RawTimeRange) => void; onClickLabel?: (label: string, value: string) => void; onStartScanning?: () => void; @@ -239,7 +240,17 @@ export default class Logs extends PureComponent { }; render() { - const { className = '', data, loading = false, onClickLabel, position, range, scanning, scanRange } = this.props; + const { + className = '', + data, + loading = false, + onClickLabel, + position, + range, + scanning, + scanRange, + logExpressionExists, + } = this.props; const { dedup, deferLogs, hiddenLogLevels, renderAll, showLocalTime, showUtc } = this.state; let { showLabels } = this.state; const hasData = data && data.rows && data.rows.length > 0; @@ -357,7 +368,8 @@ export default class Logs extends PureComponent { ))} {hasData && deferLogs && Rendering {dedupedData.rows.length} rows...} - {!loading && + {logExpressionExists && + !loading && !hasData && !scanning && (
From e21ca3f545260fc03171f3c22587f1561d455992 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Mon, 3 Dec 2018 17:17:57 +0100 Subject: [PATCH 2/9] Revert commit --- public/app/features/explore/Explore.tsx | 2 -- public/app/features/explore/Logs.tsx | 16 ++-------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index 17ee35fda9b..3e35a68bf84 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -836,7 +836,6 @@ export class Explore extends React.PureComponent { const graphLoading = queryTransactions.some(qt => qt.resultType === 'Graph' && !qt.done); const tableLoading = queryTransactions.some(qt => qt.resultType === 'Table' && !qt.done); const logsLoading = queryTransactions.some(qt => qt.resultType === 'Logs' && !qt.done); - const logExpressionExists = queryTransactions.some(qt => qt.resultType === 'Logs' && qt.query.expr && !qt.error); const loading = queryTransactions.some(qt => !qt.done); return ( @@ -970,7 +969,6 @@ export class Explore extends React.PureComponent { range={range} scanning={scanning} scanRange={scanRange} - logExpressionExists={logExpressionExists} /> )} diff --git a/public/app/features/explore/Logs.tsx b/public/app/features/explore/Logs.tsx index 5cadfb13b0d..6447ec895ed 100644 --- a/public/app/features/explore/Logs.tsx +++ b/public/app/features/explore/Logs.tsx @@ -140,7 +140,6 @@ interface LogsProps { range?: RawTimeRange; scanning?: boolean; scanRange?: RawTimeRange; - logExpressionExists?: boolean; onChangeTime?: (range: RawTimeRange) => void; onClickLabel?: (label: string, value: string) => void; onStartScanning?: () => void; @@ -240,17 +239,7 @@ export default class Logs extends PureComponent { }; render() { - const { - className = '', - data, - loading = false, - onClickLabel, - position, - range, - scanning, - scanRange, - logExpressionExists, - } = this.props; + const { className = '', data, loading = false, onClickLabel, position, range, scanning, scanRange } = this.props; const { dedup, deferLogs, hiddenLogLevels, renderAll, showLocalTime, showUtc } = this.state; let { showLabels } = this.state; const hasData = data && data.rows && data.rows.length > 0; @@ -368,8 +357,7 @@ export default class Logs extends PureComponent { ))} {hasData && deferLogs && Rendering {dedupedData.rows.length} rows...}
- {logExpressionExists && - !loading && + {!loading && !hasData && !scanning && (
From 541a691aca8fc681b7e39d7c9ae4a1f2e13ca21e Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 4 Dec 2018 11:00:21 +0100 Subject: [PATCH 3/9] only display scan button if there is at least one existing selector that returned an empty result --- public/app/core/logs_model.ts | 1 + public/app/core/utils/explore.ts | 15 +++++++++++---- public/app/features/explore/Explore.tsx | 2 +- public/app/features/explore/Logs.tsx | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/public/app/core/logs_model.ts b/public/app/core/logs_model.ts index c05f5bab866..5ae32a1d1bb 100644 --- a/public/app/core/logs_model.ts +++ b/public/app/core/logs_model.ts @@ -62,6 +62,7 @@ export interface LogsModel { meta?: LogsMetaItem[]; rows: LogRow[]; series?: TimeSeries[]; + queryEmpty?: boolean; } export interface LogsStream { diff --git a/public/app/core/utils/explore.ts b/public/app/core/utils/explore.ts index be771c1b232..59d9e701992 100644 --- a/public/app/core/utils/explore.ts +++ b/public/app/core/utils/explore.ts @@ -133,7 +133,12 @@ export function ensureQueries(queries?: DataQuery[]): DataQuery[] { * A target is non-empty when it has keys other than refId and key. */ export function hasNonEmptyQuery(queries: DataQuery[]): boolean { - return queries.some(query => Object.keys(query).length > 2); + return queries.some( + query => + Object.keys(query) + .map(k => query[k]) + .filter(v => v).length > 2 + ); } export function calculateResultsFromQueryTransactions( @@ -148,15 +153,17 @@ export function calculateResultsFromQueryTransactions( new TableModel(), ...queryTransactions.filter(qt => qt.resultType === 'Table' && qt.done && qt.result).map(qt => qt.result) ); - const logsResult = - datasource && datasource.mergeStreams + const logsResult = { + ...datasource && datasource.mergeStreams ? datasource.mergeStreams( _.flatten( queryTransactions.filter(qt => qt.resultType === 'Logs' && qt.done && qt.result).map(qt => qt.result) ), graphInterval ) - : undefined; + : undefined, + queryEmpty: queryTransactions.filter(qt => qt.resultType === 'Logs' && qt.done).every(qt => qt.result.length === 0), + }; return { graphResult, diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index 3e35a68bf84..7205e486992 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -220,7 +220,7 @@ export class Explore extends React.PureComponent { modifiedQueries = [...this.modifiedQueries]; } else if (datasource.importQueries) { // Datasource-specific importers - modifiedQueries = await datasource.importQueries(this.modifiedQueries, origin.meta); + modifiedQueries = await datasource.importQueries(this.modifiedQueries, datasource.meta); } else { // Default is blank queries modifiedQueries = ensureQueries(); diff --git a/public/app/features/explore/Logs.tsx b/public/app/features/explore/Logs.tsx index 6447ec895ed..42a9a2fdbb0 100644 --- a/public/app/features/explore/Logs.tsx +++ b/public/app/features/explore/Logs.tsx @@ -358,7 +358,7 @@ export default class Logs extends PureComponent { {hasData && deferLogs && Rendering {dedupedData.rows.length} rows...}
{!loading && - !hasData && + data.queryEmpty && !scanning && (
No logs found. From 2be92af4567591e4c40b92f3f8a6d27c1e3cb3f3 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 4 Dec 2018 11:13:16 +0100 Subject: [PATCH 4/9] Use origin meta --- public/app/features/explore/Explore.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index 7205e486992..3e35a68bf84 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -220,7 +220,7 @@ export class Explore extends React.PureComponent { modifiedQueries = [...this.modifiedQueries]; } else if (datasource.importQueries) { // Datasource-specific importers - modifiedQueries = await datasource.importQueries(this.modifiedQueries, datasource.meta); + modifiedQueries = await datasource.importQueries(this.modifiedQueries, origin.meta); } else { // Default is blank queries modifiedQueries = ensureQueries(); From 2af78aca8edcfb0b3267c01b2600e522ee16a5b2 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 4 Dec 2018 13:23:26 +0100 Subject: [PATCH 5/9] Remove query empty from model --- public/app/core/logs_model.ts | 1 - public/app/core/utils/explore.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/public/app/core/logs_model.ts b/public/app/core/logs_model.ts index 5ae32a1d1bb..c05f5bab866 100644 --- a/public/app/core/logs_model.ts +++ b/public/app/core/logs_model.ts @@ -62,7 +62,6 @@ export interface LogsModel { meta?: LogsMetaItem[]; rows: LogRow[]; series?: TimeSeries[]; - queryEmpty?: boolean; } export interface LogsStream { diff --git a/public/app/core/utils/explore.ts b/public/app/core/utils/explore.ts index 59d9e701992..271ea0a2a23 100644 --- a/public/app/core/utils/explore.ts +++ b/public/app/core/utils/explore.ts @@ -162,7 +162,6 @@ export function calculateResultsFromQueryTransactions( graphInterval ) : undefined, - queryEmpty: queryTransactions.filter(qt => qt.resultType === 'Logs' && qt.done).every(qt => qt.result.length === 0), }; return { From 4e591653bd261f45dac1a04eba7928e7a601a967 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 4 Dec 2018 13:26:26 +0100 Subject: [PATCH 6/9] Set query empty condition in render function. Also clear query transactions when no valid query is present --- public/app/features/explore/Explore.tsx | 5 +++++ public/app/features/explore/Logs.tsx | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index 3e35a68bf84..b381fdbcd41 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -771,6 +771,9 @@ export class Explore extends React.PureComponent { async runQueries(resultType: ResultType, queryOptions: any, resultGetter?: any) { const queries = [...this.modifiedQueries]; if (!hasNonEmptyQuery(queries)) { + this.setState({ + queryTransactions: [], + }); return; } const { datasource } = this.state; @@ -837,6 +840,7 @@ export class Explore extends React.PureComponent { const tableLoading = queryTransactions.some(qt => qt.resultType === 'Table' && !qt.done); const logsLoading = queryTransactions.some(qt => qt.resultType === 'Logs' && !qt.done); const loading = queryTransactions.some(qt => !qt.done); + const queryEmpty = queryTransactions.some(qt => qt.resultType === 'Logs' && qt.done && qt.result.length === 0); return (
@@ -969,6 +973,7 @@ export class Explore extends React.PureComponent { range={range} scanning={scanning} scanRange={scanRange} + queryEmpty={queryEmpty} /> )} diff --git a/public/app/features/explore/Logs.tsx b/public/app/features/explore/Logs.tsx index 42a9a2fdbb0..8d098813490 100644 --- a/public/app/features/explore/Logs.tsx +++ b/public/app/features/explore/Logs.tsx @@ -140,6 +140,7 @@ interface LogsProps { range?: RawTimeRange; scanning?: boolean; scanRange?: RawTimeRange; + queryEmpty: boolean; onChangeTime?: (range: RawTimeRange) => void; onClickLabel?: (label: string, value: string) => void; onStartScanning?: () => void; @@ -239,7 +240,17 @@ export default class Logs extends PureComponent { }; render() { - const { className = '', data, loading = false, onClickLabel, position, range, scanning, scanRange } = this.props; + const { + className = '', + data, + loading = false, + onClickLabel, + position, + range, + scanning, + scanRange, + queryEmpty, + } = this.props; const { dedup, deferLogs, hiddenLogLevels, renderAll, showLocalTime, showUtc } = this.state; let { showLabels } = this.state; const hasData = data && data.rows && data.rows.length > 0; @@ -358,7 +369,7 @@ export default class Logs extends PureComponent { {hasData && deferLogs && Rendering {dedupedData.rows.length} rows...}
{!loading && - data.queryEmpty && + queryEmpty && !scanning && (
No logs found. From 8b3bb95007fb86078a03dfa2f6508f4a382feaa2 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 4 Dec 2018 14:01:32 +0100 Subject: [PATCH 7/9] remove redudant spread --- public/app/core/utils/explore.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/public/app/core/utils/explore.ts b/public/app/core/utils/explore.ts index 271ea0a2a23..89537081fd3 100644 --- a/public/app/core/utils/explore.ts +++ b/public/app/core/utils/explore.ts @@ -153,16 +153,15 @@ export function calculateResultsFromQueryTransactions( new TableModel(), ...queryTransactions.filter(qt => qt.resultType === 'Table' && qt.done && qt.result).map(qt => qt.result) ); - const logsResult = { - ...datasource && datasource.mergeStreams + const logsResult = + datasource && datasource.mergeStreams ? datasource.mergeStreams( _.flatten( queryTransactions.filter(qt => qt.resultType === 'Logs' && qt.done && qt.result).map(qt => qt.result) ), graphInterval ) - : undefined, - }; + : undefined; return { graphResult, From 9c8bd347871718bf0498c045be37870245385471 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 4 Dec 2018 14:55:56 +0100 Subject: [PATCH 8/9] remove all query empty related code. root cause of the problem was to fix hasNonEmptyQuery --- public/app/features/explore/Explore.tsx | 2 -- public/app/features/explore/Logs.tsx | 15 ++------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index b381fdbcd41..7e0120c9079 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -840,7 +840,6 @@ export class Explore extends React.PureComponent { const tableLoading = queryTransactions.some(qt => qt.resultType === 'Table' && !qt.done); const logsLoading = queryTransactions.some(qt => qt.resultType === 'Logs' && !qt.done); const loading = queryTransactions.some(qt => !qt.done); - const queryEmpty = queryTransactions.some(qt => qt.resultType === 'Logs' && qt.done && qt.result.length === 0); return (
@@ -973,7 +972,6 @@ export class Explore extends React.PureComponent { range={range} scanning={scanning} scanRange={scanRange} - queryEmpty={queryEmpty} /> )} diff --git a/public/app/features/explore/Logs.tsx b/public/app/features/explore/Logs.tsx index 8d098813490..6447ec895ed 100644 --- a/public/app/features/explore/Logs.tsx +++ b/public/app/features/explore/Logs.tsx @@ -140,7 +140,6 @@ interface LogsProps { range?: RawTimeRange; scanning?: boolean; scanRange?: RawTimeRange; - queryEmpty: boolean; onChangeTime?: (range: RawTimeRange) => void; onClickLabel?: (label: string, value: string) => void; onStartScanning?: () => void; @@ -240,17 +239,7 @@ export default class Logs extends PureComponent { }; render() { - const { - className = '', - data, - loading = false, - onClickLabel, - position, - range, - scanning, - scanRange, - queryEmpty, - } = this.props; + const { className = '', data, loading = false, onClickLabel, position, range, scanning, scanRange } = this.props; const { dedup, deferLogs, hiddenLogLevels, renderAll, showLocalTime, showUtc } = this.state; let { showLabels } = this.state; const hasData = data && data.rows && data.rows.length > 0; @@ -369,7 +358,7 @@ export default class Logs extends PureComponent { {hasData && deferLogs && Rendering {dedupedData.rows.length} rows...}
{!loading && - queryEmpty && + !hasData && !scanning && (
No logs found. From 27c4db06fc380aaf3082a101d483611815bf4f2b Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 4 Dec 2018 15:00:24 +0100 Subject: [PATCH 9/9] improve comments --- public/app/core/utils/explore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/core/utils/explore.ts b/public/app/core/utils/explore.ts index 89537081fd3..e268508b833 100644 --- a/public/app/core/utils/explore.ts +++ b/public/app/core/utils/explore.ts @@ -130,7 +130,7 @@ export function ensureQueries(queries?: DataQuery[]): DataQuery[] { } /** - * A target is non-empty when it has keys other than refId and key. + * A target is non-empty when it has keys (with non-empty values) other than refId and key. */ export function hasNonEmptyQuery(queries: DataQuery[]): boolean { return queries.some(