From c96ebe9c8d58ede91a1b7c0e7a485f2b555d7acb Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Mon, 9 Sep 2024 16:09:49 +0200 Subject: [PATCH 01/10] Added resources component --- src/components/app-overview/index.tsx | 2 + src/components/resources/index.tsx | 75 +++++++++++++++++++++++++++ src/components/resources/style.css | 9 ++++ src/store/radix-api.ts | 36 +++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 src/components/resources/index.tsx create mode 100644 src/components/resources/style.css diff --git a/src/components/app-overview/index.tsx b/src/components/app-overview/index.tsx index 151254b7d..e045612e3 100644 --- a/src/components/app-overview/index.tsx +++ b/src/components/app-overview/index.tsx @@ -13,6 +13,7 @@ import { DefaultAppAlias } from '../component/default-app-alias'; import { DNSAliases } from '../component/dns-aliases'; import { EnvironmentsSummary } from '../environments-summary'; import { JobsList } from '../jobs-list'; +import { UsedResources } from '../resources'; const LATEST_JOBS_LIMIT = 5; @@ -50,6 +51,7 @@ export function AppOverview({ appName }: { appName: string }) {
+
{appAlias && } diff --git a/src/components/resources/index.tsx b/src/components/resources/index.tsx new file mode 100644 index 000000000..2bca8ab22 --- /dev/null +++ b/src/components/resources/index.tsx @@ -0,0 +1,75 @@ +import { Typography } from '@equinor/eds-core-react'; +import * as PropTypes from 'prop-types'; +import type { FunctionComponent } from 'react'; +import { + type ResourcesApiResponse, + useResourcesQuery, +} from '../../store/radix-api'; +import { formatDateTimeYear } from '../../utils/datetime'; +import AsyncResource from '../async-resource/async-resource'; + +import './style.css'; + +function getPeriod({ from, to }: ResourcesApiResponse): string { + return `${formatDateTimeYear(new Date(from))} - ${formatDateTimeYear( + new Date(to) + )}`; +} + +export interface UsedResourcesProps { + appName: string; +} + +export const UsedResources: FunctionComponent = ({ + appName, +}) => { + const { data: resources, ...state } = useResourcesQuery( + { appName }, + { skip: !appName } + ); + + return ( +
+ Used resources + + {resources ? ( +
+
+ Period + + {getPeriod(resources)} + +
+ +
+ <> + + CPU{' '} + + min {resources?.cpu?.min ?? '-'}, max{' '} + {resources?.cpu?.max ?? '-'}, avg{' '} + {resources?.cpu?.average ?? '-'} + + + + Memory{' '} + + min {resources?.memory?.min ?? '-'}, max{' '} + {resources?.memory?.max ?? '-'}, avg{' '} + {resources?.memory?.average ?? '-'} + + + +
+
+ ) : ( + No data + )} +
+
+ ); +}; + +UsedResources.propTypes = { + appName: PropTypes.string.isRequired, +}; diff --git a/src/components/resources/style.css b/src/components/resources/style.css new file mode 100644 index 000000000..ff51d9a33 --- /dev/null +++ b/src/components/resources/style.css @@ -0,0 +1,9 @@ +.resources-section > div { + grid-auto-rows: min-content; +} + +@media (min-width: 30rem) { + .resources-section { + grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); + } +} diff --git a/src/store/radix-api.ts b/src/store/radix-api.ts index 0d7aa4d8a..bf72e72d7 100644 --- a/src/store/radix-api.ts +++ b/src/store/radix-api.ts @@ -1007,6 +1007,15 @@ const injectedRtkApi = api.injectEndpoints({ }, }), }), + resources: build.query({ + query: (queryArg) => ({ + url: `/applications/${queryArg.appName}/resources`, + headers: { + 'Impersonate-User': queryArg['Impersonate-User'], + 'Impersonate-Group': queryArg['Impersonate-Group'], + }, + }), + }), restartApplication: build.mutation< RestartApplicationApiResponse, RestartApplicationApiArg @@ -2133,6 +2142,16 @@ export type RegenerateDeployKeyApiArg = { /** Regenerate deploy key and secret data */ regenerateDeployKeyAndSecretData: RegenerateDeployKeyAndSecretData; }; +export type ResourcesApiResponse = + /** status 200 Successful trigger pipeline */ UsedResources; +export type ResourcesApiArg = { + /** Name of application */ + appName: string; + /** Works only with custom setup of cluster. Allow impersonation of test users (Required if Impersonate-Group is set) */ + 'Impersonate-User'?: string; + /** Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set) */ + 'Impersonate-Group'?: string; +}; export type RestartApplicationApiResponse = unknown; export type RestartApplicationApiArg = { /** Name of application */ @@ -3272,6 +3291,22 @@ export type RegenerateDeployKeyAndSecretData = { /** SharedSecret of the shared secret */ sharedSecret?: string; }; +export type UsedResource = { + /** Average resource used */ + average?: string; + /** Max resource used */ + max?: string; + /** Min resource used */ + min?: string; +}; +export type UsedResources = { + cpu?: UsedResource; + /** From timestamp */ + from: string; + memory?: UsedResource; + /** To timestamp */ + to: string; +}; export const { useShowApplicationsQuery, useRegisterApplicationMutation, @@ -3354,6 +3389,7 @@ export const { useGetPrivateImageHubsQuery, useUpdatePrivateImageHubsSecretValueMutation, useRegenerateDeployKeyMutation, + useResourcesQuery, useRestartApplicationMutation, useStartApplicationMutation, useStopApplicationMutation, From 0e77e320ef94cb14631356d019a7a25f7bd7b14e Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Thu, 12 Sep 2024 14:45:48 +0200 Subject: [PATCH 02/10] Added resources popup with details --- src/components/resources/index.tsx | 96 +++++++++++++++++++++++++++--- src/components/resources/style.css | 17 ++++++ src/externalUrls.ts | 1 + src/store/radix-api.ts | 6 ++ 4 files changed, 113 insertions(+), 7 deletions(-) diff --git a/src/components/resources/index.tsx b/src/components/resources/index.tsx index 2bca8ab22..e2d95240b 100644 --- a/src/components/resources/index.tsx +++ b/src/components/resources/index.tsx @@ -1,12 +1,15 @@ -import { Typography } from '@equinor/eds-core-react'; +import { Icon, Table, Tooltip, Typography } from '@equinor/eds-core-react'; +import { info_circle, library_books } from '@equinor/eds-icons'; import * as PropTypes from 'prop-types'; -import type { FunctionComponent } from 'react'; +import { type FunctionComponent, useState } from 'react'; +import { externalUrls } from '../../externalUrls'; import { type ResourcesApiResponse, useResourcesQuery, } from '../../store/radix-api'; import { formatDateTimeYear } from '../../utils/datetime'; import AsyncResource from '../async-resource/async-resource'; +import { ScrimPopup } from '../scrim-popup'; import './style.css'; @@ -27,10 +30,21 @@ export const UsedResources: FunctionComponent = ({ { appName }, { skip: !appName } ); - + const [visibleScrim, setVisibleScrim] = useState(false); return (
- Used resources +
+ Used resources + + + + + +
{resources ? (
@@ -41,8 +55,8 @@ export const UsedResources: FunctionComponent = ({
-
- <> +
+
CPU{' '} @@ -59,7 +73,75 @@ export const UsedResources: FunctionComponent = ({ {resources?.memory?.average ?? '-'} - +
+ setVisibleScrim(true)} + /> + setVisibleScrim(false)} + > +
+ + + + + Min + Max + Average + + + + + CPU (rounded, millicores) + {resources?.cpu?.min ?? '-'} + {resources?.cpu?.max ?? '-'} + + {resources?.cpu?.average ?? '-'} + + + + CPU (actual, millicores) + + {resources?.cpu?.minActual ?? '-'} + + + {resources?.cpu?.maxActual ?? '-'} + + + {resources?.cpu?.avgActual ?? '-'} + + + + Memory (rounded, MB) + {resources?.memory?.min ?? '-'} + {resources?.memory?.max ?? '-'} + + {resources?.memory?.average ?? '-'} + + + + Memory (actual, MB) + + {resources?.memory?.minActual ?? '-'} + + + {resources?.memory?.maxActual ?? '-'} + + + {resources?.memory?.avgActual ?? '-'} + + + +
+
+
) : ( diff --git a/src/components/resources/style.css b/src/components/resources/style.css index ff51d9a33..55a8a74a4 100644 --- a/src/components/resources/style.css +++ b/src/components/resources/style.css @@ -7,3 +7,20 @@ grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); } } + +.icon-justify-end { + justify-self: end; +} + +.resources__scrim .resources__scrim-content { + margin: var(--eds_spacing_medium); + margin-top: initial; + align-content: center; + min-width: 500px; +} + +.resources-content { + padding: var(--eds_spacing_medium); + padding-top: 0; + overflow: auto; +} diff --git a/src/externalUrls.ts b/src/externalUrls.ts index d887540b9..f722fad17 100644 --- a/src/externalUrls.ts +++ b/src/externalUrls.ts @@ -15,6 +15,7 @@ export const externalUrls = { externalDNSGuide: 'https://www.radix.equinor.com/guides/external-alias/', workloadIdentityGuide: 'https://www.radix.equinor.com/guides/workload-identity/', uptimeDocs: 'https://radix.equinor.com/docs/topic-uptime/', + resourcesDocs: 'https://radix.equinor.com/guides/resource-request/', radixPlatformWebConsole: `https://console.${clusterBases.radixPlatformWebConsole}/`, radixPlatform2WebConsole: `https://console.${clusterBases.radixPlatform2WebConsole}/`, playgroundWebConsole: `https://console.${clusterBases.playgroundWebConsole}/`, diff --git a/src/store/radix-api.ts b/src/store/radix-api.ts index bf72e72d7..66528df28 100644 --- a/src/store/radix-api.ts +++ b/src/store/radix-api.ts @@ -3294,10 +3294,16 @@ export type RegenerateDeployKeyAndSecretData = { export type UsedResource = { /** Average resource used */ average?: string; + /** AvgActual actual precise resource used */ + avgActual?: number; /** Max resource used */ max?: string; + /** MaxActual actual precise resource used */ + maxActual?: number; /** Min resource used */ min?: string; + /** MinActual actual precise resource used */ + minActual?: number; }; export type UsedResources = { cpu?: UsedResource; From 125e7bfde49a966e4a51b2baf13553d6d8d9f4bd Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Thu, 12 Sep 2024 17:13:24 +0200 Subject: [PATCH 03/10] Added resources args --- src/components/resources/index.tsx | 10 +++++----- src/store/radix-api.ts | 27 ++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/components/resources/index.tsx b/src/components/resources/index.tsx index e2d95240b..f84a3b425 100644 --- a/src/components/resources/index.tsx +++ b/src/components/resources/index.tsx @@ -4,8 +4,8 @@ import * as PropTypes from 'prop-types'; import { type FunctionComponent, useState } from 'react'; import { externalUrls } from '../../externalUrls'; import { - type ResourcesApiResponse, - useResourcesQuery, + type GetResourcesApiResponse, + useGetResourcesQuery, } from '../../store/radix-api'; import { formatDateTimeYear } from '../../utils/datetime'; import AsyncResource from '../async-resource/async-resource'; @@ -13,7 +13,7 @@ import { ScrimPopup } from '../scrim-popup'; import './style.css'; -function getPeriod({ from, to }: ResourcesApiResponse): string { +function getPeriod({ from, to }: GetResourcesApiResponse): string { return `${formatDateTimeYear(new Date(from))} - ${formatDateTimeYear( new Date(to) )}`; @@ -26,7 +26,7 @@ export interface UsedResourcesProps { export const UsedResources: FunctionComponent = ({ appName, }) => { - const { data: resources, ...state } = useResourcesQuery( + const { data: resources, ...state } = useGetResourcesQuery( { appName }, { skip: !appName } ); @@ -78,7 +78,7 @@ export const UsedResources: FunctionComponent = ({ style={{ cursor: 'pointer' }} data={info_circle} className={'icon-justify-end'} - onClick={(event) => setVisibleScrim(true)} + onClick={() => setVisibleScrim(true)} /> ({ + getResources: build.query({ query: (queryArg) => ({ url: `/applications/${queryArg.appName}/resources`, headers: { 'Impersonate-User': queryArg['Impersonate-User'], 'Impersonate-Group': queryArg['Impersonate-Group'], }, + params: { + environment: queryArg.environment, + component: queryArg.component, + duration: queryArg.duration, + since: queryArg.since, + ignorezero: queryArg.ignorezero, + }, }), }), restartApplication: build.mutation< @@ -2142,11 +2149,21 @@ export type RegenerateDeployKeyApiArg = { /** Regenerate deploy key and secret data */ regenerateDeployKeyAndSecretData: RegenerateDeployKeyAndSecretData; }; -export type ResourcesApiResponse = +export type GetResourcesApiResponse = /** status 200 Successful trigger pipeline */ UsedResources; -export type ResourcesApiArg = { - /** Name of application */ +export type GetResourcesApiArg = { + /** Name of the application */ appName: string; + /** Name of the application environment */ + environment?: string; + /** Name of the application component in an environment */ + component?: string; + /** Duration of the period, default is 30d (30 days). Example 10m, 1h, 2d, 3w, where m-minutes, h-hours, d-days, w-weeks */ + duration?: string; + /** End time-point of the period in the past, default is now. Example 10m, 1h, 2d, 3w, where m-minutes, h-hours, d-days, w-weeks */ + since?: string; + /** Ignore metrics with zero value if true, default is false */ + ignorezero?: string; /** Works only with custom setup of cluster. Allow impersonation of test users (Required if Impersonate-Group is set) */ 'Impersonate-User'?: string; /** Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set) */ @@ -3395,7 +3412,7 @@ export const { useGetPrivateImageHubsQuery, useUpdatePrivateImageHubsSecretValueMutation, useRegenerateDeployKeyMutation, - useResourcesQuery, + useGetResourcesQuery, useRestartApplicationMutation, useStartApplicationMutation, useStopApplicationMutation, From b145769871954b1fc9cc749edf1a8ba181e68599 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Fri, 13 Sep 2024 13:53:49 +0200 Subject: [PATCH 04/10] Added links to docs --- src/components/resources/index.tsx | 52 +++++++++++++++++++++++++++--- src/externalUrls.ts | 2 ++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/components/resources/index.tsx b/src/components/resources/index.tsx index f84a3b425..ec202ac02 100644 --- a/src/components/resources/index.tsx +++ b/src/components/resources/index.tsx @@ -99,7 +99,18 @@ export const UsedResources: FunctionComponent = ({ - CPU (rounded, millicores) + + CPU ( + + millicores + + , rounded) + {resources?.cpu?.min ?? '-'} {resources?.cpu?.max ?? '-'} @@ -107,7 +118,18 @@ export const UsedResources: FunctionComponent = ({ - CPU (actual, millicores) + + CPU ( + + millicores + + , actual) + {resources?.cpu?.minActual ?? '-'} @@ -119,7 +141,18 @@ export const UsedResources: FunctionComponent = ({ - Memory (rounded, MB) + + Memory ( + + MB + + , rounded) + {resources?.memory?.min ?? '-'} {resources?.memory?.max ?? '-'} @@ -127,7 +160,18 @@ export const UsedResources: FunctionComponent = ({ - Memory (actual, MB) + + Memory ( + + MB + + , actual) + {resources?.memory?.minActual ?? '-'} diff --git a/src/externalUrls.ts b/src/externalUrls.ts index f722fad17..ab910cdcf 100644 --- a/src/externalUrls.ts +++ b/src/externalUrls.ts @@ -16,6 +16,8 @@ export const externalUrls = { workloadIdentityGuide: 'https://www.radix.equinor.com/guides/workload-identity/', uptimeDocs: 'https://radix.equinor.com/docs/topic-uptime/', resourcesDocs: 'https://radix.equinor.com/guides/resource-request/', + kubernetesResourcesCpuUnits: 'https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu', + kubernetesResourcesMemoryUnits: 'https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#meaning-of-memory', radixPlatformWebConsole: `https://console.${clusterBases.radixPlatformWebConsole}/`, radixPlatform2WebConsole: `https://console.${clusterBases.radixPlatform2WebConsole}/`, playgroundWebConsole: `https://console.${clusterBases.playgroundWebConsole}/`, From 08ab3628b0410e34a2a4c773c535434df0161fa3 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Fri, 13 Sep 2024 14:03:54 +0200 Subject: [PATCH 05/10] Added links to docs --- src/components/resources/index.tsx | 36 +++++------------------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/src/components/resources/index.tsx b/src/components/resources/index.tsx index ec202ac02..773a2cbbe 100644 --- a/src/components/resources/index.tsx +++ b/src/components/resources/index.tsx @@ -100,16 +100,15 @@ export const UsedResources: FunctionComponent = ({ - CPU ( + CPU (millicores , rounded){' '} - millicores + - , rounded) {resources?.cpu?.min ?? '-'} {resources?.cpu?.max ?? '-'} @@ -118,18 +117,7 @@ export const UsedResources: FunctionComponent = ({ - - CPU ( - - millicores - - , actual) - + CPU (millicores, actual) {resources?.cpu?.minActual ?? '-'} @@ -142,16 +130,15 @@ export const UsedResources: FunctionComponent = ({ - Memory ( + Memory (MB, rounded){' '} - MB + - , rounded) {resources?.memory?.min ?? '-'} {resources?.memory?.max ?? '-'} @@ -160,18 +147,7 @@ export const UsedResources: FunctionComponent = ({ - - Memory ( - - MB - - , actual) - + Memory ( MB , actual) {resources?.memory?.minActual ?? '-'} From d388ae27229d34ec0e669efd345f3da9de312e55 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Wed, 18 Sep 2024 15:40:12 +0200 Subject: [PATCH 06/10] Fix and merge --- src/components/replica-list/replica-name.tsx | 2 +- src/store/radix-api.ts | 34 ++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/components/replica-list/replica-name.tsx b/src/components/replica-list/replica-name.tsx index f07d1884a..5d9c575ce 100644 --- a/src/components/replica-list/replica-name.tsx +++ b/src/components/replica-list/replica-name.tsx @@ -68,7 +68,7 @@ export const ReplicaName: FunctionComponent<{ displayName={'Job Manager'} replicaName={replica.name} description={ - 'Job Manager creates, gets, deletes singe jobs and batch jobs with Job API' + 'Job Manager creates, gets, deletes single jobs and batch jobs with Job API' } replicaUrlFunc={replicaUrlFunc} /> diff --git a/src/store/radix-api.ts b/src/store/radix-api.ts index e4dc039f7..5e2648cd2 100644 --- a/src/store/radix-api.ts +++ b/src/store/radix-api.ts @@ -1542,6 +1542,19 @@ export type ReplicaLogApiArg = { /** Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set) */ 'Impersonate-Group'?: string; }; +export type ResetScaledComponentApiResponse = unknown; +export type ResetScaledComponentApiArg = { + /** Name of application */ + appName: string; + /** Name of environment */ + envName: string; + /** Name of component */ + componentName: string; + /** Works only with custom setup of cluster. Allow impersonation of test users (Required if Impersonate-Group is set) */ + 'Impersonate-User'?: string; + /** Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set) */ + 'Impersonate-Group'?: string; +}; export type RestartComponentApiResponse = unknown; export type RestartComponentApiArg = { /** Name of application */ @@ -1895,6 +1908,17 @@ export type JobLogApiArg = { /** Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set) */ 'Impersonate-Group'?: string; }; +export type ResetManuallyScaledComponentsInEnvironmentApiResponse = unknown; +export type ResetManuallyScaledComponentsInEnvironmentApiArg = { + /** Name of application */ + appName: string; + /** Name of environment */ + envName: string; + /** Works only with custom setup of cluster. Allow impersonation of test users (Required if Impersonate-Group is set) */ + 'Impersonate-User'?: string; + /** Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set) */ + 'Impersonate-Group'?: string; +}; export type RestartEnvironmentApiResponse = unknown; export type RestartEnvironmentApiArg = { /** Name of application */ @@ -2455,6 +2479,8 @@ export type Component = { replicaList?: ReplicaSummary[]; /** Deprecated: Array of pod names. Use ReplicaList instead */ replicas?: string[]; + /** Set if manual control of replicas is in place. Not set means automatic control, 0 means stopped and >= 1 is manually scaled. */ + replicasOverride?: number | null; resources?: ResourceRequirements; runtime?: Runtime; /** ScheduledJobPayloadPath defines the payload path, where payload for Job Scheduler will be mapped as a file. From radixconfig.yaml */ @@ -2739,7 +2765,7 @@ export type AlertingConfig = { export type UpdateSlackConfigSecrets = { /** WebhookURL the Slack webhook URL where alerts are sent Secret key for webhook URL is updated if a non-nil value is present, and deleted if omitted or set to null - + required: */ webhookUrl?: string | null; }; @@ -3066,7 +3092,7 @@ export type Job = { /** CommitID the commit ID of the branch to build */ commitID?: string; /** Components (array of ComponentSummary) created by the job - + Deprecated: Inspect each deployment to get list of components created by the job */ components?: ComponentSummary[]; /** Created timestamp */ @@ -3377,6 +3403,8 @@ export type UsedResources = { memory?: UsedResource; /** To timestamp */ to: string; + /** Warning messages */ + warnings?: string[]; }; export const { useShowApplicationsQuery, @@ -3414,6 +3442,7 @@ export const { useChangeEnvVarMutation, useUpdateComponentExternalDnsTlsMutation, useReplicaLogQuery, + useResetScaledComponentMutation, useRestartComponentMutation, useScaleComponentMutation, useGetAzureKeyVaultSecretVersionsQuery, @@ -3437,6 +3466,7 @@ export const { useRestartJobMutation, useStopJobMutation, useJobLogQuery, + useResetManuallyScaledComponentsInEnvironmentMutation, useRestartEnvironmentMutation, useStartEnvironmentMutation, useStopEnvironmentMutation, From ee4adede6bc7d0c5a484667abde4b232556bd5d1 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Mon, 23 Sep 2024 15:01:59 +0200 Subject: [PATCH 07/10] Cleanup --- src/components/resources/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/resources/index.tsx b/src/components/resources/index.tsx index 773a2cbbe..5413cec76 100644 --- a/src/components/resources/index.tsx +++ b/src/components/resources/index.tsx @@ -147,7 +147,7 @@ export const UsedResources: FunctionComponent = ({ - Memory ( MB , actual) + Memory (MB , actual) {resources?.memory?.minActual ?? '-'} From 234354f4582479fcdac8ba8db84e69d43c0d51d6 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Wed, 25 Sep 2024 16:14:17 +0200 Subject: [PATCH 08/10] Removed popup --- src/components/resources/index.tsx | 161 +++++++++++------------------ src/store/radix-api.ts | 21 ++-- 2 files changed, 68 insertions(+), 114 deletions(-) diff --git a/src/components/resources/index.tsx b/src/components/resources/index.tsx index 5413cec76..b0cf18f1e 100644 --- a/src/components/resources/index.tsx +++ b/src/components/resources/index.tsx @@ -1,7 +1,7 @@ -import { Icon, Table, Tooltip, Typography } from '@equinor/eds-core-react'; -import { info_circle, library_books } from '@equinor/eds-icons'; +import { Icon, Tooltip, Typography } from '@equinor/eds-core-react'; +import { library_books } from '@equinor/eds-icons'; import * as PropTypes from 'prop-types'; -import { type FunctionComponent, useState } from 'react'; +import type { FunctionComponent } from 'react'; import { externalUrls } from '../../externalUrls'; import { type GetResourcesApiResponse, @@ -9,7 +9,6 @@ import { } from '../../store/radix-api'; import { formatDateTimeYear } from '../../utils/datetime'; import AsyncResource from '../async-resource/async-resource'; -import { ScrimPopup } from '../scrim-popup'; import './style.css'; @@ -30,7 +29,59 @@ export const UsedResources: FunctionComponent = ({ { appName }, { skip: !appName } ); - const [visibleScrim, setVisibleScrim] = useState(false); + const formatCpuUsage = (value?: number): string => { + if (!value) { + return '-'; + } + if (value >= 1) { + return parseFloat(value.toPrecision(3)).toString(); + } + + let millicores = value * 1000; + let formattedValue: string; + if (millicores > 0.009) { + formattedValue = parseFloat(millicores.toPrecision(3)).toString(); + return `${formattedValue}m`; + } + + const significantDigits = 1; + + const exponent = Math.floor(Math.log10(value)); + const factor = 10 ** (-exponent + (significantDigits - 1)); + const roundedValue = Math.round(value * factor) / factor; + millicores = roundedValue * 1000; + formattedValue = millicores.toFixed(-Math.floor(Math.log10(millicores))); + + formattedValue = parseFloat(formattedValue).toString(); + return `${formattedValue}m`; + }; + + const formatMemoryUsage = (value?: number): string => { + if (!value) { + return '-'; + } + const units = [ + { unit: 'P', size: 1e15 }, + { unit: 'T', size: 1e12 }, + { unit: 'G', size: 1e9 }, + { unit: 'M', size: 1e6 }, + { unit: 'k', size: 1e3 }, + ]; + + let unit = ''; // Default to bytes + + // Determine the appropriate unit + for (const u of units) { + if (value >= u.size) { + value = value / u.size; + unit = u.unit; + break; + } + } + const formattedValue = parseFloat(value.toPrecision(3)).toString(); + return formattedValue + unit; + }; + return (
@@ -60,108 +111,20 @@ export const UsedResources: FunctionComponent = ({ CPU{' '} - min {resources?.cpu?.min ?? '-'}, max{' '} - {resources?.cpu?.max ?? '-'}, avg{' '} - {resources?.cpu?.average ?? '-'} + min {formatCpuUsage(resources?.cpu?.min)}, avg{' '} + {formatCpuUsage(resources?.cpu?.avg)}, max{' '} + {formatCpuUsage(resources?.cpu?.max)} Memory{' '} - min {resources?.memory?.min ?? '-'}, max{' '} - {resources?.memory?.max ?? '-'}, avg{' '} - {resources?.memory?.average ?? '-'} + min {formatMemoryUsage(resources?.memory?.min)}, avg{' '} + {formatMemoryUsage(resources?.memory?.avg)}, max{' '} + {formatMemoryUsage(resources?.memory?.max)}
- setVisibleScrim(true)} - /> - setVisibleScrim(false)} - > -
- - - - - Min - Max - Average - - - - - - CPU (millicores , rounded){' '} - - - - - {resources?.cpu?.min ?? '-'} - {resources?.cpu?.max ?? '-'} - - {resources?.cpu?.average ?? '-'} - - - - CPU (millicores, actual) - - {resources?.cpu?.minActual ?? '-'} - - - {resources?.cpu?.maxActual ?? '-'} - - - {resources?.cpu?.avgActual ?? '-'} - - - - - Memory (MB, rounded){' '} - - - - - {resources?.memory?.min ?? '-'} - {resources?.memory?.max ?? '-'} - - {resources?.memory?.average ?? '-'} - - - - Memory (MB , actual) - - {resources?.memory?.minActual ?? '-'} - - - {resources?.memory?.maxActual ?? '-'} - - - {resources?.memory?.avgActual ?? '-'} - - - -
-
-
) : ( diff --git a/src/store/radix-api.ts b/src/store/radix-api.ts index 5e2648cd2..e43279950 100644 --- a/src/store/radix-api.ts +++ b/src/store/radix-api.ts @@ -1058,7 +1058,6 @@ const injectedRtkApi = api.injectEndpoints({ component: queryArg.component, duration: queryArg.duration, since: queryArg.since, - ignorezero: queryArg.ignorezero, }, }), }), @@ -2234,8 +2233,6 @@ export type GetResourcesApiArg = { duration?: string; /** End time-point of the period in the past, default is now. Example 10m, 1h, 2d, 3w, where m-minutes, h-hours, d-days, w-weeks */ since?: string; - /** Ignore metrics with zero value if true, default is false */ - ignorezero?: string; /** Works only with custom setup of cluster. Allow impersonation of test users (Required if Impersonate-Group is set) */ 'Impersonate-User'?: string; /** Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set) */ @@ -3383,18 +3380,12 @@ export type RegenerateDeployKeyAndSecretData = { sharedSecret?: string; }; export type UsedResource = { - /** Average resource used */ - average?: string; - /** AvgActual actual precise resource used */ - avgActual?: number; - /** Max resource used */ - max?: string; - /** MaxActual actual precise resource used */ - maxActual?: number; - /** Min resource used */ - min?: string; - /** MinActual actual precise resource used */ - minActual?: number; + /** Avg actual precise resource used */ + avg?: number; + /** Max actual precise resource used */ + max?: number; + /** Min actual precise resource used */ + min?: number; }; export type UsedResources = { cpu?: UsedResource; From 868109564e038030acdc17c730377d43740247e5 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Fri, 27 Sep 2024 17:06:34 +0200 Subject: [PATCH 09/10] Adjusted cpu resources --- src/components/resources/index.tsx | 51 ++++++++++++++++++++++-------- src/store/radix-api.ts | 31 +++++++++++++++--- 2 files changed, 64 insertions(+), 18 deletions(-) diff --git a/src/components/resources/index.tsx b/src/components/resources/index.tsx index b0cf18f1e..988d89213 100644 --- a/src/components/resources/index.tsx +++ b/src/components/resources/index.tsx @@ -37,23 +37,48 @@ export const UsedResources: FunctionComponent = ({ return parseFloat(value.toPrecision(3)).toString(); } - let millicores = value * 1000; + const millicores = value * 1000.0; let formattedValue: string; - if (millicores > 0.009) { + if (millicores >= 1.0) { formattedValue = parseFloat(millicores.toPrecision(3)).toString(); return `${formattedValue}m`; } - - const significantDigits = 1; - - const exponent = Math.floor(Math.log10(value)); - const factor = 10 ** (-exponent + (significantDigits - 1)); - const roundedValue = Math.round(value * factor) / factor; - millicores = roundedValue * 1000; - formattedValue = millicores.toFixed(-Math.floor(Math.log10(millicores))); - - formattedValue = parseFloat(formattedValue).toString(); - return `${formattedValue}m`; + let mcStr = millicores.toFixed(20); // Use 20 decimal places to ensure precision + mcStr = mcStr.replace(/0+$/, ''); + // Find the position of the decimal point + const decimalIndex = mcStr.indexOf('.'); + // Find the index of the first non-zero digit after the decimal point + let firstNonZeroIndex = -1; + for (let i = decimalIndex + 1; i < mcStr.length; i++) { + if (mcStr[i] !== '0') { + firstNonZeroIndex = i; + break; + } + } + if (firstNonZeroIndex === -1) { + return '0m'; + } + // Create a new number where the digit at firstNonZeroIndex becomes the first decimal digit + const digits = `0.${mcStr.substring(firstNonZeroIndex)}`; + let num = parseFloat(digits); + // Round the number to one digit + num = Math.round(num * 10) / 10; + // Handle rounding that results in num >= 1 + if (num >= 1) { + num = 1; + } + let numStr = num.toString(); + // Remove the decimal point and any following zeros + numStr = numStr.replace('0.', '').replace(/0+$/, ''); + // Replace the part of mcStr starting from firstNonZeroIndex - 1 + let zerosCount = firstNonZeroIndex - decimalIndex - 1; + // Adjust zerosCount in case of carry-over (when num becomes 1) + if (num === 1) { + zerosCount -= 1; + } + const leadingDigitalZeros = '0'.repeat(Math.max(zerosCount, 0)); + const output = `0.${leadingDigitalZeros}${numStr}`; + return `${output}m`; }; const formatMemoryUsage = (value?: number): string => { diff --git a/src/store/radix-api.ts b/src/store/radix-api.ts index e43279950..45d94b92d 100644 --- a/src/store/radix-api.ts +++ b/src/store/radix-api.ts @@ -2354,6 +2354,16 @@ export type AzureIdentity = { export type Identity = { azure?: AzureIdentity; }; +export type IngressPublic = { + /** List of allowed IP addresses or CIDRs. All traffic is allowed if list is empty. */ + allow: string[]; +}; +export type Ingress = { + public?: IngressPublic; +}; +export type Network = { + ingress?: Ingress; +}; export type Notifications = { /** Webhook is a URL for notification about internal events or changes. The URL should be of a Radix component or job-component, with not public port. */ webhook?: string; @@ -2446,10 +2456,12 @@ export type OAuth2AuxiliaryResource = { deployment: AuxiliaryResourceDeployment; }; export type Port = { + /** IsPublic indicates that the port is accessible from the Internet by proxying traffic from 443 */ + isPublic: boolean; /** Component port name. From radixconfig.yaml */ name: string; /** Component port number. From radixconfig.yaml */ - port?: number; + port: number; }; export type Runtime = { /** CPU architecture */ @@ -2468,6 +2480,7 @@ export type Component = { image: string; /** Name the component */ name: string; + network?: Network; notifications?: Notifications; oauth2?: OAuth2AuxiliaryResource; /** Ports defines the port number and protocol that a component is exposed for internally in environment */ @@ -2553,6 +2566,8 @@ export type ApplicationSummary = { export type ApplicationRegistration = { /** AdGroups the groups that should be able to access the application */ adGroups: string[]; + /** AdUsers the users/service-principals that should be able to access the application */ + adUsers: string[]; /** ConfigBranch information */ configBranch: string; /** ConfigurationItem is an identifier for an entity in a configuration management solution such as a CMDB. @@ -2568,7 +2583,9 @@ export type ApplicationRegistration = { /** radixconfig.yaml file name and path, starting from the GitHub repository root (without leading slash) */ radixConfigFullName?: string; /** ReaderAdGroups the groups that should be able to read the application */ - readerAdGroups?: string[]; + readerAdGroups: string[]; + /** ReaderAdUsers the users/service-principals that should be able to read the application */ + readerAdUsers: string[]; /** Repository the github repository */ repository: string; /** SharedSecret the shared secret of the webhook */ @@ -2697,6 +2714,8 @@ export type Application = { export type ApplicationRegistrationPatch = { /** AdGroups the groups that should be able to access the application */ adGroups?: string[]; + /** AdUsers the users/service-principals that should be able to access the application */ + adUsers?: string[]; /** ConfigBranch information */ configBranch?: string; /** ConfigurationItem is an identifier for an entity in a configuration management solution such as a CMDB. @@ -2709,6 +2728,8 @@ export type ApplicationRegistrationPatch = { radixConfigFullName?: string; /** ReaderAdGroups the groups that should be able to read the application */ readerAdGroups?: string[]; + /** ReaderAdUsers the users/service-principals that should be able to read the application */ + readerAdUsers?: string[]; /** Repository the github repository */ repository?: string; /** WBS information */ @@ -3380,11 +3401,11 @@ export type RegenerateDeployKeyAndSecretData = { sharedSecret?: string; }; export type UsedResource = { - /** Avg actual precise resource used */ + /** Avg Average resource used */ avg?: number; - /** Max actual precise resource used */ + /** Max resource used */ max?: number; - /** Min actual precise resource used */ + /** Min resource used */ min?: number; }; export type UsedResources = { From 9ef14bb67b543b7cb321b62b747c187ce351df71 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Fri, 27 Sep 2024 17:07:51 +0200 Subject: [PATCH 10/10] Adjusted cpu resources --- src/components/resources/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/resources/index.tsx b/src/components/resources/index.tsx index 988d89213..d82ab9ef7 100644 --- a/src/components/resources/index.tsx +++ b/src/components/resources/index.tsx @@ -72,7 +72,7 @@ export const UsedResources: FunctionComponent = ({ numStr = numStr.replace('0.', '').replace(/0+$/, ''); // Replace the part of mcStr starting from firstNonZeroIndex - 1 let zerosCount = firstNonZeroIndex - decimalIndex - 1; - // Adjust zerosCount in case of carry-over (when num becomes 1) + // Adjust zerosCount, when num is 1 if (num === 1) { zerosCount -= 1; }