|
|
@@ -16,47 +16,39 @@ jest.mock('@grafana/data/src/utils/moment_wrapper', () => ({
|
|
|
import { ResultProcessor } from './ResultProcessor';
|
|
|
import { ExploreItemState, ExploreMode } from 'app/types/explore';
|
|
|
import TableModel from 'app/core/table_model';
|
|
|
-import { TimeSeries, LogRowModel, LogsMetaItem, GraphSeriesXY } from '@grafana/data';
|
|
|
+import { TimeSeries, LogRowModel, LogsMetaItem, GraphSeriesXY, toDataFrame, FieldType } from '@grafana/data';
|
|
|
|
|
|
const testContext = (options: any = {}) => {
|
|
|
- const response = [
|
|
|
- {
|
|
|
- target: 'A-series',
|
|
|
- alias: 'A-series',
|
|
|
- datapoints: [[39.91264531864214, 1559038518831], [40.35179822906545, 1559038519831]],
|
|
|
- refId: 'A',
|
|
|
- },
|
|
|
- {
|
|
|
- columns: [
|
|
|
- {
|
|
|
- text: 'Time',
|
|
|
- },
|
|
|
- {
|
|
|
- text: 'Message',
|
|
|
- },
|
|
|
- {
|
|
|
- text: 'Description',
|
|
|
- },
|
|
|
- {
|
|
|
- text: 'Value',
|
|
|
- },
|
|
|
- ],
|
|
|
- rows: [
|
|
|
- [1559038518831, 'This is a message', 'Description', 23.1],
|
|
|
- [1559038519831, 'This is a message', 'Description', 23.1],
|
|
|
- ],
|
|
|
- refId: 'B',
|
|
|
- },
|
|
|
- ];
|
|
|
+ const timeSeries = toDataFrame({
|
|
|
+ name: 'A-series',
|
|
|
+ refId: 'A',
|
|
|
+ fields: [
|
|
|
+ { name: 'A-series', type: FieldType.number, values: [4, 5, 6] },
|
|
|
+ { name: 'time', type: FieldType.time, values: [100, 200, 300] },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+
|
|
|
+ const table = toDataFrame({
|
|
|
+ name: 'table-res',
|
|
|
+ refId: 'A',
|
|
|
+ fields: [
|
|
|
+ { name: 'value', type: FieldType.number, values: [4, 5, 6] },
|
|
|
+ { name: 'time', type: FieldType.time, values: [100, 200, 300] },
|
|
|
+ { name: 'message', type: FieldType.string, values: ['this is a message', 'second message', 'third'] },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+
|
|
|
const defaultOptions = {
|
|
|
mode: ExploreMode.Metrics,
|
|
|
replacePreviousResults: true,
|
|
|
- result: { data: response },
|
|
|
+ dataFrames: [timeSeries, table],
|
|
|
graphResult: [] as TimeSeries[],
|
|
|
tableResult: new TableModel(),
|
|
|
logsResult: { hasUniqueLabels: false, rows: [] as LogRowModel[] },
|
|
|
};
|
|
|
+
|
|
|
const combinedOptions = { ...defaultOptions, ...options };
|
|
|
+
|
|
|
const state = ({
|
|
|
mode: combinedOptions.mode,
|
|
|
graphResult: combinedOptions.graphResult,
|
|
|
@@ -64,28 +56,24 @@ const testContext = (options: any = {}) => {
|
|
|
logsResult: combinedOptions.logsResult,
|
|
|
queryIntervals: { intervalMs: 10 },
|
|
|
} as any) as ExploreItemState;
|
|
|
- const resultProcessor = new ResultProcessor(state, combinedOptions.replacePreviousResults, combinedOptions.result);
|
|
|
+
|
|
|
+ const resultProcessor = new ResultProcessor(
|
|
|
+ state,
|
|
|
+ combinedOptions.replacePreviousResults,
|
|
|
+ combinedOptions.dataFrames
|
|
|
+ );
|
|
|
|
|
|
return {
|
|
|
- result: combinedOptions.result,
|
|
|
+ dataFrames: combinedOptions.dataFrames,
|
|
|
resultProcessor,
|
|
|
};
|
|
|
};
|
|
|
|
|
|
describe('ResultProcessor', () => {
|
|
|
describe('constructed without result', () => {
|
|
|
- describe('when calling getRawData', () => {
|
|
|
- it('then it should return an empty array', () => {
|
|
|
- const { resultProcessor } = testContext({ result: null });
|
|
|
- const theResult = resultProcessor.getRawData();
|
|
|
-
|
|
|
- expect(theResult).toEqual([]);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
describe('when calling getGraphResult', () => {
|
|
|
it('then it should return an empty array', () => {
|
|
|
- const { resultProcessor } = testContext({ result: null });
|
|
|
+ const { resultProcessor } = testContext({ dataFrames: [] });
|
|
|
const theResult = resultProcessor.getGraphResult();
|
|
|
|
|
|
expect(theResult).toEqual([]);
|
|
|
@@ -94,7 +82,7 @@ describe('ResultProcessor', () => {
|
|
|
|
|
|
describe('when calling getTableResult', () => {
|
|
|
it('then it should return an empty TableModel', () => {
|
|
|
- const { resultProcessor } = testContext({ result: null });
|
|
|
+ const { resultProcessor } = testContext({ dataFrames: [] });
|
|
|
const theResult = resultProcessor.getTableResult();
|
|
|
|
|
|
expect(theResult).toEqual(new TableModel());
|
|
|
@@ -103,7 +91,7 @@ describe('ResultProcessor', () => {
|
|
|
|
|
|
describe('when calling getLogsResult', () => {
|
|
|
it('then it should return null', () => {
|
|
|
- const { resultProcessor } = testContext({ result: null });
|
|
|
+ const { resultProcessor } = testContext({ dataFrames: [] });
|
|
|
const theResult = resultProcessor.getLogsResult();
|
|
|
|
|
|
expect(theResult).toBeNull();
|
|
|
@@ -112,15 +100,6 @@ describe('ResultProcessor', () => {
|
|
|
});
|
|
|
|
|
|
describe('constructed with a result that is a DataQueryResponse', () => {
|
|
|
- describe('when calling getRawData', () => {
|
|
|
- it('then it should return result.data', () => {
|
|
|
- const { result, resultProcessor } = testContext();
|
|
|
- const theResult = resultProcessor.getRawData();
|
|
|
-
|
|
|
- expect(theResult).toEqual(result.data);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
describe('when calling getGraphResult', () => {
|
|
|
it('then it should return correct graph result', () => {
|
|
|
const { resultProcessor } = testContext();
|
|
|
@@ -130,7 +109,7 @@ describe('ResultProcessor', () => {
|
|
|
{
|
|
|
label: 'A-series',
|
|
|
color: '#7EB26D',
|
|
|
- data: [[1559038518831, 39.91264531864214], [1559038519831, 40.35179822906545]],
|
|
|
+ data: [[100, 4], [200, 5], [300, 6]],
|
|
|
info: undefined,
|
|
|
isVisible: true,
|
|
|
yAxis: {
|
|
|
@@ -148,11 +127,12 @@ describe('ResultProcessor', () => {
|
|
|
|
|
|
expect(theResult).toEqual({
|
|
|
columnMap: {},
|
|
|
- columns: [{ text: 'Time' }, { text: 'Message' }, { text: 'Description' }, { text: 'Value' }],
|
|
|
- rows: [
|
|
|
- [1559038518831, 'This is a message', 'Description', 23.1],
|
|
|
- [1559038519831, 'This is a message', 'Description', 23.1],
|
|
|
+ columns: [
|
|
|
+ { text: 'value', type: 'number', filterable: undefined },
|
|
|
+ { text: 'time', type: 'time', filterable: undefined },
|
|
|
+ { text: 'message', type: 'string', filterable: undefined },
|
|
|
],
|
|
|
+ rows: [[4, 100, 'this is a message'], [5, 200, 'second message'], [6, 300, 'third']],
|
|
|
type: 'table',
|
|
|
});
|
|
|
});
|
|
|
@@ -160,41 +140,53 @@ describe('ResultProcessor', () => {
|
|
|
|
|
|
describe('when calling getLogsResult', () => {
|
|
|
it('then it should return correct logs result', () => {
|
|
|
- const { resultProcessor } = testContext({ mode: ExploreMode.Logs, observerResponse: null });
|
|
|
+ const { resultProcessor } = testContext({ mode: ExploreMode.Logs });
|
|
|
const theResult = resultProcessor.getLogsResult();
|
|
|
|
|
|
- console.log(JSON.stringify(theResult));
|
|
|
-
|
|
|
expect(theResult).toEqual({
|
|
|
hasUniqueLabels: false,
|
|
|
meta: [],
|
|
|
rows: [
|
|
|
{
|
|
|
- entry: 'This is a message',
|
|
|
+ entry: 'third',
|
|
|
+ hasAnsi: false,
|
|
|
+ labels: undefined,
|
|
|
+ logLevel: 'unknown',
|
|
|
+ raw: 'third',
|
|
|
+ searchWords: [] as string[],
|
|
|
+ timeEpochMs: 300,
|
|
|
+ timeFromNow: 'fromNow() jest mocked',
|
|
|
+ timeLocal: 'format() jest mocked',
|
|
|
+ timeUtc: 'format() jest mocked',
|
|
|
+ timestamp: 300,
|
|
|
+ uniqueLabels: {},
|
|
|
+ },
|
|
|
+ {
|
|
|
+ entry: 'second message',
|
|
|
hasAnsi: false,
|
|
|
labels: undefined,
|
|
|
logLevel: 'unknown',
|
|
|
- raw: 'This is a message',
|
|
|
+ raw: 'second message',
|
|
|
searchWords: [] as string[],
|
|
|
- timeEpochMs: 1559038519831,
|
|
|
+ timeEpochMs: 200,
|
|
|
timeFromNow: 'fromNow() jest mocked',
|
|
|
timeLocal: 'format() jest mocked',
|
|
|
timeUtc: 'format() jest mocked',
|
|
|
- timestamp: 1559038519831,
|
|
|
+ timestamp: 200,
|
|
|
uniqueLabels: {},
|
|
|
},
|
|
|
{
|
|
|
- entry: 'This is a message',
|
|
|
+ entry: 'this is a message',
|
|
|
hasAnsi: false,
|
|
|
labels: undefined,
|
|
|
logLevel: 'unknown',
|
|
|
- raw: 'This is a message',
|
|
|
+ raw: 'this is a message',
|
|
|
searchWords: [] as string[],
|
|
|
- timeEpochMs: 1559038518831,
|
|
|
+ timeEpochMs: 100,
|
|
|
timeFromNow: 'fromNow() jest mocked',
|
|
|
timeLocal: 'format() jest mocked',
|
|
|
timeUtc: 'format() jest mocked',
|
|
|
- timestamp: 1559038518831,
|
|
|
+ timestamp: 100,
|
|
|
uniqueLabels: {},
|
|
|
},
|
|
|
],
|
|
|
@@ -202,7 +194,7 @@ describe('ResultProcessor', () => {
|
|
|
{
|
|
|
label: 'A-series',
|
|
|
color: '#7EB26D',
|
|
|
- data: [[1559038518831, 39.91264531864214], [1559038519831, 40.35179822906545]],
|
|
|
+ data: [[100, 4], [200, 5], [300, 6]],
|
|
|
info: undefined,
|
|
|
isVisible: true,
|
|
|
yAxis: {
|
|
|
@@ -216,84 +208,6 @@ describe('ResultProcessor', () => {
|
|
|
});
|
|
|
|
|
|
describe('constructed with result that is a DataQueryResponse and merging with previous results', () => {
|
|
|
- describe('when calling getRawData', () => {
|
|
|
- it('then it should return result.data', () => {
|
|
|
- const { result, resultProcessor } = testContext();
|
|
|
- const theResult = resultProcessor.getRawData();
|
|
|
-
|
|
|
- expect(theResult).toEqual(result.data);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('when calling getGraphResult', () => {
|
|
|
- it('then it should return correct graph result', () => {
|
|
|
- const { resultProcessor } = testContext({
|
|
|
- replacePreviousResults: false,
|
|
|
- graphResult: [
|
|
|
- {
|
|
|
- label: 'A-series',
|
|
|
- color: '#7EB26D',
|
|
|
- data: [[1558038518831, 19.91264531864214], [1558038518831, 20.35179822906545]],
|
|
|
- info: undefined,
|
|
|
- isVisible: true,
|
|
|
- yAxis: {
|
|
|
- index: 1,
|
|
|
- },
|
|
|
- },
|
|
|
- ],
|
|
|
- });
|
|
|
- const theResult = resultProcessor.getGraphResult();
|
|
|
-
|
|
|
- expect(theResult).toEqual([
|
|
|
- {
|
|
|
- label: 'A-series',
|
|
|
- color: '#7EB26D',
|
|
|
- data: [
|
|
|
- [1558038518831, 19.91264531864214],
|
|
|
- [1558038518831, 20.35179822906545],
|
|
|
- [1559038518831, 39.91264531864214],
|
|
|
- [1559038519831, 40.35179822906545],
|
|
|
- ],
|
|
|
- info: undefined,
|
|
|
- isVisible: true,
|
|
|
- yAxis: {
|
|
|
- index: 1,
|
|
|
- },
|
|
|
- },
|
|
|
- ]);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('when calling getTableResult', () => {
|
|
|
- it('then it should return correct table result', () => {
|
|
|
- const { resultProcessor } = testContext({
|
|
|
- replacePreviousResults: false,
|
|
|
- tableResult: {
|
|
|
- columnMap: {},
|
|
|
- columns: [{ text: 'Time' }, { text: 'Message' }, { text: 'Description' }, { text: 'Value' }],
|
|
|
- rows: [
|
|
|
- [1558038518831, 'This is a previous message 1', 'Previous Description 1', 21.1],
|
|
|
- [1558038519831, 'This is a previous message 2', 'Previous Description 2', 22.1],
|
|
|
- ],
|
|
|
- type: 'table',
|
|
|
- },
|
|
|
- });
|
|
|
- const theResult = resultProcessor.getTableResult();
|
|
|
-
|
|
|
- expect(theResult).toEqual({
|
|
|
- columnMap: {},
|
|
|
- columns: [{ text: 'Time' }, { text: 'Message' }, { text: 'Description' }, { text: 'Value' }],
|
|
|
- rows: [
|
|
|
- [1558038518831, 'This is a previous message 1', 'Previous Description 1', 21.1],
|
|
|
- [1558038519831, 'This is a previous message 2', 'Previous Description 2', 22.1],
|
|
|
- [1559038518831, 'This is a message', 'Description', 23.1],
|
|
|
- [1559038519831, 'This is a message', 'Description', 23.1],
|
|
|
- ],
|
|
|
- type: 'table',
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
describe('when calling getLogsResult', () => {
|
|
|
it('then it should return correct logs result', () => {
|
|
|
const { resultProcessor } = testContext({
|
|
|
@@ -348,6 +262,7 @@ describe('ResultProcessor', () => {
|
|
|
],
|
|
|
},
|
|
|
});
|
|
|
+
|
|
|
const theResult = resultProcessor.getLogsResult();
|
|
|
const expected = {
|
|
|
hasUniqueLabels: false,
|
|
|
@@ -384,33 +299,48 @@ describe('ResultProcessor', () => {
|
|
|
uniqueLabels: {},
|
|
|
},
|
|
|
{
|
|
|
- entry: 'This is a message',
|
|
|
+ entry: 'third',
|
|
|
+ fresh: true,
|
|
|
+ hasAnsi: false,
|
|
|
+ labels: undefined,
|
|
|
+ logLevel: 'unknown',
|
|
|
+ raw: 'third',
|
|
|
+ searchWords: [] as string[],
|
|
|
+ timeEpochMs: 300,
|
|
|
+ timeFromNow: 'fromNow() jest mocked',
|
|
|
+ timeLocal: 'format() jest mocked',
|
|
|
+ timeUtc: 'format() jest mocked',
|
|
|
+ timestamp: 300,
|
|
|
+ uniqueLabels: {},
|
|
|
+ },
|
|
|
+ {
|
|
|
+ entry: 'second message',
|
|
|
fresh: true,
|
|
|
hasAnsi: false,
|
|
|
labels: undefined,
|
|
|
logLevel: 'unknown',
|
|
|
- raw: 'This is a message',
|
|
|
+ raw: 'second message',
|
|
|
searchWords: [] as string[],
|
|
|
- timeEpochMs: 1559038519831,
|
|
|
+ timeEpochMs: 200,
|
|
|
timeFromNow: 'fromNow() jest mocked',
|
|
|
timeLocal: 'format() jest mocked',
|
|
|
timeUtc: 'format() jest mocked',
|
|
|
- timestamp: 1559038519831,
|
|
|
+ timestamp: 200,
|
|
|
uniqueLabels: {},
|
|
|
},
|
|
|
{
|
|
|
- entry: 'This is a message',
|
|
|
+ entry: 'this is a message',
|
|
|
fresh: true,
|
|
|
hasAnsi: false,
|
|
|
labels: undefined,
|
|
|
logLevel: 'unknown',
|
|
|
- raw: 'This is a message',
|
|
|
+ raw: 'this is a message',
|
|
|
searchWords: [] as string[],
|
|
|
- timeEpochMs: 1559038518831,
|
|
|
+ timeEpochMs: 100,
|
|
|
timeFromNow: 'fromNow() jest mocked',
|
|
|
timeLocal: 'format() jest mocked',
|
|
|
timeUtc: 'format() jest mocked',
|
|
|
- timestamp: 1559038518831,
|
|
|
+ timestamp: 100,
|
|
|
uniqueLabels: {},
|
|
|
},
|
|
|
],
|
|
|
@@ -418,12 +348,7 @@ describe('ResultProcessor', () => {
|
|
|
{
|
|
|
label: 'A-series',
|
|
|
color: '#7EB26D',
|
|
|
- data: [
|
|
|
- [1558038518831, 37.91264531864214],
|
|
|
- [1558038519831, 38.35179822906545],
|
|
|
- [1559038518831, 39.91264531864214],
|
|
|
- [1559038519831, 40.35179822906545],
|
|
|
- ],
|
|
|
+ data: [[100, 4], [200, 5], [300, 6]],
|
|
|
info: undefined,
|
|
|
isVisible: true,
|
|
|
yAxis: {
|