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

adding null check to fix overlapping blocks #7058

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
36 changes: 36 additions & 0 deletions pkg/ui/react-app/src/thanos/pages/blocks/helpers.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { debug } from 'console';
import { BlocksPool, Block } from './block';
import { sortBlocks, isOverlapping, getFilteredBlockPools } from './helpers';

// Number of blocks in data: 8.
Expand Down Expand Up @@ -656,3 +658,37 @@ describe('Filtered block pools', () => {
expect(filteredBlockPoolArray[0].thanos.labels).toEqual(filteredBlocks[0].thanos.labels);
});
});

describe('handle null in blockPool', () => {
const newBlockPools = blockPools;
const poolArrayIndex: BlocksPool = newBlockPools['1'];
const poolArray: Block[][] = poolArrayIndex[Object.keys(poolArrayIndex)[0]];
const undefinedBlock: Block = {
compaction: {
level: null as unknown as number,
sources: [],
parents: [],
},
maxTime: null as unknown as number,
minTime: null as unknown as number,
stats: {
numChunks: null as unknown as number,
numSamples: null as unknown as number,
numSeries: null as unknown as number,
},
thanos: {
downsample: {
resolution: null as unknown as number,
},
labels: {},
source: null as unknown as string,
},
ulid: null as unknown as string,
version: null as unknown as number,
};

poolArray[0][0] = undefinedBlock;
it('should not crash UI', () => {
expect(Object.keys(newBlockPools)).toEqual(Object.keys(blockPools));
});
});
5 changes: 4 additions & 1 deletion pkg/ui/react-app/src/thanos/pages/blocks/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ export const getFilteredBlockPools = (
const poolArrayIndex = blockPools[key];
const poolArray = poolArrayIndex[Object.keys(poolArrayIndex)[0]];
for (let i = 0; i < filteredBlocks.length; i++) {
if (JSON.stringify(filteredBlocks[i].thanos.labels) === JSON.stringify(poolArray[0][0].thanos.labels)) {
if (
poolArray[0][0] &&
JSON.stringify(filteredBlocks[i].thanos.labels) === JSON.stringify(poolArray[0][0].thanos.labels)
) {
Object.assign(newblockPools, { [key]: blockPools[key] });
break;
}
Expand Down