function validateAppComponentAndServerMetricsConfig()

in src/Utils/YamlValidationUtil.ts [262:313]


function validateAppComponentAndServerMetricsConfig(appComponents: Array<any>) : ValidationModel {
    let appComponentsParsed = appComponents;
    for(let i = 0; i < appComponentsParsed.length; i++){
        if(!isDictionary(appComponentsParsed[i])){
            return {valid : false, error : `The value "${appComponentsParsed[i].toString()}" for AppComponents in the index "${i}" is invalid. Provide a valid dictionary.`};
        }
        let resourceId = appComponentsParsed[i].resourceId;
        if(isInvalidString(resourceId)){
            return {valid : false, error : `The value "${appComponentsParsed[i].resourceId}" for resourceId in appComponents is invalid. Provide a valid resourceId.`};
        }
        resourceId = resourceId.toLowerCase();
        let subscriptionId = getSubscriptionIdFromResourceId(resourceId);
        let resourceType = getResourceTypeFromResourceId(resourceId);
        let name = getResourceNameFromResourceId(resourceId);
        let resourceGroup = getResourceGroupFromResourceId(resourceId);
        if(isNullOrUndefined(resourceGroup) || isNullOrUndefined(subscriptionId) 
            || isNullOrUndefined(resourceType) || isNullOrUndefined(name) 
            || !isValidGUID(subscriptionId)){
            return {valid : false, error : `The value "${resourceId}" for resourceId in appComponents is invalid. Provide a valid resourceId.`};
        }
        if(isInvalidString(appComponentsParsed[i].kind, true)){
            return {valid : false, error : `The value "${appComponentsParsed[i].kind?.toString()}" for kind in appComponents is invalid. Provide a valid string.`};
        }
        if(isInvalidString(appComponentsParsed[i].resourceName, true)){
            return {valid : false, error : `The value "${appComponentsParsed[i].resourceName?.toString()}" for resourceName in appComponents is invalid. Provide a valid string.`};
        }
        let resourceName = appComponentsParsed[i].resourceName || name;
        if(!isNullOrUndefined(appComponentsParsed[i].metrics)) {
            let metrics = appComponentsParsed[i].metrics;
            if(!Array.isArray(metrics)){
                return {valid : false, error : `The value "${metrics?.toString()}" for metrics in the appComponent with resourceName "${resourceName}" is invalid. Provide a valid list of metrics.`};
            }
            for(let metric of metrics){
                if(!isDictionary(metric)){
                    return {valid : false, error : `The value "${metric?.toString()}" for metrics in the appComponent with resourceName "${resourceName}" is invalid. Provide a valid dictionary.`};
                }
                if(metric && isInvalidString(metric.name)){
                    return {valid : false, error : `The value "${metric.name?.toString()}" for name in the appComponent with resourceName "${resourceName}" is invalid. Provide a valid string.`};
                }
                if(isInvalidString(metric.aggregation)){
                    return {valid : false, error : `The value "${metric.aggregation?.toString()}" for aggregation in the appComponent with resourceName "${resourceName}" is invalid. Provide a valid string.`};
                }
                if(isInvalidString(metric.namespace, true)){
                    return {valid : false, error : `The value "${metric.namespace?.toString()}" for namespace in the appComponent with resourceName "${resourceName}" is invalid. Provide a valid string.`};
                }
            }
        } else {
            console.log(`Metrics not provided for the appComponent "${resourceName}", default metrics will be enabled for the same.`);
        }
    }
    return {valid : true, error : ""};
}