[release-12.2.1] TimeSeries: Fix memory leak with boolean fields (#112290)
TimeSeries: Fix memory leak with boolean fields (#112252)
(cherry picked from commit 248c20a6b6)
Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
Co-authored-by: Paul Marbach <paul.marbach@grafana.com>
This commit is contained in:
co-authored by
Leon Sorokin
Paul Marbach
parent
664a91dc84
commit
9bb79a0e8e
@@ -1,4 +1,5 @@
|
|||||||
import { createTheme, FieldType, createDataFrame, toDataFrame } from '@grafana/data';
|
import { createTheme, FieldType, createDataFrame, toDataFrame } from '@grafana/data';
|
||||||
|
import { LineInterpolation } from '@grafana/ui';
|
||||||
|
|
||||||
import { prepareGraphableFields } from './utils';
|
import { prepareGraphableFields } from './utils';
|
||||||
|
|
||||||
@@ -142,4 +143,39 @@ describe('prepare timeseries graph', () => {
|
|||||||
`);
|
`);
|
||||||
expect(frames![0].length).toEqual(6);
|
expect(frames![0].length).toEqual(6);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('boolean fields', () => {
|
||||||
|
it('will set line interpolation to an appropriate mode for boolean fields', () => {
|
||||||
|
const df = createDataFrame({
|
||||||
|
fields: [
|
||||||
|
{ name: 'time', type: FieldType.time, values: [1, 2, 3] },
|
||||||
|
{ name: 'a', type: FieldType.boolean, values: [true, false, true] },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const frames = prepareGraphableFields([df], createTheme());
|
||||||
|
const field = frames![0].fields.find((f) => f.name === 'a');
|
||||||
|
expect(field?.config.custom.lineInterpolation).toEqual(LineInterpolation.StepAfter);
|
||||||
|
expect(df.fields[1].config?.custom).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
// #112194 - mutating this value directly can cause a memory leak
|
||||||
|
it('does not mutate the underlying lineInterpolation value', () => {
|
||||||
|
const df = createDataFrame({
|
||||||
|
fields: [
|
||||||
|
{ name: 'time', type: FieldType.time, values: [1, 2, 3] },
|
||||||
|
{
|
||||||
|
name: 'a',
|
||||||
|
type: FieldType.boolean,
|
||||||
|
values: [true, false, true],
|
||||||
|
config: { custom: { lineInterpolation: LineInterpolation.Smooth } },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const frames = prepareGraphableFields([df], createTheme());
|
||||||
|
expect(df.fields[1].config.custom.lineInterpolation).toEqual(LineInterpolation.Smooth);
|
||||||
|
expect(frames![0].fields[1].config.custom.lineInterpolation).toEqual(LineInterpolation.StepAfter);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -176,12 +176,12 @@ export function prepareGraphableFields(
|
|||||||
...field.config,
|
...field.config,
|
||||||
max: 1,
|
max: 1,
|
||||||
min: 0,
|
min: 0,
|
||||||
custom,
|
custom: { ...custom },
|
||||||
};
|
};
|
||||||
|
|
||||||
// smooth and linear do not make sense
|
// smooth and linear do not make sense
|
||||||
if (custom.lineInterpolation !== LineInterpolation.StepBefore) {
|
if (config.custom.lineInterpolation !== LineInterpolation.StepBefore) {
|
||||||
custom.lineInterpolation = LineInterpolation.StepAfter;
|
config.custom.lineInterpolation = LineInterpolation.StepAfter;
|
||||||
}
|
}
|
||||||
|
|
||||||
copy = {
|
copy = {
|
||||||
|
|||||||
Reference in New Issue
Block a user