Skip to content

Commit 569bdf8

Browse files
Merge pull request #907 from devtron-labs/feat/cost-config
feat: cost config
2 parents 6e7dcf6 + 730953f commit 569bdf8

File tree

9 files changed

+132
-43
lines changed

9 files changed

+132
-43
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.20.3-alpha-9",
3+
"version": "1.20.3-pre-10",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/Common.service.ts

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ const cdMaterialListModal = ({
141141
}
142142

143143
const isConsumedNonApprovedImage =
144-
!isExceptionUser && isApprovalConfigured &&
144+
!isExceptionUser &&
145+
isApprovalConfigured &&
145146
(!material.userApprovalMetadata ||
146-
material.userApprovalMetadata.approvalRuntimeState !== ApprovalRuntimeStateType.approved)
147+
material.userApprovalMetadata.approvalRuntimeState !== ApprovalRuntimeStateType.approved)
147148

148149
const selectImage =
149150
!isImageMarked && markFirstSelected && filterState === FilterStates.ALLOWED && !isConsumedNonApprovedImage
@@ -349,9 +350,7 @@ export const processCDMaterialServiceResponse = (
349350
cdMaterialsResult,
350351
)
351352

352-
const isApprovalConfigured = getIsApprovalPolicyConfigured(
353-
approvalInfo?.deploymentApprovalInfo?.approvalConfigData,
354-
)
353+
const isApprovalConfigured = getIsApprovalPolicyConfigured(approvalInfo?.deploymentApprovalInfo?.approvalConfigData)
355354

356355
const isExceptionUser = approvalInfo?.deploymentApprovalInfo?.approvalConfigData?.isExceptionUser ?? false
357356

@@ -570,7 +569,6 @@ export const getAppsInfoForEnv = async ({ envId, appIds }: GetAppsInfoForEnvProp
570569
}
571570
}
572571

573-
574572
export const getAppOptionsGroupedByProjects = async (): Promise<AppsGroupedByProjectsType> => {
575573
const { result } = await get<AppsGroupedByProjectsType>(ROUTES.APP_LIST_MIN)
576574

@@ -586,7 +584,6 @@ export const getAppOptionsGroupedByProjects = async (): Promise<AppsGroupedByPro
586584
.sort((a, b) => stringComparatorBySortOrder(a.projectName, b.projectName))
587585
}
588586

589-
590587
export const getEnvironmentOptionsGroupedByClusters = async (): Promise<EnvironmentsGroupedByClustersType> => {
591588
const { result } = (await get(ROUTES.ENVIRONMENT_LIST_MIN)) as ResponseType<EnvListMinDTO[]>
592589

@@ -634,7 +631,10 @@ export const getEnvironmentOptionsGroupedByClusters = async (): Promise<Environm
634631
return envGroupedByCluster
635632
}
636633

637-
export const getDetailedClusterList = async (clusterIds?: number[], signal?: AbortSignal): Promise<ClusterDetailListType[]> => {
634+
export const getDetailedClusterList = async (
635+
clusterIds?: number[],
636+
signal?: AbortSignal,
637+
): Promise<ClusterDetailListType[]> => {
638638
const url = getUrlWithSearchParams(ROUTES.CLUSTER, { clusterId: clusterIds?.join() })
639639
const { result } = await get<ClusterDetailDTO[]>(url, { signal })
640640

@@ -647,21 +647,47 @@ export const getDetailedClusterList = async (clusterIds?: number[], signal?: Abo
647647
prometheus_url: prometheusUrl,
648648
category,
649649
clusterStatus,
650+
costModuleConfig,
650651
...res
651-
}) => ({
652-
...res,
653-
clusterId: id,
654-
serverUrl,
655-
clusterName,
656-
prometheusUrl,
657-
category: category?.name
658-
? {
659-
label: category.name,
660-
value: category.id,
661-
}
662-
: null,
663-
status: clusterStatus,
664-
}),
652+
}) => {
653+
const costModuleInstallationStatus = costModuleConfig?.installationStatus || 'NotInstalled'
654+
// Need to remove following keys from config if present: openCostServiceName, openCostServicePort, releaseName, namespace
655+
const sanitizedCostConfig = costModuleConfig?.config
656+
? Object.fromEntries(
657+
Object.entries(costModuleConfig.config).filter(
658+
([key]) =>
659+
!['openCostServiceName', 'openCostServicePort', 'releaseName', 'namespace'].includes(
660+
key,
661+
),
662+
),
663+
)
664+
: undefined
665+
666+
return {
667+
...res,
668+
clusterId: id,
669+
serverUrl,
670+
clusterName,
671+
prometheusUrl,
672+
category: category?.name
673+
? {
674+
label: category.name,
675+
value: category.id,
676+
}
677+
: null,
678+
status: clusterStatus,
679+
costModuleConfig: {
680+
enabled: costModuleConfig?.enabled || false,
681+
config: sanitizedCostConfig,
682+
installationStatus: costModuleInstallationStatus,
683+
...(costModuleInstallationStatus === 'Failed'
684+
? {
685+
installationError: costModuleConfig?.installationError || 'Some error occurred',
686+
}
687+
: {}),
688+
} satisfies ClusterDetailListType['costModuleConfig'],
689+
}
690+
},
665691
)
666692
.sort((a, b) => stringComparatorBySortOrder(a.clusterName, b.clusterName))
667693
}

src/Common/Types.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,23 @@ export type EnvironmentsGroupedByClustersType = {
11181118
envList: EnvironmentType[]
11191119
}[]
11201120

1121+
export type ClusterCostModuleConfigPayload =
1122+
| {
1123+
enabled: true
1124+
config?: Record<string, any>
1125+
}
1126+
| {
1127+
enabled: false
1128+
config?: never
1129+
}
1130+
1131+
interface ClusterCostModuleDetailsDTO extends Pick<ClusterCostModuleConfigPayload, 'enabled' | 'config'> {
1132+
// Note that these status are independent of `enabled` flag
1133+
// e.g. cost module can be disabled but still in `Success` state
1134+
installationStatus: 'Success' | 'Installing' | 'Upgrading' | 'NotInstalled' | 'Failed'
1135+
installationError?: string
1136+
}
1137+
11211138
export interface ClusterDetailDTO {
11221139
category: ClusterEnvironmentCategoryType
11231140
cluster_name: string
@@ -1133,6 +1150,7 @@ export interface ClusterDetailDTO {
11331150
proxyUrl: string
11341151
toConnectWithSSHTunnel: boolean
11351152
clusterStatus: ClusterStatusType
1153+
costModuleConfig: ClusterCostModuleDetailsDTO
11361154
}
11371155

11381156
export interface ClusterDetailListType
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { IconName } from '@Shared/Components'
2+
3+
import { ClusterProviderType } from './types'
4+
5+
export const CLUSTER_PROVIDER_TO_ICON_NAME: Record<ClusterProviderType, IconName | null> = {
6+
AWS: 'ic-aws',
7+
OTC: 'ic-otc-cloud',
8+
Azure: 'ic-azure',
9+
GCP: 'ic-google-cloud',
10+
Alibaba: 'ic-alibaba',
11+
Oracle: 'ic-oracle-cloud',
12+
Scaleway: null,
13+
DigitalOcean: null,
14+
Unknown: null,
15+
}
16+
17+
export const CLUSTER_PROVIDER_TO_LABEL: Record<ClusterProviderType, string> = {
18+
AWS: 'AWS',
19+
OTC: 'OTC',
20+
Azure: 'Azure',
21+
GCP: 'GCP',
22+
Alibaba: 'Alibaba',
23+
Oracle: 'Oracle',
24+
Scaleway: 'Scaleway',
25+
DigitalOcean: 'DigitalOcean',
26+
Unknown: 'N/A',
27+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from './constants'
12
export * from './types'

src/Pages-Devtron-2.0/CostVisibility/Shared/types.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import { ReactNode } from 'react'
2+
3+
import { RJSFFormSchema } from '@Common/RJSF'
4+
import { ClusterDetailListType } from '@Common/Types'
5+
16
export enum CostBreakdownViewType {
27
CLUSTERS = 'clusters',
38
ENVIRONMENTS = 'environments',
@@ -10,3 +15,33 @@ export enum CostBreakdownItemViewParamsType {
1015
VIEW = 'view',
1116
DETAIL = 'detail',
1217
}
18+
19+
type RenderClusterFormParamsType = {
20+
clusterDetails: ClusterDetailListType
21+
handleClose: () => void
22+
handleSuccess: () => void
23+
}
24+
25+
export interface CostVisibilityRenderContextType {
26+
renderClusterForm: (params: RenderClusterFormParamsType) => JSX.Element
27+
}
28+
29+
export interface CostVisibilityRenderProviderProps extends CostVisibilityRenderContextType {
30+
children: ReactNode
31+
}
32+
33+
export type ClusterProviderType =
34+
| 'AWS'
35+
| 'GCP'
36+
| 'Azure'
37+
| 'Alibaba'
38+
| 'Scaleway'
39+
| 'Oracle'
40+
| 'OTC'
41+
| 'DigitalOcean'
42+
| 'Unknown'
43+
44+
export interface ClusterProviderDetailsType {
45+
clusterProvider: ClusterProviderType
46+
costModuleSchema: RJSFFormSchema
47+
}

src/Shared/Components/PrometheusConfigurations/PrometheusConfigCard.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
import { noop } from '@Common/Helper'
21
import RadioGroup from '@Common/RadioGroup'
32
import RadioGroupItem from '@Common/RadioGroupItem'
43
import { AuthenticationType } from '@Shared/types'
54

6-
import { ButtonVariantType } from '../Button'
75
import { CustomInput, PasswordField } from '../CustomInput'
8-
import { Icon } from '../Icon'
96
import { InfoBlock } from '../InfoBlock'
107
import { Textarea } from '../Textarea'
118
import { PromoetheusConfigProps } from './types'
129

1310
const PromoetheusConfigCard = ({
1411
prometheusConfig,
15-
isCostPrometheus,
1612
handleOnChange,
1713
onPrometheusAuthTypeChange,
1814
}: PromoetheusConfigProps) => {
@@ -26,19 +22,6 @@ const PromoetheusConfigCard = ({
2622
Devtron uses prometheus to store and track cluster metrics
2723
</span>
2824
</div>
29-
{isCostPrometheus && (
30-
<InfoBlock
31-
variant="help"
32-
description="Reuse Prometheus configuration from Application Monitoring"
33-
buttonProps={{
34-
dataTestId: 'autofill-prometheus',
35-
text: 'Autofill',
36-
onClick: noop, // TODO: Update onClick when cost prometheus is supported
37-
variant: ButtonVariantType.text,
38-
startIcon: <Icon name="ic-magic-wand" color={null} />,
39-
}}
40-
/>
41-
)}
4225
{(userName.error || password.error || endpoint.error) && (
4326
<InfoBlock
4427
variant="error"

src/Shared/Components/PrometheusConfigurations/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ export interface PromoetheusConfigProps {
2020
prometheusConfig: PromoetheusConfig
2121
handleOnChange: (event: SyntheticEvent) => void
2222
onPrometheusAuthTypeChange: (event: SyntheticEvent) => void
23-
isCostPrometheus?: boolean
2423
}

0 commit comments

Comments
 (0)