Skip to content

Commit

Permalink
Allow templated legend via attribute keys and values from query resul…
Browse files Browse the repository at this point in the history
…ts (#57)

A few changes were made to the Time Series Value fields:
- Labels are appended to the field it self. This will use default formatting and removes the need for our createFieldName function.
- Name is changed to use the TIME_SERIES_VALUE_FIELD which has logic to remove the name if there is no displayNameFromDS set and use default label formatting.
- Query Name allows for variable names in simple mustache like syntax {{var1}} which is similar to the Prometheus / Loki datasource
- If an attribute value doesn't exist in the results set, then the value will be set to <undefined>
  • Loading branch information
heidmotron authored Sep 4, 2024
1 parent 7219563 commit d6b5ede
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 158 deletions.
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

0 comments on commit d6b5ede

Please sign in to comment.