コード例 #1
0
        public EventHubsScaleMonitor(
            string functionId,
            string eventHubName,
            string consumerGroup,
            string connectionString,
            string storageConnectionString,
            ILogger logger,
            BlobContainerClient blobContainer = null)
        {
            _functionId              = functionId;
            _eventHubName            = eventHubName;
            _consumerGroup           = consumerGroup;
            _connectionString        = connectionString;
            _storageConnectionString = storageConnectionString;
            _logger = logger;
            _scaleMonitorDescriptor   = new ScaleMonitorDescriptor($"{_functionId}-EventHubTrigger-{_eventHubName}-{_consumerGroup}".ToLowerInvariant());
            _nextPartitionLogTime     = DateTime.UtcNow;
            _nextPartitionWarningTime = DateTime.UtcNow;
            _blobContainer            = blobContainer;

            EventHubsConnectionStringBuilder builder = new EventHubsConnectionStringBuilder(connectionString);

            builder.EntityPath = eventHubName;

            _client = new Lazy <EventHubConsumerClient>(() => new EventHubConsumerClient(EventHubConsumerClient.DefaultConsumerGroupName, builder.ToString()));
        }
コード例 #2
0
        public CosmosDBTriggerListener(ITriggeredFunctionExecutor executor,
                                       string functionId,
                                       DocumentCollectionInfo documentCollectionLocation,
                                       DocumentCollectionInfo leaseCollectionLocation,
                                       ChangeFeedProcessorOptions processorOptions,
                                       ICosmosDBService monitoredCosmosDBService,
                                       ICosmosDBService leasesCosmosDBService,
                                       ILogger logger,
                                       IRemainingWorkEstimator workEstimator = null)
        {
            this._logger     = logger;
            this._executor   = executor;
            this._functionId = functionId;
            this._hostName   = Guid.NewGuid().ToString();

            this._monitorCollection        = documentCollectionLocation;
            this._leaseCollection          = leaseCollectionLocation;
            this._processorOptions         = processorOptions;
            this._monitoredCosmosDBService = monitoredCosmosDBService;
            this._leasesCosmosDBService    = leasesCosmosDBService;
            this._healthMonitor            = new CosmosDBTriggerHealthMonitor(this._logger);

            this._workEstimator = workEstimator;

            this._scaleMonitorDescriptor = new ScaleMonitorDescriptor($"{_functionId}-CosmosDBTrigger-{_monitorCollection.DatabaseName}-{_monitorCollection.CollectionName}".ToLower());
        }
コード例 #3
0
 public ServiceBusScaleMonitor(string functionId, ServiceBusEntityType serviceBusEntityType, string entityPath, string connection, Lazy <ServiceBusReceiver> receiver, ILoggerFactory loggerFactory, ServiceBusClientFactory clientFactory)
 {
     _functionId                   = functionId;
     _serviceBusEntityType         = serviceBusEntityType;
     _entityPath                   = entityPath;
     _scaleMonitorDescriptor       = new ScaleMonitorDescriptor($"{_functionId}-ServiceBusTrigger-{_entityPath}".ToLower(CultureInfo.InvariantCulture));
     _isListeningOnDeadLetterQueue = entityPath.EndsWith(DeadLetterQueuePath, StringComparison.OrdinalIgnoreCase);
     _receiver             = receiver;
     _administrationClient = new Lazy <ServiceBusAdministrationClient>(() => clientFactory.CreateAdministrationClient(connection));
     _logger          = loggerFactory.CreateLogger <ServiceBusScaleMonitor>();
     _nextWarningTime = DateTime.UtcNow;
 }
 public ServiceBusScaleMonitor(string functionId, EntityType entityType, string entityPath, string connectionString, Lazy <MessageReceiver> receiver, ILoggerFactory loggerFactory)
 {
     _functionId                   = functionId;
     _entityType                   = entityType;
     _entityPath                   = entityPath;
     _connectionString             = connectionString;
     _scaleMonitorDescriptor       = new ScaleMonitorDescriptor($"{_functionId}-ServiceBusTrigger-{_entityPath}".ToLower());
     _isListeningOnDeadLetterQueue = entityPath.EndsWith(DeadLetterQueuePath);
     _receiver         = receiver;
     _managementClient = new Lazy <ManagementClient>(() => new ManagementClient(_connectionString));
     _logger           = loggerFactory.CreateLogger <ServiceBusScaleMonitor>();
     _nextWarningTime  = DateTime.UtcNow;
 }
コード例 #5
0
        public EventHubsScaleMonitor(
            string functionId,
            IEventHubConsumerClient client,
            BlobsCheckpointStore checkpointStore,
            ILogger logger)
        {
            _functionId               = functionId;
            _logger                   = logger;
            _checkpointStore          = checkpointStore;
            _nextPartitionLogTime     = DateTime.UtcNow;
            _nextPartitionWarningTime = DateTime.UtcNow;
            _client                   = client;

            Descriptor = new ScaleMonitorDescriptor($"{_functionId}-EventHubTrigger-{_client.EventHubName}-{_client.ConsumerGroup}".ToLowerInvariant());
        }
 public DurableTaskScaleMonitor(
     string functionId,
     FunctionName functionName,
     string hubName,
     string storageConnectionString,
     EndToEndTraceHelper traceHelper,
     DisconnectedPerformanceMonitor performanceMonitor = null)
 {
     this.functionId              = functionId;
     this.functionName            = functionName;
     this.hubName                 = hubName;
     this.storageConnectionString = storageConnectionString;
     this.performanceMonitor      = performanceMonitor;
     this.traceHelper             = traceHelper;
     this.scaleMonitorDescriptor  = new ScaleMonitorDescriptor($"{this.functionId}-DurableTaskTrigger-{this.hubName}".ToLower());
 }
 public RabbitMQListener(
     ITriggeredFunctionExecutor executor,
     IRabbitMQService service,
     string queueName,
     ILogger logger,
     FunctionDescriptor functionDescriptor,
     ushort prefetchCount)
 {
     _executor               = executor;
     _service                = service;
     _queueName              = queueName;
     _logger                 = logger;
     _rabbitMQModel          = _service.RabbitMQModel;
     _functionDescriptor     = functionDescriptor ?? throw new ArgumentNullException(nameof(functionDescriptor));
     _functionId             = functionDescriptor.Id;
     _scaleMonitorDescriptor = new ScaleMonitorDescriptor($"{_functionId}-RabbitMQTrigger-{_queueName}".ToLower());
     _prefetchCount          = prefetchCount;
 }
コード例 #8
0
        public KafkaTopicScaler(string topic, string consumerGroup, string functionId, IConsumer <TKey, TValue> consumer, AdminClientConfig adminClientConfig, ILogger logger)
        {
            if (string.IsNullOrWhiteSpace(topic))
            {
                throw new ArgumentException("Invalid topic", nameof(topic));
            }

            if (string.IsNullOrWhiteSpace(consumerGroup))
            {
                throw new ArgumentException("Invalid consumer group", nameof(consumerGroup));
            }

            this.logger            = logger ?? throw new ArgumentNullException(nameof(logger));
            this.adminClientConfig = adminClientConfig ?? throw new ArgumentNullException(nameof(adminClientConfig));
            this.consumer          = consumer ?? throw new ArgumentNullException(nameof(consumer));
            this.topicName         = topic;
            this.Descriptor        = new ScaleMonitorDescriptor($"{functionId}-kafkatrigger-{topicName}-{consumerGroup}".ToLower());
            this.topicPartitions   = new Lazy <List <TopicPartition> >(LoadTopicPartitions);
            this.consumerGroup     = consumerGroup;
        }
コード例 #9
0
 public EventHubsScaleMonitor(
     string functionId,
     string eventHubName,
     string consumerGroup,
     string connectionString,
     string storageConnectionString,
     ILogger logger,
     CloudBlobContainer blobContainer = null)
 {
     _functionId              = functionId;
     _eventHubName            = eventHubName;
     _consumerGroup           = consumerGroup;
     _connectionString        = connectionString;
     _storageConnectionString = storageConnectionString;
     _logger = logger;
     _scaleMonitorDescriptor   = new ScaleMonitorDescriptor($"{_functionId}-EventHubTrigger-{_eventHubName}-{_consumerGroup}".ToLower());
     _nextPartitionLogTime     = DateTime.UtcNow;
     _nextPartitionWarningTime = DateTime.UtcNow;
     _blobContainer            = blobContainer;
     _client = new Lazy <EventHubClient>(() => EventHubClient.CreateFromConnectionString(ConnectionStringBuilder.ToString()));
 }
コード例 #10
0
        public QueueListener(QueueClient queue,
                             QueueClient poisonQueue,
                             ITriggerExecutor <QueueMessage> triggerExecutor,
                             IWebJobsExceptionHandler exceptionHandler,
                             ILoggerFactory loggerFactory,
                             SharedQueueWatcher sharedWatcher,
                             QueuesOptions queueOptions,
                             QueueProcessor queueProcessor,
                             FunctionDescriptor functionDescriptor,
                             string functionId           = null,
                             TimeSpan?maxPollingInterval = null)
        {
            if (queueOptions == null)
            {
                throw new ArgumentNullException(nameof(queueOptions));
            }

            if (queueProcessor == null)
            {
                throw new ArgumentNullException(nameof(queueProcessor));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (queueOptions.BatchSize <= 0)
            {
                throw new ArgumentException("BatchSize must be greater than zero.");
            }

            if (queueOptions.MaxDequeueCount <= 0)
            {
                throw new ArgumentException("MaxDequeueCount must be greater than zero.");
            }

            _timer              = new TaskSeriesTimer(this, exceptionHandler, Task.Delay(0));
            _queue              = queue;
            _poisonQueue        = poisonQueue;
            _triggerExecutor    = triggerExecutor;
            _exceptionHandler   = exceptionHandler;
            _queueOptions       = queueOptions;
            _logger             = loggerFactory.CreateLogger <QueueListener>();
            _functionDescriptor = functionDescriptor ?? throw new ArgumentNullException(nameof(functionDescriptor));
            _functionId         = functionId ?? _functionDescriptor.Id;

            // if the function runs longer than this, the invisibility will be updated
            // on a timer periodically for the duration of the function execution
            _visibilityTimeout = TimeSpan.FromMinutes(10);

            if (sharedWatcher != null)
            {
                // Call Notify whenever a function adds a message to this queue.
                sharedWatcher.Register(queue.Name, this);
                _sharedWatcher = sharedWatcher;
            }

            _queueProcessor = queueProcessor;

            TimeSpan maximumInterval = _queueProcessor.QueuesOptions.MaxPollingInterval;

            if (maxPollingInterval.HasValue && maximumInterval > maxPollingInterval.Value)
            {
                // enforce the maximum polling interval if specified
                maximumInterval = maxPollingInterval.Value;
            }

            _delayStrategy = new RandomizedExponentialBackoffStrategy(QueuePollingIntervals.Minimum, maximumInterval);

            _scaleMonitorDescriptor          = new ScaleMonitorDescriptor($"{_functionId}-QueueTrigger-{_queue.Name}".ToLower(CultureInfo.InvariantCulture));
            _shutdownCancellationTokenSource = new CancellationTokenSource();
        }
コード例 #11
0
        internal static TableOperation CreateMetricsInsertOperation(ScaleMetrics metrics, string hostId, ScaleMonitorDescriptor descriptor, DateTime?now = null)
        {
            now = now ?? DateTime.UtcNow;

            // Use an inverted ticks rowkey to order the table in descending order, allowing us to easily
            // query for latest logs. Adding a guid as part of the key to ensure uniqueness.
            string rowKey = TableStorageHelpers.GetRowKey(now.Value);

            var entity = TableEntityConverter.ToEntity(metrics, hostId, rowKey, metrics.Timestamp);

            entity.Properties.Add(MonitorIdPropertyName, EntityProperty.GeneratePropertyForString(descriptor.Id));

            // We map the sample timestamp to its own column so it doesn't conflict with the built in column.
            // We want to ensure that timestamp values for returned metrics are precise and monotonically
            // increasing when ordered results are returned. The built in timestamp doesn't guarantee this.
            entity.Properties.Add(SampleTimestampPropertyName, EntityProperty.GeneratePropertyForDateTimeOffset(metrics.Timestamp));

            return(TableOperation.Insert(entity));
        }
コード例 #12
0
 public TestScaleMonitor()
 {
     Index       = 0;
     _descriptor = new ScaleMonitorDescriptor(GetType().Name.ToLower());
 }
コード例 #13
0
 public TestInvalidScaleMonitor()
 {
     _descriptor = new ScaleMonitorDescriptor("testmonitor-invalid");
 }