NodeGraph: Fix error when rendering in dashboards (#34187)

* Pass only serializable values to worker

* Fix random generated data frame
This commit is contained in:
Andrej Ocenas 2021-05-17 13:20:49 +02:00 committed by GitHub
parent d5ae55c5dd
commit bc4ec61f67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 8 deletions

View File

@ -1,4 +1,11 @@
import { ArrayVector, FieldType, MutableDataFrame, NodeGraphDataFrameFieldNames } from '@grafana/data';
import {
ArrayVector,
FieldColorModeId,
FieldDTO,
FieldType,
MutableDataFrame,
NodeGraphDataFrameFieldNames,
} from '@grafana/data';
import { nodes, edges } from './testData/serviceMapResponse';
export function generateRandomNodes(count = 10) {
@ -43,7 +50,7 @@ export function generateRandomNodes(count = 10) {
nodes[sourceIndex].edges.push(nodes[sourceIndex].id);
}
const nodeFields: any = {
const nodeFields: Record<string, Omit<FieldDTO, 'name'> & { values: ArrayVector }> = {
[NodeGraphDataFrameFieldNames.id]: {
values: new ArrayVector(),
type: FieldType.string,
@ -59,20 +66,22 @@ export function generateRandomNodes(count = 10) {
[NodeGraphDataFrameFieldNames.mainStat]: {
values: new ArrayVector(),
type: FieldType.number,
config: { displayName: 'Transactions per second' },
},
[NodeGraphDataFrameFieldNames.secondaryStat]: {
values: new ArrayVector(),
type: FieldType.number,
config: { displayName: 'Average duration' },
},
[NodeGraphDataFrameFieldNames.arc + 'success']: {
values: new ArrayVector(),
type: FieldType.number,
config: { color: { fixedColor: 'green' } },
config: { color: { fixedColor: 'green', mode: FieldColorModeId.Fixed }, displayName: 'Success' },
},
[NodeGraphDataFrameFieldNames.arc + 'errors']: {
values: new ArrayVector(),
type: FieldType.number,
config: { color: { fixedColor: 'red' } },
config: { color: { fixedColor: 'red', mode: FieldColorModeId.Fixed }, displayName: 'Errors' },
},
};

View File

@ -137,16 +137,21 @@ function defaultLayout(
for (let i = 0; i < nodes.length; i++) {
// These stats needs to be Field class but the data is stringified over the worker boundary
event.data.nodes[i] = {
...nodes[i],
...event.data.nodes[i],
mainStat: nodes[i].mainStat,
secondaryStat: nodes[i].secondaryStat,
arcSections: nodes[i].arcSections,
};
}
done(event.data);
};
worker.postMessage({ nodes, edges, config: defaultConfig });
worker.postMessage({
nodes: nodes.map((n) => ({
id: n.id,
incoming: n.incoming,
})),
edges,
config: defaultConfig,
});
}
/**