mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: Generate log row uid (#18994)
This commit is contained in:
@@ -1,26 +1,29 @@
|
||||
import { logStreamToDataFrame } from './result_transformer';
|
||||
import { logStreamToDataFrame, appendResponseToBufferedData } from './result_transformer';
|
||||
import { FieldType, MutableDataFrame } from '@grafana/data';
|
||||
import { LokiLogsStream } from './types';
|
||||
|
||||
describe('convert loki response to DataFrame', () => {
|
||||
const streams = [
|
||||
{
|
||||
labels: '{foo="bar"}',
|
||||
entries: [
|
||||
{
|
||||
line: "foo: [32m'bar'[39m",
|
||||
ts: '1970-01-01T00:00:00Z',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
labels: '{bar="foo"}',
|
||||
entries: [
|
||||
{
|
||||
line: "bar: 'foo'",
|
||||
ts: '1970-01-01T00:00:00Z',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
const streams: LokiLogsStream[] = [
|
||||
{
|
||||
labels: '{foo="bar"}',
|
||||
entries: [
|
||||
{
|
||||
line: "foo: [32m'bar'[39m",
|
||||
ts: '1970-01-01T00:00:00Z',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
labels: '{bar="foo"}',
|
||||
entries: [
|
||||
{
|
||||
line: "bar: 'foo'",
|
||||
ts: '1970-01-01T00:00:00Z',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
describe('logStreamToDataFrame', () => {
|
||||
it('converts streams to series', () => {
|
||||
const data = streams.map(stream => logStreamToDataFrame(stream));
|
||||
|
||||
@@ -28,7 +31,27 @@ describe('convert loki response to DataFrame', () => {
|
||||
expect(data[0].labels['foo']).toEqual('bar');
|
||||
expect(data[0].fields[0].values.get(0)).toEqual(streams[0].entries[0].ts);
|
||||
expect(data[0].fields[1].values.get(0)).toEqual(streams[0].entries[0].line);
|
||||
expect(data[0].fields[2].values.get(0)).toEqual('1970-01-01T00:00:00Z_{foo="bar"}');
|
||||
expect(data[1].fields[0].values.get(0)).toEqual(streams[1].entries[0].ts);
|
||||
expect(data[1].fields[1].values.get(0)).toEqual(streams[1].entries[0].line);
|
||||
expect(data[1].fields[2].values.get(0)).toEqual('1970-01-01T00:00:00Z_{bar="foo"}');
|
||||
});
|
||||
});
|
||||
|
||||
describe('appendResponseToBufferedData', () => {
|
||||
it('appends response', () => {
|
||||
const data = new MutableDataFrame();
|
||||
data.addField({ name: 'ts', type: FieldType.time, config: { title: 'Time' } });
|
||||
data.addField({ name: 'line', type: FieldType.string });
|
||||
data.addField({ name: 'labels', type: FieldType.other });
|
||||
data.addField({ name: 'id', type: FieldType.string });
|
||||
|
||||
appendResponseToBufferedData({ streams }, data);
|
||||
expect(data.get(0)).toEqual({
|
||||
ts: '1970-01-01T00:00:00Z',
|
||||
line: "foo: [32m'bar'[39m",
|
||||
labels: { foo: 'bar' },
|
||||
id: '1970-01-01T00:00:00Z_{foo="bar"}',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user