TEMPORARY: introduce a breaking change in @grafana/data

This commit is contained in:
Levente Balogh 2021-12-14 14:48:50 +01:00
parent d82d88f840
commit 986ac9ab82
3 changed files with 7 additions and 5 deletions

View File

@ -3,12 +3,12 @@ import { Labels } from '../types/data';
describe('parseLabels()', () => {
it('returns no labels on empty labels string', () => {
expect(parseLabels('')).toEqual({});
expect(parseLabels('{}')).toEqual({});
expect(parseLabels('', 'Foo')).toEqual({});
expect(parseLabels('{}', 'Foo')).toEqual({});
});
it('returns labels on labels string', () => {
expect(parseLabels('{foo="bar", baz="42"}')).toEqual({ foo: 'bar', baz: '42' });
expect(parseLabels('{foo="bar", baz="42"}', 'Foo')).toEqual({ foo: 'bar', baz: '42' });
});
});

View File

@ -10,7 +10,9 @@ const labelRegexp = /\b(\w+)(!?=~?)"([^"\n]*?)"/g;
*
* Example: `parseLabels('{job="foo", instance="bar"}) // {job: "foo", instance: "bar"}`
*/
export function parseLabels(labels: string): Labels {
export function parseLabels(labels: string, foo: string): Labels {
console.log(foo);
const labelsByKey: Labels = {};
labels.replace(labelRegexp, (_, key, operator, value) => {
labelsByKey[key] = value;

View File

@ -32,7 +32,7 @@ export class LiveStreams {
const data = new CircularDataFrame({ capacity: target.size });
data.addField({ name: 'ts', type: FieldType.time, config: { displayName: 'Time' } });
data.addField({ name: 'tsNs', type: FieldType.time, config: { displayName: 'Time ns' } });
data.addField({ name: 'line', type: FieldType.string }).labels = parseLabels(target.query);
data.addField({ name: 'line', type: FieldType.string }).labels = parseLabels(target.query, 'Foo');
data.addField({ name: 'labels', type: FieldType.other }); // The labels for each line
data.addField({ name: 'id', type: FieldType.string });
data.meta = { ...data.meta, preferredVisualisationType: 'logs' };