-
Notifications
You must be signed in to change notification settings - Fork 17
feat(Versions): show overall version info in Versions tab #1442
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 3 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 |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| display: flex; | ||
| flex-direction: column; | ||
|
|
||
| width: 600px; | ||
| min-width: 600px; | ||
|
|
||
| & .g-progress { | ||
| width: 100%; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "title_overall": "Overall", | ||
| "title_storage": "Storage nodes", | ||
| "title_database": "Database nodes", | ||
| "title_other": "Other nodes" | ||
| } |
| 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-versions'; | ||
|
|
||
| export default registerKeysets(COMPONENT, {en}); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {skipToken} from '@reduxjs/toolkit/query'; | ||
|
|
||
| import {nodesApi} from '../../store/reducers/nodes/nodes'; | ||
| import {isClusterInfoV2} from '../../types/api/cluster'; | ||
| import type {TClusterInfo} from '../../types/api/cluster'; | ||
| import type {VersionToColorMap} from '../../types/versions'; | ||
| import {parseNodeGroupsToVersionsValues, parseNodesToVersionsValues} from '../../utils/versions'; | ||
|
|
||
| export const useGetVersionValues = (cluster?: TClusterInfo, versionToColor?: VersionToColorMap) => { | ||
| const {currentData} = nodesApi.useGetNodesQuery( | ||
| isClusterInfoV2(cluster) | ||
| ? skipToken | ||
| : { | ||
| tablets: false, | ||
| group: 'Version', | ||
| }, | ||
| ); | ||
|
|
||
| const versionsValues = React.useMemo(() => { | ||
| if (isClusterInfoV2(cluster) && cluster.MapVersions) { | ||
| const groups = Object.entries(cluster.MapVersions).map(([version, count]) => ({ | ||
| name: version, | ||
| count, | ||
| })); | ||
| return parseNodeGroupsToVersionsValues(groups, versionToColor, cluster.NodesTotal); | ||
| } | ||
| if (!currentData) { | ||
| return []; | ||
| } | ||
| if (Array.isArray(currentData.NodeGroups)) { | ||
| return parseNodeGroupsToVersionsValues( | ||
| currentData.NodeGroups, | ||
| versionToColor, | ||
| cluster?.NodesTotal, | ||
| ); | ||
| } | ||
| return parseNodesToVersionsValues(currentData.Nodes, versionToColor); | ||
| }, [currentData, versionToColor, cluster]); | ||
|
|
||
| return versionsValues; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ export const hashCode = (s: string) => { | |
| // TODO: colors used in charts as well, need to move to constants | ||
| // 11 distinct colors from https://mokole.com/palette.html | ||
| export const COLORS = [ | ||
| '#008000', // green | ||
| '#4169e1', // royalblue | ||
| '#ffd700', // gold | ||
| '#ff8c00', // darkorange | ||
|
|
@@ -25,7 +24,7 @@ export const COLORS = [ | |
| '#b22222', // firebrick | ||
| ]; | ||
|
|
||
| export const GREY_COLOR = '#bfbfbf'; | ||
| export const DEFAULT_COLOR = '#008000'; // green | ||
|
Contributor
Author
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. discussed with @adameat and decided to set green color as defaut. |
||
|
|
||
| export const getVersionsMap = (versions: string[], initialMap: VersionsMap = new Map()) => { | ||
| versions.forEach((version) => { | ||
|
|
@@ -88,7 +87,7 @@ export const getVersionToColorMap = (versionsMap: VersionsMap) => { | |
| versionToColor.set(minor.version, versionColor); | ||
| }); | ||
| } else { | ||
| versionToColor.set(item.version, GREY_COLOR); | ||
| versionToColor.set(item.version, DEFAULT_COLOR); | ||
| } | ||
| }); | ||
| return versionToColor; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ import type {VersionToColorMap, VersionValue} from '../../types/versions'; | |
|
|
||
| import {getMinorVersion} from './parseVersion'; | ||
|
|
||
| const MIN_VALUE = 0.5; | ||
|
|
||
| export const parseNodesToVersionsValues = ( | ||
| nodes: TSystemStateInfo[] = [], | ||
| versionsToColor?: VersionToColorMap, | ||
|
|
@@ -18,15 +20,16 @@ export const parseNodesToVersionsValues = ( | |
| } | ||
| return acc; | ||
| }, {}); | ||
|
|
||
| return Object.keys(versionsCount).map((version) => { | ||
| const result = Object.keys(versionsCount).map((version) => { | ||
| const value = (versionsCount[version] / nodes.length) * 100; | ||
| return { | ||
| title: version, | ||
| version: version, | ||
| color: versionsToColor?.get(getMinorVersion(version)), | ||
| value: (versionsCount[version] / nodes.length) * 100, | ||
| value: value < MIN_VALUE ? MIN_VALUE : value, | ||
|
Collaborator
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. Why MIN_VALUE is 0.5 ?
Contributor
Author
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. It was kinda a shot in the dark. It looks nice - not wide, but sufficient to hove a mouse. |
||
| }; | ||
| }); | ||
| return normalizeResult(result); | ||
| }; | ||
|
|
||
| export function parseNodeGroupsToVersionsValues( | ||
|
|
@@ -35,12 +38,31 @@ export function parseNodeGroupsToVersionsValues( | |
| total?: number, | ||
| ) { | ||
| const normalizedTotal = total ?? groups.reduce((acc, group) => acc + group.count, 0); | ||
| return groups.map((group) => { | ||
| const result = groups.map((group) => { | ||
| const value = (group.count / normalizedTotal) * 100; | ||
| return { | ||
| title: group.name, | ||
| version: group.name, | ||
| color: versionsToColor?.get(group.name), | ||
| value: (group.count / normalizedTotal) * 100, | ||
| value: value < MIN_VALUE ? MIN_VALUE : value, | ||
| }; | ||
| }); | ||
| const normalized = normalizeResult(result); | ||
| return normalized; | ||
| } | ||
|
|
||
| function normalizeResult(data: VersionValue[]) { | ||
| let maximum = data[0].value; | ||
| let maximumIndex = 0; | ||
| let total = 0; | ||
| data.forEach((item, index) => { | ||
| total += item.value; | ||
| if (item.value > maximum) { | ||
| maximum = item.value; | ||
| maximumIndex = index; | ||
| } | ||
| }); | ||
| const result = [...data]; | ||
| result[maximumIndex] = {...data[maximumIndex], value: maximum + 100 - total}; | ||
|
Member
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. Why do you need such normalization? If my most common version is 24-3 and I have 1000 nodes out of 1300 with such version, its value will be -200 (converted to 0.5)? So most common version will have least space on the bar?
Contributor
Author
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. Discussed in pm, I've added a comment, for what this normalization is needed. |
||
| return result; | ||
| } | ||
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.
Why don't you reuse the same hook from
/containers/Cluster/ClusterInfo/utils.ts?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.
Cause very soon it will be removed from
/containers/Cluster/ClusterInfo/utils.ts. Currently in #1473 .