Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow templated legend via attribute keys and values from query results #57

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

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

149 changes: 148 additions & 1 deletion src/preprocessors/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`preprocesses logs successfully 1`] = `
exports[`logs preprocesses successfully 1`] = `
{
"fields": [
{
Expand Down Expand Up @@ -91,3 +91,150 @@ exports[`preprocesses logs successfully 1`] = `
"refId": "a",
}
`;

exports[`preprocesses Timeseries successfully should set displayNameDS with legend formatter 1`] = `
{
"fields": [
{
"config": {},
"labels": undefined,
"name": "Time",
"type": "time",
"values": [
0,
1,
2,
],
},
{
"config": {
"displayNameFromDS": "/get",
"links": [
{
"targetBlank": true,
"title": "Create a Notebook in Lightstep",
"url": "https://notebooks",
},
],
},
"labels": {
"operation": "/get",
},
"name": "Value",
"type": "number",
"values": [
1,
7,
1,
],
},
{
"config": {
"displayNameFromDS": "/load",
"links": [
{
"targetBlank": true,
"title": "Create a Notebook in Lightstep",
"url": "https://notebooks",
},
],
},
"labels": {
"operation": "/load",
},
"name": "Value",
"type": "number",
"values": [
6,
5,
9,
],
},
],
"meta": undefined,
"name": undefined,
"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,
}
`;

exports[`preprocesses Timeseries successfully should work if there are no labels and no legend 1`] = `
{
"fields": [
{
"config": {},
"labels": undefined,
"name": "Time",
"type": "time",
"values": [
0,
1,
2,
],
},
{
"config": {
"displayNameFromDS": "",
"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,
}
`;
143 changes: 108 additions & 35 deletions src/preprocessors/index.test.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,118 @@
import { preprocessData } from './index';

test('preprocesses logs successfully', () => {
const logsDataFrame = preprocessData(
{
data: {
attributes: {
logs: [
[
1691409972788,
{
event: 'one',
severity: 'ErrorSeverity',
tags: {
'http.status_code': 200,
large_batch: true,
trace_id: 'd29a3fa8fb446ec65eb691a3259a541e',
describe('logs', () => {
it('preprocesses successfully', () => {
const logsDataFrame = preprocessData(
{
data: {
attributes: {
logs: [
[
1691409972788,
{
event: 'one',
severity: 'ErrorSeverity',
tags: {
'http.status_code': 200,
large_batch: true,
trace_id: 'd29a3fa8fb446ec65eb691a3259a541e',
},
},
},
],
[
1691409971908,
{
event: 'two',
severity: 'InfoSeverity',
tags: {
customer: 'hipcore',
large_batch: false,
trace_id: 'd0fa420269652931236c94bc54d2233e',
],
[
1691409971908,
{
event: 'two',
severity: 'InfoSeverity',
tags: {
customer: 'hipcore',
large_batch: false,
trace_id: 'd0fa420269652931236c94bc54d2233e',
},
k8s_environment: 'production',
k8s_namespace: 'default',
k8s_pod: 'hipcore-pod',
},
k8s_environment: 'production',
k8s_namespace: 'default',
k8s_pod: 'hipcore-pod',
},
],
],
},
},
},
{ refId: 'a' },
''
);

expect(logsDataFrame.toJSON()).toMatchSnapshot();
});
});

describe('preprocesses Timeseries successfully', () => {
it('should set displayNameDS with legend formatter', () => {
const res = {
data: {
attributes: {
series: [
{
'group-labels': ['operation=/get'],
points: [
[0, 1],
[1, 7],
[2, 1],
],
},
{
'group-labels': ['operation=/load'],
points: [
[0, 6],
[1, 5],
[2, 9],
],
},
],
},
},
},
{ refId: 'a' },
''
);
};
const query = { projectName: 'demo', format: '{{operation}}' };
expect(preprocessData(res, query, 'https://notebooks')).toMatchSnapshot();
});

expect(logsDataFrame.toJSON()).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();
});

it('should work if there are no labels and no legend', () => {
const res = {
data: {
attributes: {
series: [
{
points: [
[0, 1],
[1, 7],
[2, 1],
],
},
],
},
},
};
const query = { projectName: 'demo', format: undefined };
expect(preprocessData(res, query, 'https://notebooks')).toMatchSnapshot();
});
});
Loading
Loading