コード例 #1
0
        public WebScriptHostManager(ScriptHostConfiguration config, ISecretManagerFactory secretManagerFactory, ScriptSettingsManager settingsManager, WebHostSettings webHostSettings, IScriptHostFactory scriptHostFactory = null, ISecretsRepositoryFactory secretsRepositoryFactory = null)
            : base(config, settingsManager, scriptHostFactory)
        {
            _config           = config;
            _metricsLogger    = new WebHostMetricsLogger();
            _exceptionHandler = new WebScriptHostExceptionHandler(this);
            _webHostSettings  = webHostSettings;

            var systemEventGenerator = config.HostConfig.GetService <IEventGenerator>() ?? new EventGenerator();
            var systemTraceWriter    = new SystemTraceWriter(systemEventGenerator, settingsManager, TraceLevel.Verbose);

            if (config.TraceWriter != null)
            {
                config.TraceWriter = new CompositeTraceWriter(new TraceWriter[] { config.TraceWriter, systemTraceWriter });
            }
            else
            {
                config.TraceWriter = systemTraceWriter;
            }

            config.IsSelfHost = webHostSettings.IsSelfHost;

            _performanceManager     = new HostPerformanceManager(settingsManager, config.TraceWriter);
            _swaggerDocumentManager = new SwaggerDocumentManager(config);

            var secretsRepository = secretsRepositoryFactory.Create(settingsManager, webHostSettings, config);

            _secretManager = secretManagerFactory.Create(settingsManager, config.TraceWriter, secretsRepository);
        }
コード例 #2
0
        public MetricsEventManagerTests()
        {
            _functionExecutionEventArguments = new List <FunctionExecutionEventArguments>();

            var mockEventGenerator = new Mock <IEventGenerator>();

            mockEventGenerator.Setup(e => e.LogFunctionExecutionEvent(
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <int>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <long>(),
                                         It.IsAny <bool>()))
            .Callback((string executionId, string siteName, int concurrency, string functionName, string invocationId, string executionStage, long executionTimeSpan, bool success) =>
            {
                _functionExecutionEventArguments.Add(new FunctionExecutionEventArguments(executionId, siteName, concurrency, functionName, invocationId, executionStage, executionTimeSpan, success));
            });

            _events = new List <SystemMetricEvent>();
            mockEventGenerator.Setup(p => p.LogFunctionMetricEvent(
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <long>(),
                                         It.IsAny <long>(),
                                         It.IsAny <long>(),
                                         It.IsAny <long>(),
                                         It.IsAny <DateTime>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>()))
            .Callback((string subscriptionId, string appName, string functionName, string eventName, long average, long min, long max, long count, DateTime eventTimestamp, string data, string runtimeSiteName, string slotName) =>
            {
                var evt = new SystemMetricEvent
                {
                    FunctionName    = functionName,
                    EventName       = eventName,
                    Average         = average,
                    Minimum         = min,
                    Maximum         = max,
                    Count           = count,
                    Data            = data,
                    RuntimeSiteName = runtimeSiteName,
                    SlotName        = slotName
                };
                _events.Add(evt);
            });

            var mockMetricsPublisher  = new Mock <IMetricsPublisher>();
            var testAppServiceOptions = new Mock <IOptionsMonitor <AppServiceOptions> >();

            testAppServiceOptions.Setup(a => a.CurrentValue).Returns(new AppServiceOptions {
                AppName = "RandomAppName", SubscriptionId = Guid.NewGuid().ToString()
            });
            _metricsEventManager = new MetricsEventManager(testAppServiceOptions.Object, mockEventGenerator.Object, MinimumLongRunningDurationInMs / 1000, mockMetricsPublisher.Object);
            _metricsLogger       = new WebHostMetricsLogger(_metricsEventManager);
        }
コード例 #3
0
        public WebScriptHostManager(ScriptHostConfiguration config,
                                    ISecretManagerFactory secretManagerFactory,
                                    IScriptEventManager eventManager,
                                    ScriptSettingsManager settingsManager,
                                    WebHostSettings webHostSettings,
                                    IWebJobsRouter router,
                                    ILoggerFactory loggerFactory,
                                    IScriptHostFactory scriptHostFactory = null,
                                    ISecretsRepositoryFactory secretsRepositoryFactory = null,
                                    HostPerformanceManager hostPerformanceManager      = null,
                                    ILoggerProviderFactory loggerProviderFactory       = null,
                                    int hostTimeoutSeconds = 30,
                                    int hostPollingIntervalMilliseconds = 500)
            : base(config, settingsManager, scriptHostFactory, eventManager, environment: null,
                   hostPerformanceManager: hostPerformanceManager, loggerProviderFactory: loggerProviderFactory)
        {
            _config = config;

            _metricsLogger      = new WebHostMetricsLogger();
            _exceptionHandler   = new WebScriptHostExceptionHandler(this);
            _webHostSettings    = webHostSettings;
            _settingsManager    = settingsManager;
            _hostTimeoutSeconds = hostTimeoutSeconds;
            _hostRunningPollIntervalMilliseconds = hostPollingIntervalMilliseconds;
            _router = router;

            config.IsSelfHost = webHostSettings.IsSelfHost;

            secretsRepositoryFactory = secretsRepositoryFactory ?? new DefaultSecretsRepositoryFactory();
            var secretsRepository = secretsRepositoryFactory.Create(settingsManager, webHostSettings, config);

            _secretManager = secretManagerFactory.Create(settingsManager, loggerFactory.CreateLogger(ScriptConstants.LogCategoryHostGeneral), secretsRepository);

            _bindingWebHookProvider = new WebJobsSdkExtensionHookProvider(_secretManager);
        }
コード例 #4
0
 protected void Application_Start()
 {
     using (var metricsLogger = new WebHostMetricsLogger())
         using (metricsLogger.LatencyEvent(MetricEventNames.ApplicationStartLatency))
         {
             GlobalConfiguration.Configure(c => WebApiConfig.Initialize(c));
         }
 }
コード例 #5
0
        public MetricsEventManagerTests()
        {
            _functionExecutionEventArguments = new List <FunctionExecutionEventArguments>();

            var mockEventGenerator = new Mock <IEventGenerator>();

            mockEventGenerator.Setup(e => e.LogFunctionExecutionEvent(
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <int>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <long>(),
                                         It.IsAny <bool>()))
            .Callback((string executionId, string siteName, int concurrency, string functionName, string invocationId, string executionStage, long executionTimeSpan, bool success) =>
            {
                _functionExecutionEventArguments.Add(new FunctionExecutionEventArguments(executionId, siteName, concurrency, functionName, invocationId, executionStage, executionTimeSpan, success));
            });

            _events = new List <SystemMetricEvent>();
            mockEventGenerator.Setup(p => p.LogFunctionMetricEvent(
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <long>(),
                                         It.IsAny <long>(),
                                         It.IsAny <long>(),
                                         It.IsAny <long>(),
                                         It.IsAny <DateTime>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>()))
            .Callback((string subscriptionId, string appName, string functionName, string eventName, long average, long min, long max, long count, DateTime eventTimestamp, string data, string runtimeSiteName) =>
            {
                var evt = new SystemMetricEvent
                {
                    FunctionName    = functionName,
                    EventName       = eventName,
                    Average         = average,
                    Minimum         = min,
                    Maximum         = max,
                    Count           = count,
                    Data            = data,
                    RuntimeSiteName = runtimeSiteName
                };
                _events.Add(evt);
            });

            var mockMetricsPublisher = new Mock <IMetricsPublisher>();

            _metricsEventManager = new MetricsEventManager(new TestEnvironment(), mockEventGenerator.Object, MinimumLongRunningDurationInMs / 1000, mockMetricsPublisher.Object);
            _metricsLogger       = new WebHostMetricsLogger(_metricsEventManager);
        }
コード例 #6
0
        private async Task TestFunction(string name, Guid invocationId, WebHostMetricsLogger metricsLogger, TimeSpan waitTimeSpan)
        {
            var functionMetadata = new FunctionMetadata
            {
                Name = name
            };
            var functionEvent = new FunctionStartedEvent(invocationId, functionMetadata);

            metricsLogger.BeginEvent(functionEvent);
            await Task.Delay(waitTimeSpan);

            metricsLogger.EndEvent(functionEvent);
        }
コード例 #7
0
        protected void Application_Start()
        {
            var settingsManager = ScriptSettingsManager.Instance;
            var webHostSettings = WebHostSettings.CreateDefault(settingsManager);

            VerifyAndEnableShadowCopy(webHostSettings);

            using (var metricsLogger = new WebHostMetricsLogger())
                using (metricsLogger.LatencyEvent(MetricEventNames.ApplicationStartLatency))
                {
                    GlobalConfiguration.Configure(c => WebApiConfig.Initialize(c, settingsManager, webHostSettings));
                }
        }
コード例 #8
0
        protected void Application_Start()
        {
            using (var metricsLogger = new WebHostMetricsLogger())
                using (metricsLogger.LatencyEvent(MetricEventNames.ApplicationStartLatency))
                {
                    GlobalConfiguration.Configure(c => WebApiConfig.Register(c));

                    var scriptHostManager = GlobalConfiguration.Configuration.DependencyResolver.GetService <WebScriptHostManager>();

                    if (scriptHostManager != null && !scriptHostManager.Initialized)
                    {
                        scriptHostManager.Initialize();
                    }
                }
        }
コード例 #9
0
        public MetricsEventManagerTests()
        {
            _settingsManager = ScriptSettingsManager.Instance;
            _functionExecutionEventArguments = new List <FunctionExecutionEventArguments>();

            var mockEventGenerator = new Mock <IEventGenerator>();

            mockEventGenerator.Setup(e => e.LogFunctionExecutionEvent(
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <int>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <long>(),
                                         It.IsAny <bool>()))
            .Callback((string executionId, string siteName, int concurrency, string functionName, string invocationId, string executionStage, long executionTimeSpan, bool success) =>
            {
                _functionExecutionEventArguments.Add(new FunctionExecutionEventArguments(executionId, siteName, concurrency, functionName, invocationId, executionStage, executionTimeSpan, success));
            });

            _events = new List <SystemMetricEvent>();
            mockEventGenerator.Setup(p => p.LogFunctionMetricEvent(
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <long>(),
                                         It.IsAny <long>(),
                                         It.IsAny <long>(),
                                         It.IsAny <long>()))
            .Callback((string subscriptionId, string appName, string eventName, long average, long min, long max, long count) =>
            {
                var evt = new SystemMetricEvent
                {
                    EventName = eventName,
                    Average   = average,
                    Minimum   = min,
                    Maximum   = max,
                    Count     = count
                };
                _events.Add(evt);
            });

            _metricsEventManager = new MetricsEventManager(_settingsManager, mockEventGenerator.Object, MinimumLongRunningDurationInMs / 1000);
            _metricsLogger       = new WebHostMetricsLogger(_metricsEventManager);
        }
コード例 #10
0
        public WebScriptHostManager(ScriptHostConfiguration config,
                                    ISecretManagerFactory secretManagerFactory,
                                    IScriptEventManager eventManager,
                                    ScriptSettingsManager settingsManager,
                                    WebHostSettings webHostSettings,
                                    IWebJobsRouter router,
                                    IScriptHostFactory scriptHostFactory = null,
                                    ISecretsRepositoryFactory secretsRepositoryFactory = null,
                                    ILoggerFactoryBuilder loggerFactoryBuilder         = null,
                                    HostPerformanceManager hostPerformanceManager      = null,
                                    int hostTimeoutSeconds = 30,
                                    int hostPollingIntervalMilliseconds = 500)
            : base(config, settingsManager, scriptHostFactory, eventManager, environment: null, loggerFactoryBuilder: loggerFactoryBuilder, hostPerformanceManager: hostPerformanceManager)
        {
            _config = config;

            _metricsLogger      = new WebHostMetricsLogger();
            _exceptionHandler   = new WebScriptHostExceptionHandler(this);
            _webHostSettings    = webHostSettings;
            _hostTimeoutSeconds = hostTimeoutSeconds;
            _hostRunningPollIntervalMilliseconds = hostPollingIntervalMilliseconds;
            _router = router;

            var systemEventGenerator = config.HostConfig.GetService <IEventGenerator>() ?? new EventGenerator();
            var systemTraceWriter    = new SystemTraceWriter(systemEventGenerator, settingsManager, TraceLevel.Verbose);

            if (config.TraceWriter != null)
            {
                config.TraceWriter = new CompositeTraceWriter(new TraceWriter[] { config.TraceWriter, systemTraceWriter });
            }
            else
            {
                config.TraceWriter = systemTraceWriter;
            }

            config.IsSelfHost = webHostSettings.IsSelfHost;

            secretsRepositoryFactory = secretsRepositoryFactory ?? new DefaultSecretsRepositoryFactory();
            var secretsRepository = secretsRepositoryFactory.Create(settingsManager, webHostSettings, config);

            _secretManager = secretManagerFactory.Create(settingsManager, config.HostConfig.LoggerFactory, secretsRepository);

            _bindingWebHookProvider = new WebJobsSdkExtensionHookProvider(_secretManager);
        }
コード例 #11
0
        protected void Application_Start()
        {
            var settingsManager = ScriptSettingsManager.Instance;
            var webHostSettings = WebHostSettings.CreateDefault(settingsManager);

            if (settingsManager.IsDynamicSku)
            {
                ServicePointManager.DefaultConnectionLimit = ScriptConstants.DynamicSkuConnectionLimit;
            }

            ConfigureMinimumThreads(settingsManager.IsDynamicSku);
            VerifyAndEnableShadowCopy(webHostSettings);

            using (var metricsLogger = new WebHostMetricsLogger())
                using (metricsLogger.LatencyEvent(MetricEventNames.ApplicationStartLatency))
                {
                    GlobalConfiguration.Configure(c => WebApiConfig.Initialize(c, settingsManager, webHostSettings));
                }
        }
コード例 #12
0
        public WebScriptHostManager(ScriptHostConfiguration config, ISecretManager secretManager, WebHostSettings webHostSettings, IScriptHostFactory scriptHostFactory = null)
            : base(config, scriptHostFactory)
        {
            _config           = config;
            _metricsLogger    = new WebHostMetricsLogger();
            _exceptionHandler = new WebScriptHostExceptionHandler(this);
            _secretManager    = secretManager;
            _webHostSettings  = webHostSettings;

            var systemEventGenerator = config.HostConfig.GetService <IEventGenerator>() ?? new EventGenerator();
            var systemTraceWriter    = new SystemTraceWriter(systemEventGenerator, TraceLevel.Verbose);

            if (config.TraceWriter != null)
            {
                config.TraceWriter = new CompositeTraceWriter(new TraceWriter[] { config.TraceWriter, systemTraceWriter });
            }
            else
            {
                config.TraceWriter = systemTraceWriter;
            }
        }
コード例 #13
0
 private async Task TestFunction(WebHostMetricsLogger metricsLogger, TimeSpan waitTimeSpan)
 {
     await TestFunction(Guid.NewGuid().ToString(), Guid.NewGuid(), metricsLogger, waitTimeSpan);
 }
コード例 #14
0
        private async Task ShortTestFunction(WebHostMetricsLogger metricsLogger)
        {
            var randomMilliSeconds = _randomNumberGenerator.Next(0, 10);

            await TestFunction(Guid.NewGuid().ToString(), Guid.NewGuid(), metricsLogger, TimeSpan.FromMilliseconds(randomMilliSeconds));
        }
コード例 #15
0
        private async Task LongTestFunction(WebHostMetricsLogger metricsLogger)
        {
            var randomMilliSeconds = _randomNumberGenerator.Next(MinimumRandomValueForLongRunningDurationInMs, MinimumRandomValueForLongRunningDurationInMs * 4);

            await TestFunction(Guid.NewGuid().ToString(), Guid.NewGuid(), metricsLogger, TimeSpan.FromMilliseconds(randomMilliSeconds));
        }
コード例 #16
0
        public async Task MetricsEventManager_ActivityTimer_HandlesExceptions()
        {
            // create a local event manager for this test, so we can override the flush interval
            var logger = _loggerFactory.CreateLogger <MetricsEventManager>();
            var metricsEventManager = new MetricsEventManager(_mockAppServiceOptions.Object, _mockEventGenerator.Object, 1, _mockEventPublisher.Object, _linuxFunctionExecutionActivityPublisher.Object, logger);
            var metricsLogger       = new WebHostMetricsLogger(metricsEventManager);

            // execute some functions
            var taskList = new List <Task>();

            for (int currentIndex = 0; currentIndex < 10; currentIndex++)
            {
                taskList.Add(ShortTestFunction(metricsLogger));
            }
            await Task.WhenAll(taskList);

            // wait for a flush to occur
            await Task.Delay(1000);

            // verify events
            Assert.Equal(10, _functionExecutionEventArguments.Count);
            Assert.True(_functionExecutionEventArguments.All(p => p.ExecutionStage == ExecutionStage.Finished.ToString()));

            // now force a logging error for an in progress function
            // on the background timer
            _throwOnExecutionEvent = true;
            var id = Guid.NewGuid();
            var functionMetadata = new FunctionMetadata
            {
                Name = "Test"
            };
            var functionEvent = new FunctionStartedEvent(id, functionMetadata);

            metricsLogger.BeginEvent(functionEvent);

            // wait for the error to be logged
            LogMessage errorLog = null;
            await TestHelpers.Await(() =>
            {
                errorLog = _testLoggerProvider.GetAllLogMessages().SingleOrDefault();
                return(errorLog != null);
            }, timeout : 5000);

            // verify error was logged
            Assert.Equal(LogLevel.Error, errorLog.Level);
            Assert.Equal("Error occurred when logging function activity", errorLog.FormattedMessage);

            // execute some more functions, verifying that the timer is
            // still running
            taskList = new List <Task>();
            for (int currentIndex = 0; currentIndex < 10; currentIndex++)
            {
                taskList.Add(ShortTestFunction(metricsLogger));
            }
            await Task.WhenAll(taskList);

            await Task.Delay(1000);

            // verify events
            Assert.Equal(20, _functionExecutionEventArguments.Count(p => p.ExecutionStage == ExecutionStage.Finished.ToString()));
            int inProgressCount = _functionExecutionEventArguments.Count(p => p.InvocationId == id.ToString() && p.ExecutionStage == ExecutionStage.InProgress.ToString());

            Assert.True(inProgressCount > 0);
        }
コード例 #17
0
        public MetricsEventManagerTests()
        {
            _loggerFactory      = new LoggerFactory();
            _testLoggerProvider = new TestLoggerProvider();
            _loggerFactory.AddProvider(_testLoggerProvider);

            _functionExecutionEventArguments = new List <FunctionExecutionEventArguments>();

            _mockEventGenerator = new Mock <IEventGenerator>();
            _mockEventGenerator.Setup(e => e.LogFunctionExecutionEvent(
                                          It.IsAny <string>(),
                                          It.IsAny <string>(),
                                          It.IsAny <int>(),
                                          It.IsAny <string>(),
                                          It.IsAny <string>(),
                                          It.IsAny <string>(),
                                          It.IsAny <long>(),
                                          It.IsAny <bool>()))
            .Callback((string executionId, string siteName, int concurrency, string functionName, string invocationId, string executionStage, long executionTimeSpan, bool success) =>
            {
                if (_throwOnExecutionEvent && executionStage == ExecutionStage.InProgress.ToString())
                {
                    _throwOnExecutionEvent = false;
                    throw new Exception("Kaboom!");
                }

                lock (_syncLock)
                {
                    _functionExecutionEventArguments.Add(new FunctionExecutionEventArguments(executionId, siteName, concurrency, functionName, invocationId, executionStage, executionTimeSpan, success));
                }
            });

            _events = new List <SystemMetricEvent>();
            _mockEventGenerator.Setup(p => p.LogFunctionMetricEvent(
                                          It.IsAny <string>(),
                                          It.IsAny <string>(),
                                          It.IsAny <string>(),
                                          It.IsAny <string>(),
                                          It.IsAny <long>(),
                                          It.IsAny <long>(),
                                          It.IsAny <long>(),
                                          It.IsAny <long>(),
                                          It.IsAny <DateTime>(),
                                          It.IsAny <string>(),
                                          It.IsAny <string>(),
                                          It.IsAny <string>()))
            .Callback((string subscriptionId, string appName, string functionName, string eventName, long average, long min, long max, long count, DateTime eventTimestamp, string data, string runtimeSiteName, string slotName) =>
            {
                var evt = new SystemMetricEvent
                {
                    FunctionName    = functionName,
                    EventName       = eventName,
                    Average         = average,
                    Minimum         = min,
                    Maximum         = max,
                    Count           = count,
                    Data            = data,
                    RuntimeSiteName = runtimeSiteName,
                    SlotName        = slotName
                };
                lock (_syncLock)
                {
                    _events.Add(evt);
                }
            });

            _mockEventPublisher    = new Mock <IMetricsPublisher>();
            _mockAppServiceOptions = new Mock <IOptionsMonitor <AppServiceOptions> >();
            _mockAppServiceOptions.Setup(a => a.CurrentValue).Returns(new AppServiceOptions {
                AppName = "RandomAppName", SubscriptionId = Guid.NewGuid().ToString()
            });
            _linuxFunctionExecutionActivityPublisher = new Mock <ILinuxContainerActivityPublisher>();
            var logger = _loggerFactory.CreateLogger <MetricsEventManager>();

            _metricsEventManager = new MetricsEventManager(_mockAppServiceOptions.Object, _mockEventGenerator.Object, MinimumLongRunningDurationInMs / 1000, _mockEventPublisher.Object, _linuxFunctionExecutionActivityPublisher.Object, logger);
            _metricsLogger       = new WebHostMetricsLogger(_metricsEventManager);
        }