Skip to content

Commit

Permalink
Removed lodash; Add test for no groups
Browse files Browse the repository at this point in the history
  • Loading branch information
heidmotron committed Aug 31, 2024
1 parent 051cee3 commit 0759e3f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@lezer/common": "1.1.1",
"@lezer/highlight": "1.2.0",
"@lezer/lr": "1.3.14",
"lodash": "^4.17.21",
"react": "18.2.0",
"react-dom": "18.2.0",
"tslib": "2.5.3"
Expand Down
41 changes: 41 additions & 0 deletions src/preprocessors/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,44 @@ exports[`preprocesses Timeseries successfully should set displayNameDS with lege
"refId": undefined,
}
`;

exports[`preprocesses Timeseries successfully should work if there are no labels 1`] = `
{
"fields": [
{
"config": {},
"labels": undefined,
"name": "Time",
"type": "time",
"values": [
0,
1,
2,
],
},
{
"config": {
"displayNameFromDS": "<undefined>",
"links": [
{
"targetBlank": true,
"title": "Create a Notebook in Lightstep",
"url": "https://notebooks",
},
],
},
"labels": {},
"name": "Value",
"type": "number",
"values": [
1,
7,
1,
],
},
],
"meta": undefined,
"name": undefined,
"refId": undefined,
}
`;
20 changes: 20 additions & 0 deletions src/preprocessors/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,24 @@ describe('preprocesses Timeseries successfully', () => {
const query = { projectName: 'demo', format: '{{operation}}' };
expect(preprocessData(res, query, 'https://notebooks')).toMatchSnapshot();
});

it('should work if there are no labels', () => {
const res = {
data: {
attributes: {
series: [
{
points: [
[0, 1],
[1, 7],
[2, 1],
],
},
],
},
},
};
const query = { projectName: 'demo', format: '{{operation}}' };
expect(preprocessData(res, query, 'https://notebooks')).toMatchSnapshot();
});
});
7 changes: 3 additions & 4 deletions src/preprocessors/timeseries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Field, FieldType, toDataFrame, Labels, TIME_SERIES_VALUE_FIELD_NAME } from '@grafana/data';
import { LightstepQuery, QueryTimeseriesRes } from '../types';
import { template } from 'lodash';


/**
* Response pre-processor that converts the LS response data into Grafana wide
Expand Down Expand Up @@ -69,7 +67,7 @@ export function preprocessTimeseries(res: QueryTimeseriesRes, query: LightstepQu
});
}

const labels: Labels = transformLabels(s['group-labels']);
const labels: Labels = transformLabels(s['group-labels'] || []);

dataFrameFields.push({
name: TIME_SERIES_VALUE_FIELD_NAME,
Expand Down Expand Up @@ -143,5 +141,6 @@ export function createTimestampMap(timestamps: number[]): Map<number, number> {

// TODO: remove when Grafana 10 is the minimum supported version
function legenedFormatter(legend: string, labels: Labels) {
return template(legend, {interpolate: /{{([\s\S]+?)}}/g})(labels);
const aliasRegex = /\{\{\s*(.+?)\s*\}\}/g;
return legend.replace(aliasRegex, (_, group) => (labels[group] ? labels[group] : "<undefined>"));
}

0 comments on commit 0759e3f

Please sign in to comment.