예제 #1
0
        /// <summary>
        /// Performs all required initialization on the host.
        /// Must be called before the host is started.
        /// </summary>
        public async Task InitializeAsync(CancellationToken cancellationToken = default)
        {
            _stopwatch.Start();
            using (_metricsLogger.LatencyEvent(MetricEventNames.HostStartupLatency))
            {
                PreInitialize();
                HostInitializing?.Invoke(this, EventArgs.Empty);

                // Generate Functions
                IEnumerable <FunctionMetadata> functionMetadataList = GetFunctionsMetadata();

                _workerRuntime = _workerRuntime ?? Utility.GetWorkerRuntime(functionMetadataList);

                if (!_environment.IsPlaceholderModeEnabled())
                {
                    // Appending the runtime version is currently only enabled for linux consumption.
                    // This will be eventually enabled for Windows Consumption as well.
                    string runtimeStack = GetPreciseRuntimeStack(_workerRuntime);
                    _metricsLogger.LogEvent(string.Format(MetricEventNames.HostStartupRuntimeLanguage, runtimeStack));
                }

                var directTypes = GetDirectTypes(functionMetadataList);
                await InitializeFunctionDescriptorsAsync(functionMetadataList);

                // Initialize worker function invocation dispatcher only for valid functions after creating function descriptors
                await _functionDispatcher.InitializeAsync(Utility.GetValidFunctions(functionMetadataList, Functions), cancellationToken);

                GenerateFunctions(directTypes);

                CleanupFileSystem();
            }
        }
예제 #2
0
        /// <summary>
        /// Performs all required initialization on the host.
        /// Must be called before the host is started.
        /// </summary>
        public async Task InitializeAsync()
        {
            _stopwatch.Start();
            using (_metricsLogger.LatencyEvent(MetricEventNames.HostStartupLatency))
            {
                PreInitialize();
                HostInitializing?.Invoke(this, EventArgs.Empty);

                // Generate Functions
                IEnumerable <FunctionMetadata> functions = GetFunctionsMetadata();

                _workerRuntime = _workerRuntime ?? Utility.GetWorkerRuntime(functions);

                if (!_environment.IsPlaceholderModeEnabled())
                {
                    _metricsLogger.LogEvent(string.Format(MetricEventNames.HostStartupRuntimeLanguage, _workerRuntime));
                }

                // Initialize language worker function dispatcher
                await _functionDispatcher.InitializeAsync(functions);

                var directTypes = GetDirectTypes(functions);
                await InitializeFunctionDescriptorsAsync(functions);

                GenerateFunctions(directTypes);

                CleanupFileSystem();
            }
        }
예제 #3
0
        /// <summary>
        /// Performs all required initialization on the host.
        /// Must be called before the host is started.
        /// </summary>
        public async Task InitializeAsync(CancellationToken cancellationToken = default)
        {
            _stopwatch = ValueStopwatch.StartNew();
            using (_metricsLogger.LatencyEvent(MetricEventNames.HostStartupLatency))
            {
                PreInitialize();
                HostInitializing?.Invoke(this, EventArgs.Empty);

                _workerRuntime = _workerRuntime ?? _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);

                // get worker config information and check to see if worker should index or not
                var workerConfigs = _languageWorkerOptions.Value.WorkerConfigs;

                bool workerIndexing = Utility.CanWorkerIndex(workerConfigs, _environment);

                // Generate Functions
                IEnumerable <FunctionMetadata> functionMetadataList = GetFunctionsMetadata(workerIndexing);

                if (!_environment.IsPlaceholderModeEnabled())
                {
                    string runtimeStack = _workerRuntime;

                    if (!string.IsNullOrEmpty(runtimeStack))
                    {
                        // Appending the runtime version is currently only enabled for linux consumption. This will be eventually enabled for
                        // Windows Consumption as well.
                        string runtimeVersion = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName);

                        if (!string.IsNullOrEmpty(runtimeVersion))
                        {
                            runtimeStack = string.Concat(runtimeStack, "-", runtimeVersion);
                        }
                    }

                    _metricsLogger.LogEvent(string.Format(MetricEventNames.HostStartupRuntimeLanguage, Sanitizer.Sanitize(runtimeStack)));

                    Utility.LogAutorestGeneratedJsonIfExists(ScriptOptions.RootScriptPath, _logger);
                }

                IsFunctionDataCacheEnabled = GetIsFunctionDataCacheEnabled();

                await InitializeFunctionDescriptorsAsync(functionMetadataList, cancellationToken);

                if (!workerIndexing)
                {
                    // Initialize worker function invocation dispatcher only for valid functions after creating function descriptors
                    // Dispatcher not needed for codeless function.
                    // Disptacher needed for non-dotnet codeless functions
                    var filteredFunctionMetadata = functionMetadataList.Where(m => !Utility.IsCodelessDotNetLanguageFunction(m));
                    await _functionDispatcher.InitializeAsync(Utility.GetValidFunctions(filteredFunctionMetadata, Functions), cancellationToken);
                }

                GenerateFunctions();
                ScheduleFileSystemCleanup();
            }
        }
        public async Task <ImmutableArray <FunctionMetadata> > GetFunctionMetadataAsync(IEnumerable <RpcWorkerConfig> workerConfigs, IEnvironment environment, bool forceRefresh)
        {
            IEnumerable <FunctionMetadata> functions = new List <FunctionMetadata>();

            _logger.FunctionMetadataProviderParsingFunctions();

            if (_functions.IsDefaultOrEmpty || forceRefresh)
            {
                IEnumerable <RawFunctionMetadata> rawFunctions = new List <RawFunctionMetadata>();
                bool workerIndexing = Utility.CanWorkerIndex(workerConfigs, environment);

                if (workerIndexing)
                {
                    if (_dispatcher == null)
                    {
                        throw new InvalidOperationException(nameof(_dispatcher));
                    }

                    // start up GRPC channels
                    await _dispatcher.InitializeAsync(new List <FunctionMetadata>());

                    // get function metadata from worker, then validate it
                    rawFunctions = await _dispatcher.GetWorkerMetadata();

                    if (IsDefaultIndexingRequired(rawFunctions))
                    {
                        _logger.LogDebug("Fallback to host indexing as worker denied indexing");
                        functions = await _hostFunctionMetadataProvider.GetFunctionMetadataAsync(workerConfigs, environment, forceRefresh);
                    }
                    else if (!IsNullOrEmpty(rawFunctions))
                    {
                        functions = ValidateMetadata(rawFunctions);
                    }

                    // set up invocation buffers and send load requests
                    await _dispatcher.FinishInitialization(functions);

                    // Validate if the app has functions in legacy format and add in logs to inform about the mixed app
                    _ = Task.Delay(TimeSpan.FromMinutes(1)).ContinueWith(t => ValidateFunctionAppFormat(_scriptOptions.Value.RootScriptPath, _logger, environment));
                }
                else
                {
                    functions = await _hostFunctionMetadataProvider.GetFunctionMetadataAsync(workerConfigs, environment, forceRefresh);
                }
            }
            _functions = functions.ToImmutableArray();
            _logger.FunctionMetadataProviderFunctionFound(_functions.IsDefault ? 0 : _functions.Count());
            return(_functions);
        }
        /// <summary>
        /// Performs all required initialization on the host.
        /// Must be called before the host is started.
        /// </summary>
        public async Task InitializeAsync(CancellationToken cancellationToken = default)
        {
            _stopwatch.Start();
            using (_metricsLogger.LatencyEvent(MetricEventNames.HostStartupLatency))
            {
                PreInitialize();
                HostInitializing?.Invoke(this, EventArgs.Empty);

                // Generate Functions
                IEnumerable <FunctionMetadata> functionMetadataList = GetFunctionsMetadata();

                _workerRuntime = _workerRuntime ?? Utility.GetWorkerRuntime(functionMetadataList);

                if (!_environment.IsPlaceholderModeEnabled())
                {
                    string runtimeStack = _workerRuntime;

                    if (!string.IsNullOrEmpty(runtimeStack))
                    {
                        // Appending the runtime version is currently only enabled for linux consumption. This will be eventually enabled for
                        // Windows Consumption as well.
                        string runtimeVersion = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName);

                        if (!string.IsNullOrEmpty(runtimeVersion))
                        {
                            runtimeStack = string.Concat(runtimeStack, "-", runtimeVersion);
                        }
                    }

                    _metricsLogger.LogEvent(string.Format(MetricEventNames.HostStartupRuntimeLanguage, runtimeStack));

                    Utility.LogAutorestGeneratedJsonIfExists(ScriptOptions.RootScriptPath, _logger);
                }

                var directTypes = GetDirectTypes(functionMetadataList);
                await InitializeFunctionDescriptorsAsync(functionMetadataList, cancellationToken);

                // Initialize worker function invocation dispatcher only for valid functions after creating function descriptors
                // Dispatcher not needed for non-proxy codeless function.
                // Disptacher needed for non-dotnet codeless functions
                var filteredFunctionMetadata = functionMetadataList.Where(m => m.IsProxy() || !Utility.IsCodelessDotNetLanguageFunction(m));
                await _functionDispatcher.InitializeAsync(Utility.GetValidFunctions(filteredFunctionMetadata, Functions), cancellationToken);

                GenerateFunctions(directTypes);

                ScheduleFileSystemCleanup();
            }
        }