-
Notifications
You must be signed in to change notification settings - Fork 13
fix(PDiskSpaceDistribution): update slots severity calculation #1907
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
import type {TPDiskInfoResponse} from '../../../../types/api/pdisk'; | ||
import {preparePDiskDataResponse} from '../utils'; | ||
|
||
describe('preparePDiskDataResponse', () => { | ||
const rawData = { | ||
Whiteboard: { | ||
PDisk: { | ||
PDiskId: 1, | ||
ChangeTime: '1738670321505', | ||
Path: '/ydb_data/pdisk1tmbtrl7c.data', | ||
Guid: '1', | ||
Category: '0', | ||
AvailableSize: '66454552576', | ||
TotalSize: '100000000000', | ||
State: 'Normal', | ||
Device: 'Green', | ||
Realtime: 'Green', | ||
SerialNumber: '', | ||
SystemSize: '2000000000', | ||
LogUsedSize: '2000000000', | ||
LogTotalSize: '60000000000', | ||
EnforcedDynamicSlotSize: '20000000000', | ||
NumActiveSlots: 1, | ||
}, | ||
VDisks: [ | ||
{ | ||
VDiskId: { | ||
GroupID: 2181038081, | ||
GroupGeneration: 1, | ||
Ring: 0, | ||
Domain: 0, | ||
VDisk: 0, | ||
}, | ||
ChangeTime: '1738672482849', | ||
PDiskId: 1, | ||
VDiskSlotId: 1001, | ||
Guid: '1', | ||
Kind: '0', | ||
VDiskState: 'OK', | ||
DiskSpace: 'Green', | ||
SatisfactionRank: { | ||
FreshRank: { | ||
Flag: 'Green', | ||
}, | ||
LevelRank: { | ||
Flag: 'Green', | ||
}, | ||
}, | ||
Replicated: true, | ||
ReplicationProgress: 1, | ||
ReplicationSecondsRemaining: 0, | ||
AllocatedSize: '5000000000', | ||
AvailableSize: '20000000000', | ||
HasUnreadableBlobs: false, | ||
IncarnationGuid: '13331041715376219418', | ||
InstanceGuid: '18177015420302975983', | ||
FrontQueues: 'Green', | ||
StoragePoolName: 'dynamic_storage_pool:1', | ||
ReadThroughput: '0', | ||
WriteThroughput: '0', | ||
}, | ||
], | ||
}, | ||
BSC: { | ||
PDisk: { | ||
Type: 'ROT', | ||
Kind: '0', | ||
Path: '/ydb_data/pdisk1tmbtrl7c.data', | ||
Guid: '1', | ||
BoxId: '1', | ||
SharedWithOs: false, | ||
ReadCentric: false, | ||
AvailableSize: '66454552576', | ||
TotalSize: '68719476736', | ||
StatusV2: 'ACTIVE', | ||
StatusChangeTimestamp: '1737458853219782', | ||
EnforcedDynamicSlotSize: '20000000000', | ||
ExpectedSlotCount: 16, | ||
NumActiveSlots: 1, | ||
Category: '0', | ||
DecommitStatus: 'DECOMMIT_NONE', | ||
State: 'Normal', | ||
}, | ||
VDisks: [ | ||
{ | ||
Key: { | ||
NodeId: 1, | ||
PDiskId: 1, | ||
VSlotId: 0, | ||
}, | ||
Info: { | ||
GroupId: 0, | ||
GroupGeneration: 1, | ||
FailRealm: 0, | ||
FailDomain: 0, | ||
VDisk: 0, | ||
AllocatedSize: '1000000000', | ||
AvailableSize: '20000000000', | ||
StatusV2: 'READY', | ||
Kind: 'Default', | ||
DiskSpace: 'Green', | ||
Replicated: true, | ||
State: 'OK', | ||
}, | ||
}, | ||
], | ||
}, | ||
} as unknown as TPDiskInfoResponse; | ||
|
||
it('Should correctly retrieve slots', () => { | ||
const preparedData = preparePDiskDataResponse([rawData, {}]); | ||
|
||
expect(preparedData.SlotItems?.length).toEqual(17); | ||
expect(preparedData.SlotItems?.filter((slot) => slot.SlotType === 'log').length).toEqual(1); | ||
expect(preparedData.SlotItems?.filter((slot) => slot.SlotType === 'vDisk').length).toEqual( | ||
1, | ||
); | ||
expect(preparedData.SlotItems?.filter((slot) => slot.SlotType === 'empty').length).toEqual( | ||
15, | ||
); | ||
}); | ||
it('Should correctly calculate empty slots size if EnforcedDynamicSlotSize is provided', () => { | ||
const preparedData = preparePDiskDataResponse([rawData, {}]); | ||
|
||
expect(preparedData.SlotItems?.find((slot) => slot.SlotType === 'empty')?.Total).toEqual( | ||
20_000_000_000, | ||
); | ||
}); | ||
it('Should correctly calculate empty slots size if EnforcedDynamicSlotSize is undefined', () => { | ||
const data: TPDiskInfoResponse = { | ||
...rawData, | ||
Whiteboard: { | ||
...rawData.Whiteboard, | ||
PDisk: { | ||
...rawData.Whiteboard?.PDisk, | ||
EnforcedDynamicSlotSize: undefined, | ||
}, | ||
}, | ||
BSC: { | ||
...rawData.BSC, | ||
PDisk: { | ||
...rawData.BSC?.PDisk, | ||
EnforcedDynamicSlotSize: undefined, | ||
}, | ||
}, | ||
}; | ||
const preparedData = preparePDiskDataResponse([data, {}]); | ||
|
||
expect(preparedData.SlotItems?.find((slot) => slot.SlotType === 'empty')?.Total).toEqual( | ||
1_000_000_000, | ||
); | ||
}); | ||
it('Should return yellow or red severity for log if its size exceeds thresholds', () => { | ||
const dataWarning: TPDiskInfoResponse = { | ||
...rawData, | ||
Whiteboard: { | ||
...rawData.Whiteboard, | ||
PDisk: { | ||
...rawData.Whiteboard?.PDisk, | ||
LogUsedSize: '90', | ||
LogTotalSize: '100', | ||
}, | ||
}, | ||
}; | ||
const preparedDataWarning = preparePDiskDataResponse([dataWarning, {}]); | ||
|
||
expect( | ||
preparedDataWarning.SlotItems?.find((slot) => slot.SlotType === 'log')?.Severity, | ||
).toEqual(3); | ||
|
||
const dataDanger: TPDiskInfoResponse = { | ||
...rawData, | ||
Whiteboard: { | ||
...rawData.Whiteboard, | ||
PDisk: { | ||
...rawData.Whiteboard?.PDisk, | ||
LogUsedSize: '99', | ||
LogTotalSize: '100', | ||
}, | ||
}, | ||
}; | ||
const preparedDataDanger = preparePDiskDataResponse([dataDanger, {}]); | ||
|
||
expect( | ||
preparedDataDanger.SlotItems?.find((slot) => slot.SlotType === 'log')?.Severity, | ||
).toEqual(5); | ||
}); | ||
it('Should return yellow or red severity for vdisk if its size exceeds thresholds', () => { | ||
const dataWarning: TPDiskInfoResponse = { | ||
...rawData, | ||
Whiteboard: { | ||
...rawData.Whiteboard, | ||
VDisks: [ | ||
{ | ||
...rawData.Whiteboard?.VDisks?.[0], | ||
AllocatedSize: '90', | ||
AvailableSize: '10', | ||
}, | ||
], | ||
}, | ||
}; | ||
const preparedDataWarning = preparePDiskDataResponse([dataWarning, {}]); | ||
|
||
expect( | ||
preparedDataWarning.SlotItems?.find((slot) => slot.SlotType === 'vDisk')?.Severity, | ||
).toEqual(3); | ||
|
||
const dataDanger: TPDiskInfoResponse = { | ||
...rawData, | ||
Whiteboard: { | ||
...rawData.Whiteboard, | ||
VDisks: [ | ||
{ | ||
...rawData.Whiteboard?.VDisks?.[0], | ||
AllocatedSize: '99', | ||
AvailableSize: '1', | ||
}, | ||
], | ||
}, | ||
}; | ||
const preparedDataDanger = preparePDiskDataResponse([dataDanger, {}]); | ||
|
||
expect( | ||
preparedDataDanger.SlotItems?.find((slot) => slot.SlotType === 'vDisk')?.Severity, | ||
).toEqual(5); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import type {TPDiskInfoResponse} from '../../../types/api/pdisk'; | ||
import type {TEvSystemStateResponse} from '../../../types/api/systemState'; | ||
import {getArray, valueIsDefined} from '../../../utils'; | ||
import {getSpaceSeverity} from '../../../utils/disks/helpers'; | ||
import { | ||
prepareWhiteboardPDiskData, | ||
prepareWhiteboardVDiskData, | ||
|
@@ -34,18 +35,20 @@ export function preparePDiskDataResponse([pdiskResponse = {}, nodeResponse]: [ | |
TotalSize: PDiskTotalSize, | ||
SystemSize, | ||
ExpectedSlotCount, | ||
EnforcedDynamicSlotSize, | ||
SlotSize, | ||
} = preparedPDisk; | ||
|
||
let logSlot: SlotItem<'log'> | undefined; | ||
|
||
if (valueIsDefined(LogTotalSize)) { | ||
const usagePercent = (Number(LogUsedSize) * 100) / Number(LogTotalSize); | ||
|
||
logSlot = { | ||
SlotType: 'log', | ||
Used: Number(LogUsedSize), | ||
Total: Number(LogTotalSize), | ||
UsagePercent: (Number(LogUsedSize) * 100) / Number(LogTotalSize), | ||
Severity: 1, | ||
UsagePercent: usagePercent, | ||
Severity: getSpaceSeverity(usagePercent), | ||
SlotData: { | ||
LogUsedSize, | ||
LogTotalSize, | ||
|
@@ -60,11 +63,19 @@ export function preparePDiskDataResponse([pdiskResponse = {}, nodeResponse]: [ | |
preparedVDisks.sort((disk1, disk2) => Number(disk2.VDiskSlotId) - Number(disk1.VDiskSlotId)); | ||
|
||
const vdisksSlots: SlotItem<'vDisk'>[] = preparedVDisks.map((preparedVDisk) => { | ||
// VDisks do not have strict limits and can be bigger than they should | ||
// In most storage views we don't colorize them depending on space usage | ||
// Colorize them inside PDiskSpaceDistribution so overused slots will be visible | ||
const slotSeverity = Math.max( | ||
getSpaceSeverity(preparedVDisk.AllocatedPercent), | ||
preparedVDisk.Severity || 0, | ||
); | ||
Comment on lines
+69
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't use allocated percent to get vdisks severity inside prepare functions, we use it only here while preparing slots |
||
|
||
return { | ||
SlotType: 'vDisk', | ||
Id: preparedVDisk.VDiskId?.GroupID, | ||
Title: preparedVDisk.StoragePoolName, | ||
Severity: preparedVDisk.Severity, | ||
Severity: slotSeverity, | ||
Used: Number(preparedVDisk.AllocatedSize), | ||
Total: Number(preparedVDisk.TotalSize), | ||
UsagePercent: preparedVDisk.AllocatedPercent, | ||
|
@@ -78,7 +89,7 @@ export function preparePDiskDataResponse([pdiskResponse = {}, nodeResponse]: [ | |
if (ExpectedSlotCount && ExpectedSlotCount > vdisksSlots.length) { | ||
const emptySlotsCount = ExpectedSlotCount - vdisksSlots.length; | ||
|
||
let emptySlotSize = Number(EnforcedDynamicSlotSize); | ||
let emptySlotSize = Number(SlotSize); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a bug, added tests |
||
|
||
if (isNaN(emptySlotSize)) { | ||
const vDisksTotalSize = vdisksSlots.reduce((sum, item) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,7 @@ | ||
import {EFlag} from '../../types/api/enums'; | ||
import type {TPDiskState} from '../../types/api/pdisk'; | ||
import {generateEvaluator} from '../generateEvaluator'; | ||
|
||
import { | ||
DISK_COLOR_STATE_TO_NUMERIC_SEVERITY, | ||
NOT_AVAILABLE_SEVERITY, | ||
PDISK_STATE_SEVERITY, | ||
} from './constants'; | ||
|
||
const getUsageSeverityForPDisk = generateEvaluator([EFlag.Green, EFlag.Yellow, EFlag.Red]); | ||
import {NOT_AVAILABLE_SEVERITY, PDISK_STATE_SEVERITY} from './constants'; | ||
import {getSpaceSeverity} from './helpers'; | ||
|
||
export function calculatePDiskSeverity< | ||
T extends { | ||
|
@@ -17,13 +10,13 @@ export function calculatePDiskSeverity< | |
}, | ||
>(pDisk: T) { | ||
const stateSeverity = getStateSeverity(pDisk.State); | ||
const spaceSeverityFlag = getUsageSeverityForPDisk(pDisk.AllocatedPercent || 0); | ||
const spaceSeverity = getSpaceSeverity(pDisk.AllocatedPercent); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just little refactoring |
||
if (stateSeverity === NOT_AVAILABLE_SEVERITY || !spaceSeverityFlag) { | ||
if (stateSeverity === NOT_AVAILABLE_SEVERITY || !spaceSeverity) { | ||
return stateSeverity; | ||
} | ||
|
||
return Math.max(stateSeverity, DISK_COLOR_STATE_TO_NUMERIC_SEVERITY[spaceSeverityFlag]); | ||
return Math.max(stateSeverity, spaceSeverity); | ||
} | ||
|
||
function getStateSeverity(pDiskState?: TPDiskState) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colorize log just like other slots. For example, if log is 90/100, it should be yellow, if 99/100 - red.