Commit f19ffee5 by David Kaltschmidt

Fix rebase, fix empty field still issuing query problem

parent 0cd89e80
......@@ -456,7 +456,11 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
this.saveState();
};
buildQueryOptions(query: string, rowIndex: number, targetOptions: { format: string; hinting?: boolean; instant?: boolean }) {
buildQueryOptions(
query: string,
rowIndex: number,
targetOptions: { format: string; hinting?: boolean; instant?: boolean }
) {
const { datasource, range } = this.state;
const resolution = this.el.offsetWidth;
const absoluteRange = {
......@@ -483,7 +487,7 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
};
}
startQueryTransaction(query: string, rowIndex: number, resultType: string, options: any): QueryTransaction {
startQueryTransaction(query: string, rowIndex: number, resultType: ResultType, options: any): QueryTransaction {
const queryOptions = this.buildQueryOptions(query, rowIndex, options);
const transaction: QueryTransaction = {
query,
......@@ -565,6 +569,13 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
});
}
discardTransactions(rowIndex: number) {
this.setState(state => {
const remainingTransactions = state.queryTransactions.filter(qt => qt.rowIndex !== rowIndex);
return { queryTransactions: remainingTransactions };
});
}
failQueryTransaction(transactionId: string, error: string, datasourceId: string) {
const { datasource } = this.state;
if (datasource.meta.id !== datasourceId) {
......@@ -609,7 +620,6 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
const transaction = this.startQueryTransaction(query, rowIndex, 'Graph', {
format: 'time_series',
instant: false,
hinting: true,
});
try {
const now = Date.now();
......@@ -623,6 +633,8 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
const queryError = response.data ? response.data.error : response;
this.failQueryTransaction(transaction.id, queryError, datasourceId);
}
} else {
this.discardTransactions(rowIndex);
}
});
}
......@@ -637,18 +649,24 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
// Run all queries concurrently
queries.forEach(async (query, rowIndex) => {
if (query) {
const transaction = this.startQueryTransaction(query, rowIndex, 'Table', { format: 'table', instant: true });
const transaction = this.startQueryTransaction(query, rowIndex, 'Table', {
format: 'table',
instant: true,
valueWithRefId: true,
});
try {
const now = Date.now();
const res = await datasource.query(transaction.options);
const latency = Date.now() - now;
const results = mergeTablesIntoModel(new TableModel(), ...res.data);
const results = res.data[0];
this.completeQueryTransaction(transaction.id, results, latency, queries, datasourceId);
} catch (response) {
console.error(response);
const queryError = response.data ? response.data.error : response;
this.failQueryTransaction(transaction.id, queryError, datasourceId);
}
} else {
this.discardTransactions(rowIndex);
}
});
}
......@@ -675,6 +693,8 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
const queryError = response.data ? response.data.error : response;
this.failQueryTransaction(transaction.id, queryError, datasourceId);
}
} else {
this.discardTransactions(rowIndex);
}
});
}
......@@ -730,7 +750,10 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
const graphResult = _.flatten(
queryTransactions.filter(qt => qt.resultType === 'Graph' && qt.done && qt.result).map(qt => qt.result)
);
const tableResult = queryTransactions.filter(qt => qt.resultType === 'Table' && qt.done).map(qt => qt.result)[0];
const tableResult = mergeTablesIntoModel(
new TableModel(),
...queryTransactions.filter(qt => qt.resultType === 'Table' && qt.done).map(qt => qt.result)
);
const logsResult = _.flatten(
queryTransactions.filter(qt => qt.resultType === 'Logs' && qt.done).map(qt => qt.result)
);
......
......@@ -196,6 +196,7 @@ export class PrometheusDatasource {
query: queries[index].expr,
responseListLength: responseList.length,
refId: activeTargets[index].refId,
valueWithRefId: activeTargets[index].valueWithRefId,
};
const series = this.resultTransformer.transform(response, transformerOptions);
result = [...result, ...series];
......
......@@ -8,7 +8,14 @@ export class ResultTransformer {
const prometheusResult = response.data.data.result;
if (options.format === 'table') {
return [this.transformMetricDataToTable(prometheusResult, options.responseListLength, options.refId)];
return [
this.transformMetricDataToTable(
prometheusResult,
options.responseListLength,
options.refId,
options.valueWithRefId
),
];
} else if (options.format === 'heatmap') {
let seriesList = [];
prometheusResult.sort(sortSeriesByLabel);
......@@ -70,7 +77,7 @@ export class ResultTransformer {
};
}
transformMetricDataToTable(md, resultCount: number, refId: string) {
transformMetricDataToTable(md, resultCount: number, refId: string, valueWithRefId?: boolean) {
const table = new TableModel();
let i, j;
const metricLabels = {};
......@@ -95,7 +102,7 @@ export class ResultTransformer {
metricLabels[label] = labelIndex + 1;
table.columns.push({ text: label, filterable: !label.startsWith('__') });
});
const valueText = resultCount > 1 ? `Value #${refId}` : 'Value';
const valueText = resultCount > 1 || valueWithRefId ? `Value #${refId}` : 'Value';
table.columns.push({ text: valueText });
// Populate rows, set value to empty string when label not present.
......
......@@ -91,7 +91,7 @@
height: 2px;
position: relative;
overflow: hidden;
background: $table-border;
background: $text-color-faint;
margin: $panel-margin / 2;
}
......
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