[v9.4.x] SQL Datasources: Prevent Call Stack Overflows with Large Numbers of Values for Variable (#65182)
SQL Datasources: Prevent Call Stack Overflows with Large Numbers of Values for Variable (#64937)
* Push values with every map call to avoid hitting the maximum call stack size.
* Add test and refactor to for of
* Use native fill instead of lodash
---------
Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
(cherry picked from commit bf687fff45)
Co-authored-by: Kyle Cunningham <codeincarnate@users.noreply.github.com>
This commit is contained in:
co-authored by
Kyle Cunningham
parent
721605af13
commit
b1c73a9984
@@ -0,0 +1,23 @@
|
|||||||
|
import { DataFrameDTO, FieldType, MutableDataFrame } from '@grafana/data';
|
||||||
|
|
||||||
|
import { ResponseParser } from './ResponseParser';
|
||||||
|
|
||||||
|
describe('transformMetricFindResponse function', () => {
|
||||||
|
it('should handle big arrays', () => {
|
||||||
|
const responseParser = new ResponseParser();
|
||||||
|
const stringValues = new Array(150_000).fill('a');
|
||||||
|
const numberValues = new Array(150_000).fill(1);
|
||||||
|
|
||||||
|
const frame: DataFrameDTO = {
|
||||||
|
fields: [
|
||||||
|
{ name: 'name', type: FieldType.string, values: stringValues },
|
||||||
|
{ name: 'value', type: FieldType.number, values: numberValues },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const dataFrame = new MutableDataFrame(frame);
|
||||||
|
const result = responseParser.transformMetricFindResponse(dataFrame);
|
||||||
|
|
||||||
|
expect(result).toHaveLength(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -14,13 +14,11 @@ export class ResponseParser implements ResponseParserType {
|
|||||||
values.push({ text: '' + textField.values.get(i), value: '' + valueField.values.get(i) });
|
values.push({ text: '' + textField.values.get(i), value: '' + valueField.values.get(i) });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
values.push(
|
for (const field of frame.fields) {
|
||||||
...frame.fields
|
for (const value of field.values.toArray()) {
|
||||||
.flatMap((f) => f.values.toArray())
|
values.push({ text: value });
|
||||||
.map((v) => ({
|
}
|
||||||
text: v,
|
}
|
||||||
}))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return uniqBy(values, 'text');
|
return uniqBy(values, 'text');
|
||||||
|
|||||||
Reference in New Issue
Block a user