-
Notifications
You must be signed in to change notification settings - Fork 17
feat: render per component memory consumption #1574
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
37ee90d
feat: prototype
astandrik 8ce3539
feat: better code
astandrik aca9e7f
fix: colors
astandrik 37e2814
fix: issues
astandrik d640d1b
Merge branch 'main' into astandrik.component-memory-consumption-1177
astandrik d211fff
fix: stylelint fix
astandrik bcba055
fix: Detailed memory
astandrik 2bcdd1b
fix: fix tests
astandrik 3b55c19
Merge branch 'main' into astandrik.component-memory-consumption-1177
astandrik 638fa69
fix: other memory
astandrik 8404336
fix: lower precision
astandrik 570f883
fix: rm precision
astandrik dfdfa28
Revert "fix: rm precision"
astandrik 6ec9842
Revert "Revert "fix: rm precision""
astandrik 45041ca
fix: review fixes
astandrik 4595c07
fix: min visible share
astandrik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| @import '../../styles/mixins.scss'; | ||
|
|
||
| $memory-type-colors: ( | ||
| 'AllocatorCachesMemory': var(--g-color-base-utility-medium-hover), | ||
| 'SharedCacheConsumption': var(--g-color-base-info-medium-hover), | ||
| 'MemTableConsumption': var(--g-color-base-warning-medium-hover), | ||
| 'QueryExecutionConsumption': var(--g-color-base-positive-medium-hover), | ||
| 'Other': var(--g-color-base-neutral-light-hover), | ||
| ); | ||
|
|
||
| @mixin memory-type-color($type) { | ||
| background-color: map-get($memory-type-colors, $type); | ||
| } | ||
|
|
||
| .memory-viewer { | ||
| $block: &; | ||
|
|
||
| position: relative; | ||
| z-index: 0; | ||
|
|
||
| min-width: 150px; | ||
| padding: 0 var(--g-spacing-1); | ||
|
|
||
| &__progress-container { | ||
| position: relative; | ||
|
|
||
| overflow: hidden; | ||
|
|
||
| height: 20px; | ||
|
|
||
| border-radius: 2px; | ||
| background: var(--g-color-base-generic); | ||
| } | ||
|
|
||
| &__container { | ||
| display: flex; | ||
|
|
||
| padding: 2px 0; | ||
| } | ||
|
|
||
| &__legend { | ||
| position: absolute; | ||
| bottom: 2px; | ||
|
|
||
| width: 20px; | ||
| height: 20px; | ||
|
|
||
| border-radius: 2px; | ||
|
|
||
| @each $type, $color in $memory-type-colors { | ||
| &_type_#{$type} { | ||
| @include memory-type-color($type); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| &__segment { | ||
| position: absolute; | ||
|
|
||
| height: 100%; | ||
|
|
||
| @each $type, $color in $memory-type-colors { | ||
| &_type_#{$type} { | ||
| @include memory-type-color($type); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| &__name { | ||
| padding-left: 28px; | ||
| } | ||
|
|
||
| &_theme_dark { | ||
| color: var(--g-color-text-light-primary); | ||
|
|
||
| #{$block}__segment { | ||
| opacity: 0.75; | ||
| } | ||
| } | ||
|
|
||
| &_status { | ||
| &_good { | ||
| #{$block}__progress-container { | ||
| background-color: var(--g-color-base-positive-light); | ||
| } | ||
| } | ||
| &_warning { | ||
| #{$block}__progress-container { | ||
| background-color: var(--g-color-base-yellow-light); | ||
| } | ||
| } | ||
| &_danger { | ||
| #{$block}__progress-container { | ||
| background-color: var(--g-color-base-danger-light); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| &__text { | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| import {DefinitionList, useTheme} from '@gravity-ui/uikit'; | ||
|
|
||
| import type {TMemoryStats} from '../../types/api/nodes'; | ||
| import {formatBytes} from '../../utils/bytesParsers'; | ||
| import {cn} from '../../utils/cn'; | ||
| import {GIGABYTE} from '../../utils/constants'; | ||
| import {calculateProgressStatus} from '../../utils/progress'; | ||
| import {isNumeric} from '../../utils/utils'; | ||
| import {HoverPopup} from '../HoverPopup/HoverPopup'; | ||
| import type {FormatProgressViewerValues} from '../ProgressViewer/ProgressViewer'; | ||
| import {ProgressViewer} from '../ProgressViewer/ProgressViewer'; | ||
|
|
||
| import {getMemorySegments} from './utils'; | ||
|
|
||
| import './MemoryViewer.scss'; | ||
|
|
||
| const MIN_VISIBLE_MEMORY_SHARE = 1; | ||
| const MIN_VISIBLE_MEMORY_VALUE = 0.01 * GIGABYTE; | ||
|
|
||
| const b = cn('memory-viewer'); | ||
|
|
||
| const formatDetailedValues: FormatProgressViewerValues = (value, total) => { | ||
| return [ | ||
| formatBytes({ | ||
| value, | ||
| size: 'gb', | ||
| withSizeLabel: false, | ||
| precision: 2, | ||
| }), | ||
| formatBytes({ | ||
| value: total, | ||
| size: 'gb', | ||
| withSizeLabel: true, | ||
| precision: 1, | ||
| }), | ||
| ]; | ||
| }; | ||
|
|
||
| export interface MemoryProgressViewerProps { | ||
| stats: TMemoryStats; | ||
| className?: string; | ||
| warningThreshold?: number; | ||
| value?: number | string; | ||
| capacity?: number | string; | ||
| formatValues: FormatProgressViewerValues; | ||
| percents?: boolean; | ||
| dangerThreshold?: number; | ||
| } | ||
|
|
||
| export function MemoryViewer({ | ||
| stats, | ||
| value, | ||
| capacity, | ||
| percents, | ||
| formatValues, | ||
| className, | ||
| warningThreshold = 60, | ||
| dangerThreshold = 80, | ||
| }: MemoryProgressViewerProps) { | ||
| const theme = useTheme(); | ||
| let fillWidth = | ||
| Math.round((parseFloat(String(value)) / parseFloat(String(capacity))) * 100) || 0; | ||
| fillWidth = fillWidth > 100 ? 100 : fillWidth; | ||
| let valueText: number | string | undefined = value, | ||
| capacityText: number | string | undefined = capacity, | ||
| divider = '/'; | ||
| if (percents) { | ||
| valueText = fillWidth + '%'; | ||
| capacityText = ''; | ||
| divider = ''; | ||
| } else if (formatValues) { | ||
| [valueText, capacityText] = formatValues(Number(value), Number(capacity)); | ||
| } | ||
|
|
||
| const renderContent = () => { | ||
| if (isNumeric(capacity)) { | ||
| return `${valueText} ${divider} ${capacityText}`; | ||
| } | ||
|
|
||
| return valueText; | ||
| }; | ||
|
|
||
| const calculateMemoryShare = (segmentSize: number) => { | ||
| if (!value) { | ||
| return 0; | ||
| } | ||
| return (segmentSize / parseFloat(String(capacity))) * 100; | ||
| }; | ||
|
|
||
| const memorySegments = getMemorySegments(stats); | ||
|
|
||
| const status = calculateProgressStatus({ | ||
| fillWidth, | ||
| warningThreshold, | ||
| dangerThreshold, | ||
| colorizeProgress: true, | ||
| }); | ||
|
|
||
| let currentPosition = 0; | ||
|
|
||
| return ( | ||
| <HoverPopup | ||
| popupContent={ | ||
| <DefinitionList responsive> | ||
| {memorySegments.map( | ||
| ({label, value: segmentSize, capacity: segmentCapacity, key}) => ( | ||
| <DefinitionList.Item | ||
| key={label} | ||
| name={ | ||
| <div className={b('container')}> | ||
| <div className={b('legend', {type: key})}></div> | ||
| <div className={b('name')}>{label}</div> | ||
| </div> | ||
| } | ||
| > | ||
| {segmentCapacity ? ( | ||
| <ProgressViewer | ||
| value={segmentSize} | ||
| capacity={segmentCapacity} | ||
| formatValues={formatDetailedValues} | ||
| colorizeProgress | ||
| /> | ||
| ) : ( | ||
| formatBytes({ | ||
| value: segmentSize, | ||
| size: 'gb', | ||
| withSizeLabel: true, | ||
| precision: 2, | ||
| }) | ||
| )} | ||
| </DefinitionList.Item> | ||
| ), | ||
| )} | ||
| </DefinitionList> | ||
| } | ||
| > | ||
| <div className={b({theme, status}, className)}> | ||
| <div className={b('progress-container')}> | ||
| {memorySegments | ||
| .filter(({isInfo}) => !isInfo) | ||
| .map((segment) => { | ||
| if (segment.value < MIN_VISIBLE_MEMORY_VALUE) { | ||
| return null; | ||
| } | ||
|
|
||
| const currentMemoryShare = Math.max( | ||
| calculateMemoryShare(segment.value), | ||
| MIN_VISIBLE_MEMORY_SHARE, | ||
| ); | ||
| const position = currentPosition; | ||
| currentPosition += currentMemoryShare; | ||
|
|
||
| return ( | ||
| <div | ||
| key={segment.key} | ||
| className={b('segment', {type: segment.key})} | ||
| style={{ | ||
| width: `${currentMemoryShare}%`, | ||
| left: `${position}%`, | ||
| }} | ||
| /> | ||
| ); | ||
| })} | ||
| <div className={b('text')}>{renderContent()}</div> | ||
| </div> | ||
| </div> | ||
| </HoverPopup> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "text_external-consumption": "External Consumption", | ||
| "text_allocator-caches": "Allocator Caches", | ||
| "text_shared-cache": "Shared Cache", | ||
| "text_memtable": "MemTable", | ||
| "text_query-execution": "Query Execution", | ||
| "text_usage": "Usage", | ||
| "text_soft-limit": "Soft Limit", | ||
| "text_hard-limit": "Hard Limit", | ||
| "text_other": "Other" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import {registerKeysets} from '../../../utils/i18n'; | ||
|
|
||
| import en from './en.json'; | ||
|
|
||
| const COMPONENT = 'ydb-memory-viewer'; | ||
|
|
||
| export default registerKeysets(COMPONENT, {en}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import type {TMemoryStats} from '../../types/api/nodes'; | ||
| import {isNumeric} from '../../utils/utils'; | ||
|
|
||
| import i18n from './i18n'; | ||
|
|
||
| function getMaybeNumber(value: string | number | undefined): number | undefined { | ||
| return isNumeric(value) ? parseFloat(String(value)) : undefined; | ||
| } | ||
|
|
||
| interface MemorySegment { | ||
| label: string; | ||
| key: string; | ||
| value: number; | ||
| capacity?: number; | ||
| isInfo?: boolean; | ||
| } | ||
|
|
||
| export function getMemorySegments(stats: TMemoryStats): MemorySegment[] { | ||
| const segments = [ | ||
| { | ||
| label: i18n('text_shared-cache'), | ||
| key: 'SharedCacheConsumption', | ||
| value: getMaybeNumber(stats.SharedCacheConsumption), | ||
| capacity: getMaybeNumber(stats.SharedCacheLimit), | ||
| isInfo: false, | ||
| }, | ||
| { | ||
| label: i18n('text_query-execution'), | ||
| key: 'QueryExecutionConsumption', | ||
| value: getMaybeNumber(stats.QueryExecutionConsumption), | ||
| capacity: getMaybeNumber(stats.QueryExecutionLimit), | ||
| isInfo: false, | ||
| }, | ||
| { | ||
| label: i18n('text_memtable'), | ||
| key: 'MemTableConsumption', | ||
| value: getMaybeNumber(stats.MemTableConsumption), | ||
| capacity: getMaybeNumber(stats.MemTableLimit), | ||
| isInfo: false, | ||
| }, | ||
| { | ||
| label: i18n('text_allocator-caches'), | ||
| key: 'AllocatorCachesMemory', | ||
| value: getMaybeNumber(stats.AllocatorCachesMemory), | ||
| isInfo: false, | ||
| }, | ||
| ]; | ||
|
|
||
| const nonInfoSegments = segments.filter( | ||
| (segment) => segment.value !== undefined, | ||
| ) as MemorySegment[]; | ||
| const sumNonInfoSegments = nonInfoSegments.reduce((acc, segment) => acc + segment.value, 0); | ||
|
|
||
| const totalMemory = getMaybeNumber(stats.AnonRss); | ||
|
|
||
| if (totalMemory) { | ||
| const otherMemory = Math.max(0, totalMemory - sumNonInfoSegments); | ||
|
|
||
| segments.push({ | ||
| label: i18n('text_other'), | ||
| key: 'Other', | ||
| value: otherMemory, | ||
| isInfo: false, | ||
| }); | ||
| } | ||
|
|
||
| segments.push( | ||
| { | ||
| label: i18n('text_external-consumption'), | ||
| key: 'ExternalConsumption', | ||
| value: getMaybeNumber(stats.ExternalConsumption), | ||
| isInfo: true, | ||
| }, | ||
| { | ||
| label: i18n('text_usage'), | ||
| key: 'Usage', | ||
| value: getMaybeNumber(stats.AnonRss), | ||
| isInfo: true, | ||
| }, | ||
| { | ||
| label: i18n('text_soft-limit'), | ||
| key: 'SoftLimit', | ||
| value: getMaybeNumber(stats.SoftLimit), | ||
| isInfo: true, | ||
| }, | ||
| { | ||
| label: i18n('text_hard-limit'), | ||
| key: 'HardLimit', | ||
| value: getMaybeNumber(stats.HardLimit), | ||
| isInfo: true, | ||
| }, | ||
| ); | ||
|
|
||
| return segments.filter((segment) => segment.value !== undefined) as MemorySegment[]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.