diff --git a/charts/uik8sappscodecom-featureset-opscenter-observability-editor/ui/create-ui.yaml b/charts/uik8sappscodecom-featureset-opscenter-observability-editor/ui/create-ui.yaml index 08663642cd..cf471c8982 100644 --- a/charts/uik8sappscodecom-featureset-opscenter-observability-editor/ui/create-ui.yaml +++ b/charts/uik8sappscodecom-featureset-opscenter-observability-editor/ui/create-ui.yaml @@ -28,13 +28,25 @@ steps: - computed: checkIsResourceLoaded if: hideThisElement type: input + - alertInfo: + show: true + type: info + label: + text: 'Note: Enabling a feature auto enables any prerequisite features' + type: label-element + - discriminator: + monitoringClusterConfig: + type: object + - if: checkIsOtelStackEnabled + fetch: fetchMonitoringClusterOptions + onChange: onMonitoringClusterChange + required: true + label: + text: Select Monitoring Cluster + schema: + $ref: discriminator#/properties/monitoringClusterName + type: select type: single-step-form - - alertInfo: - show: true - type: info - label: - text: 'Note: Enabling a feature auto enables any prerequisite features' - type: label-element type: single-step-form id: opscenter-monitoring title: steps.0.label diff --git a/charts/uik8sappscodecom-featureset-opscenter-observability-editor/ui/functions.js b/charts/uik8sappscodecom-featureset-opscenter-observability-editor/ui/functions.js index bf4f0f30b3..44084aa05a 100644 --- a/charts/uik8sappscodecom-featureset-opscenter-observability-editor/ui/functions.js +++ b/charts/uik8sappscodecom-featureset-opscenter-observability-editor/ui/functions.js @@ -1,6 +1,8 @@ // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern +const appsCodeOtelStack = 'appscode-otel-stack' + // get specific feature details function getFeatureSetDetails(storeGet) { const featureSets = storeGet('/cluster/featureSets/result') || [] @@ -195,8 +197,53 @@ function getResourceValuePathFromFeature(feature) { return resourceValuePath } -function onEnabledFeaturesChange({ discriminator, getValue, commit, storeGet }) { +function deepMergeValues(existingValues, newValues) { + if (!newValues) return existingValues + if (!existingValues) return newValues + + const merged = { ...existingValues } + + Object.keys(newValues).forEach((key) => { + if ( + typeof newValues[key] === 'object' && + newValues[key] !== null && + !Array.isArray(newValues[key]) + ) { + merged[key] = deepMergeValues(existingValues[key], newValues[key]) + } else { + merged[key] = newValues[key] + } + }) + + return merged +} + +// fetch monitoring cluster configuration +async function fetchMonitoringClusterConfig({ storeGet, axios, monitoringClusterName }) { + if (!monitoringClusterName) { + return null + } + + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const { data } = await axios.get( + `/clustersv2/${owner}/${cluster}/telemetry/values/appscode-otel-stack?cluster=${monitoringClusterName}`, + ) + return data +} + +async function onEnabledFeaturesChange({ discriminator, getValue, commit, storeGet, axios }) { const enabledFeatures = getValue(discriminator, '/enabledFeatures') || [] + const monitoringClusterName = getValue(discriminator, '/monitoringClusterName') + let monitoringClusterConfig = getValue(discriminator, '/monitoringClusterConfig') + + if (monitoringClusterName && !monitoringClusterConfig) { + monitoringClusterConfig = await fetchMonitoringClusterConfig({ + storeGet, + axios, + monitoringClusterName, + }) + } const allFeatures = storeGet('/cluster/features/result') || [] @@ -232,6 +279,14 @@ function onEnabledFeaturesChange({ discriminator, getValue, commit, storeGet }) if (isEnabled && !isManaged) { commit('wizard/model$delete', `/resources/${resourceValuePath}`) } else { + // Merge existing values with otelStack data only for appscode-otel-stack feature + const initialResourceValues = resources?.[resourceValuePath]?.spec?.values + let mergedResourceValues = initialResourceValues + + if (featureName === appsCodeOtelStack && monitoringClusterName && monitoringClusterConfig) { + mergedResourceValues = deepMergeValues(initialResourceValues, monitoringClusterConfig) + } + commit('wizard/model$update', { path: `/resources/${resourceValuePath}`, value: { @@ -246,6 +301,7 @@ function onEnabledFeaturesChange({ discriminator, getValue, commit, storeGet }) }, spec: { ...resources?.[resourceValuePath]?.spec, + values: mergedResourceValues, chart: { spec: { chart, @@ -375,6 +431,61 @@ function checkIsResourceLoaded({ commit, storeGet, watchDependency, getValue, di } } +//this function is used to check if AppsCode OpenTelemetry Stack is enabled +//it is the condition to show monitoring cluster dropdown +function checkIsOtelStackEnabled({ discriminator, getValue, watchDependency }) { + watchDependency('discriminator#/enabledFeatures') + const enabledFeatures = getValue(discriminator, '/enabledFeatures') || [] + if (enabledFeatures.includes(appsCodeOtelStack)) { + return true + } + return false +} + +//this function is used to fetch monitoring cluster options from dropdown +async function fetchMonitoringClusterOptions({ discriminator, storeGet, axios, getValue }) { + const enabledFeatures = getValue(discriminator, '/enabledFeatures') || [] + if (!enabledFeatures.includes(appsCodeOtelStack)) { + return [] + } + + const owner = storeGet('/route/params/user') + let url = `/clustersv2/${owner}/monitoring-clusters` + const { data } = await axios.get(url) + + return data || [] +} + +async function onMonitoringClusterChange({ + discriminator, + getValue, + storeGet, + axios, + commit, + setDiscriminatorValue, +}) { + const monitoringClusterName = getValue(discriminator, '/monitoringClusterName') + if (!monitoringClusterName) { + return + } + + const data = await fetchMonitoringClusterConfig({ + storeGet, + axios, + monitoringClusterName, + }) + + setDiscriminatorValue('/monitoringClusterConfig', data) + onEnabledFeaturesChange({ + discriminator, + getValue, + commit, + storeGet, + axios, + setDiscriminatorValue, + }) +} + return { hideThisElement, checkIsResourceLoaded, @@ -388,4 +499,7 @@ return { returnFalse, setReleaseNameAndNamespaceAndInitializeValues, fetchFeatureSetOptions, + checkIsOtelStackEnabled, + fetchMonitoringClusterOptions, + onMonitoringClusterChange, }