def load_supported_services(context: LoggingContext, selected_services: List[str]) -> List[GCPService]: working_directory = os.path.dirname(os.path.realpath(__file__)) config_directory = os.path.join(working_directory, "config") config_files = [ file for file in listdir(config_directory) if isfile(os.path.join(config_directory, file)) and is_yaml_file(file) ] services = [] for file in config_files: config_file_path = os.path.join(config_directory, file) try: with open(config_file_path, encoding="utf-8") as config_file: config_yaml = yaml.safe_load(config_file) technology_name = extract_technology_name(config_yaml) for service_yaml in config_yaml.get("gcp", {}): # If whitelist of services exists and current service is not present in it, skip should_skip = selected_services and \ (service_yaml.get("service", "None") not in selected_services) if should_skip: continue services.append(GCPService(tech_name=technology_name, **service_yaml)) except Exception as error: context.log(f"Failed to load configuration file: '{config_file_path}'. Error details: {error}") continue services_names = [service.name for service in services] context.log("Selected services: " + ",".join(services_names)) return services
def load_supported_services(context: LoggingContext) -> List[GCPService]: activation_yaml = read_activation_yaml() activation_config_per_service = get_activation_config_per_service( activation_yaml) feature_sets_from_activation_config = load_activated_feature_sets( context, activation_yaml) working_directory = os.path.dirname(os.path.realpath(__file__)) config_directory = os.path.join(working_directory, "config") config_files = [ file for file in listdir(config_directory) if isfile(os.path.join(config_directory, file)) and is_yaml_file(file) ] services = [] for file in config_files: config_file_path = os.path.join(config_directory, file) try: with open(config_file_path, encoding="utf-8") as config_file: config_yaml = yaml.safe_load(config_file) technology_name = extract_technology_name(config_yaml) for service_yaml in config_yaml.get("gcp", {}): service_name = service_yaml.get("service", "None") featureSet = service_yaml.get("featureSet", "default_metrics") # If whitelist of services exists and current service is not present in it, skip # If whitelist is empty - no services explicitly selected - load all available whitelist_exists = feature_sets_from_activation_config.__len__( ) > 0 if f'{service_name}/{featureSet}' in feature_sets_from_activation_config or not whitelist_exists: activation = activation_config_per_service.get( service_name, {}) services.append( GCPService(tech_name=technology_name, **service_yaml, activation=activation)) except Exception as error: context.log( f"Failed to load configuration file: '{config_file_path}'. Error details: {error}" ) continue featureSets = [ f"{service.name}/{service.feature_set}" for service in services ] if featureSets: context.log("Selected feature sets: " + ", ".join(featureSets)) else: context.log("Empty feature sets. GCP services not monitored.") return services
async def _get_service_configs_for_extension(self, extension_name: str, extension_version: str, activation_config_per_service, feature_sets_from_activation_config) -> (List[GCPService], List): extension_zip = await self._get_extension_zip_from_dynatrace_cluster(extension_name, extension_version) extension_configuration = self._load_extension_config_from_zip(extension_name, extension_zip) if extension_zip else {} if "gcp" not in extension_configuration: self.logging_context.log(f"Incorrect extension fetched from Dynatrace cluster. {extension_name}-{extension_version} has no 'gcp' section and will be skipped") return [] configured_services = [] not_configured_services = [] for service in extension_configuration.get("gcp"): service_name = service.get('service') feature_set = f"{service_name}/{service.get('featureSet')}" if feature_set in feature_sets_from_activation_config: activation = activation_config_per_service.get(service_name, {}) configured_services.append(GCPService(**service, activation=activation)) else: not_configured_services.append(feature_set) return configured_services, not_configured_services