Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the type
        /// </summary>
        /// <param name="logger">The logger to write debugging and diagnostics information to</param>
        /// <param name="metricFactory">The factory to create metric recorders from</param>
        /// <param name="consumerGroupName">The name of the consumer group that the processor is associated with</param>
        /// <param name="storageAccount">The storage account used to access the Azure BLOB store</param>
        /// <param name="containerName">The name of the container that the BLOBs are contained in</param>
        /// <param name="subContainerPrefix">The prefix for the BLOB container</param>
        public AzureStorageEpochRecorder(ILogger logger, IMetricFactory metricFactory, string consumerGroupName, CloudStorageAccount storageAccount, string containerName, string subContainerPrefix)
        {
            Guard.NotNullOrWhitespace(nameof(consumerGroupName), consumerGroupName);
            Guard.NotNull(nameof(storageAccount), storageAccount);
            Guard.NotNull(nameof(logger), logger);
            AzureBlobCommon.ValidContainerName(nameof(containerName), containerName);

            _logger = logger;

            using (_logger.BeginScope("Azure Storage Lease Manager::ctor"))
            {
                _logger.LogInformation("Creating Azure lease manager for consumer group {consumerGroupName}, container {containerName}", containerName, consumerGroupName);

                subContainerPrefix = (subContainerPrefix != null) ? subContainerPrefix.Trim() : "";

                var storageClient = storageAccount.CreateCloudBlobClient();

                storageClient.DefaultRequestOptions = new BlobRequestOptions {
                    MaximumExecutionTime = TimeSpan.FromSeconds(60)
                };
                _epochStoreContainer    = storageClient.GetContainerReference(containerName);
                _consumerGroupDirectory = _epochStoreContainer.GetDirectoryReference($"{subContainerPrefix}{consumerGroupName}");

                _epochReadCounter          = metricFactory.CreateCounter("aer-checkpoint-read", "The number of times that the Azure Storage epoch recorder has read the epoch", false, new string[0]);
                _epochUpdateCounter        = metricFactory.CreateCounter("aer-checkpoint-update", "The number of times that the Azure Storage epoch recorder has updated the epoch", false, new string[0]);
                _epochErrorCounter         = metricFactory.CreateCounter("aer-checkpoint-error", "The number of times that the Azure Storage epoch recorder has errors raised", false, new string[0]);
                _storagePerformanceSummary = metricFactory.CreateSummary("aer-storage-timing", "The duration taken to access Azure Storage to perform checkpoint recorder operations", 10, false, new string[0]);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Configures the basic information associated with the instance, including metrics setup
        /// </summary>
        /// <param name="logger">The logger to write debugging and diagnostics information to</param>
        /// <param name="metricFactory">The metrics factory used to create metrics containers from</param>
        private void ConfigureInstance(ILogger logger, IMetricFactory metricFactory)
        {
            Guard.NotNull(nameof(logger), logger);
            Guard.NotNull(nameof(metricFactory), metricFactory);

            Logger        = logger;
            MetricFactory = metricFactory;

            using (logger.BeginScope("Configuring Instance"))
            {
                Logger.LogInformation("Beginning Configuring instance");
                _testCounter      = metricFactory.CreateCounter("bpm-test-count", "The number of times the poisoned message test has beene executed since the start of the instance.", false, new string[0]);
                _updateCounter    = metricFactory.CreateCounter("bpm-update-count", "The number of times the poisoned message store has been updated since the start of the instance.", false, new string[0]);
                _updateBlobTiming = metricFactory.CreateSummary("bspm-update-timing", "The timing of the calls to the Azure Storage for updating the poisoned message values", 10, false, new string[0]);
                _readBlobTiming   = metricFactory.CreateSummary("bspm-read-timing", "The timing of the calls to the Azure Storage for reading the poisoned message values", 10, false, new string[0]);
                Logger.LogInformation("Finished Configuring instance");
            }
        }
        /// <summary>
        /// Initializes a new instance of the type
        /// </summary>
        /// <param name="logger">The logger to write debugging and diagnostics information to</param>
        /// <param name="metricFactory">The factory to create metrics containers from.</param>
        /// <param name="partitionId">The identifier of the partition that the context represents.</param>
        /// <param name="readLastEnqueuedEventProperties">A function that can be used to read the last enqueued event properties for the partition.</param>
        /// <param name="checkpointManager">The checkpoint manager to used to create the checkpoint</param>
        internal ProcessorPartitionContext(ILogger logger, IMetricFactory metricFactory, string partitionId, LastPropertiesReader readLastEnqueuedEventProperties, ICheckpointManager checkpointManager) : base(partitionId)
        {
            _logger            = logger;
            _checkpointManager = checkpointManager;
            _readLastEnqueuedEventProperties = readLastEnqueuedEventProperties;

            _checkpointCounter = metricFactory.CreateCounter($"ppc-checkpoint-counter-{partitionId}", $"The number of times that the checkpoint has been called for partition {partitionId}", false, new string[0]);
            _checkpointTiming  = metricFactory.CreateSummary($"ppc-checkpoint-timing-{partitionId}", $"The time taken to perform checkpoints for partition {partitionId}", 10, false, new string[0]);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Configures the basic information associated with the instance, including metrics setup
        /// </summary>
        /// <param name="logger">The logger to write debugging and diagnostics information to</param>
        /// <param name="metricFactory">The metrics factory used to create metrics containers from</param>
        private void ConfigureInstance(ILogger logger, IMetricFactory metricFactory)
        {
            Guard.NotNull(nameof(logger), logger);
            Guard.NotNull(nameof(metricFactory), metricFactory);

            Logger        = logger;
            MetricFactory = metricFactory;


            using (logger.BeginScope("Configuring Instance"))
            {
                Logger.LogInformation("Beginning Configuring instance");
                _listCheckpointsCounter  = metricFactory.CreateCounter("bscm-list-count", "The number of times the list of checkpoints has been invoked since the start of the instance.", false, new string[0]);
                _updateCheckpointCounter = metricFactory.CreateCounter("bscm-update-count", "The number of times the update checkpoint has been invoked since the start of the instance.", false, new string[0]);
                _listBlobTiming          = metricFactory.CreateSummary("bscm-list-timing", "The timing of the calls to the Azure Storage for list blob operations", 10, false, new string[0]);
                UpdateBlobTiming         = metricFactory.CreateSummary("bscm-update-timing", "The timing of the calls to the Azure Storage for update blob operations", 10, false, new string[0]);
                Logger.LogInformation("Finished Configuring instance");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the type
        /// </summary>
        /// <param name="dependencyService">A service that can be used to retrieve dependencies that were injected</param>
        /// <param name="loggerFactory">A factory that can be used to create loggers</param>
        /// <param name="metricFactory">A factory that can be used to create metrics</param>
        /// <param name="webSocketConfiguration">The configuration of the web socket</param>
        /// <param name="bufferPool">The buffer pool used to retreive arrays</param>
        public WebSocketHandler(IDependencyService dependencyService, IWebSocketConfiguration webSocketConfiguration, IMetricFactory metricFactory, ILoggerFactory loggerFactory, IBufferPool bufferPool)
        {
            Guard.NotNull(nameof(metricFactory), metricFactory);
            Guard.NotNull(nameof(loggerFactory), loggerFactory);
            Guard.NotNull(nameof(bufferPool), bufferPool);
            Guard.NotNull(nameof(webSocketConfiguration), webSocketConfiguration);

            WebSocketConfiguration = webSocketConfiguration;
            BufferPool             = bufferPool;
            SessionId     = Guid.NewGuid();
            MetricFactory = metricFactory;
            Logger        = loggerFactory.CreateLogger($"Session Handler: {SessionId:N}");

            DependencyService = dependencyService;

            _errorCounter        = metricFactory.CreateCounter("WebSocket error counter", "Tracks the number of errors that have occurred since the start of the service", false, new string[0]);
            _serviceSessionGauge = metricFactory.CreateGauge("WebSocket sessions in progress", "Tracks the number of sessions underway", false, new string[0]);
            _sessionTimes        = metricFactory.CreateSummary("WebSocket session iteration times", "Tracks the time taken to execute an iteration in the session", 10, false, new string[0]);
            _receiveTimes        = metricFactory.CreateSummary("WebSocket message receive time", "Tracks the time taken to receive a message", 10, false, new string[0]);
        }
 public static IMetricFamily <ISummary, ValueTuple <string> > CreateSummary(
     this IMetricFactory factory,
     string name,
     string help,
     string labelName,
     bool includeTimestamp = false,
     IReadOnlyList <QuantileEpsilonPair> objectives = null,
     TimeSpan?maxAge = null,
     int?ageBuckets  = null,
     int?bufCap      = null)
 {
     return(factory.CreateSummary(name, help, ValueTuple.Create(labelName), includeTimestamp, objectives, maxAge, ageBuckets, bufCap));
 }
 /// <summary>
 ///     Create Summary
 /// </summary>
 /// <param name="factory">Metric factory</param>
 /// <param name="name">Name.</param>
 /// <param name="help">Help text.</param>
 /// <param name="includeTimestamp">Include unix timestamp for metric.</param>
 /// <param name="labelNames">Array of label names.</param>
 /// <param name="objectives">.</param>
 /// <param name="maxAge"></param>
 /// <param name="ageBuckets"></param>
 /// <param name="bufCap"></param>
 public static IMetricFamily <ISummary> CreateSummary(
     this IMetricFactory factory,
     string name,
     string help,
     bool includeTimestamp,
     string[] labelNames,
     IReadOnlyList <QuantileEpsilonPair> objectives,
     TimeSpan?maxAge,
     int?ageBuckets,
     int?bufCap)
 {
     return(factory.CreateSummary(name, help, labelNames, includeTimestamp, objectives, maxAge, ageBuckets, bufCap));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the type
        /// </summary>
        /// <param name="authenticationPath">The HTTP path used for authentication</param>
        /// <param name="authorizationHeaderName">The name of the header where the authorization token is stored</param>
        /// <param name="authorizationPolicyHeaderName">The name of the header where the policy is stored</param>
        /// <param name="dependencyService">A service that can be used to retrieve dependencies that were injected</param>
        /// <param name="loggerFactory">A factory that can be used to create loggers</param>
        /// <param name="metricFactory">A factory that can be used to create metrics</param>
        /// <param name="resourceUriHeaderName">The name of the header that stores the resource URL</param>
        /// <param name="sasSigningKey">A Shared Access Signature signing key</param>
        /// <param name="sasTokenPolicyName">A Shared Access Signature token policy name</param>
        /// <param name="sasTokenTimeout">The Shared Access Signature token timeout</param>
        /// <param name="next">The next middleware component to execute</param>
        public SasAuthenticationMiddleware(RequestDelegate next, IDependencyService dependencyService, IMetricFactory metricFactory, ILoggerFactory loggerFactory, TimeSpan?sasTokenTimeout, string sasTokenPolicyName, string sasSigningKey, string authenticationPath, string authorizationHeaderName = "Authorization", string resourceUriHeaderName = "AuthResourceUri", string authorizationPolicyHeaderName = "AuthPolicyName")
        {
            Guard.NotNull(nameof(metricFactory), metricFactory);
            Guard.NotNull(nameof(loggerFactory), loggerFactory);
            Guard.NotNull(nameof(dependencyService), dependencyService);
            Guard.NotNullOrWhitespace(nameof(sasTokenPolicyName), sasTokenPolicyName);
            Guard.NotNullOrWhitespace(nameof(sasSigningKey), sasSigningKey);
            Guard.NotNullOrWhitespace(nameof(authorizationHeaderName), authorizationHeaderName);
            Guard.NotNullOrWhitespace(nameof(resourceUriHeaderName), resourceUriHeaderName);
            Guard.NotNullOrWhitespace(nameof(authorizationPolicyHeaderName), authorizationPolicyHeaderName);
            Guard.NotNullOrWhitespace(nameof(authenticationPath), authenticationPath);

            _logger = loggerFactory.CreateLogger("SAS Authentication");

            using (_logger.BeginScope("SAS CTOR"))
            {
                _logger.LogInformation("Initializing authentication middleware");

                _next = next;

                _sasTokenTimeout               = sasTokenTimeout ?? TimeSpan.FromHours(1);
                _sasTokenPolicyName            = sasTokenPolicyName;
                _sasTokenScheme                = sasTokenPolicyName;
                _sasSigningKey                 = sasSigningKey;
                _authorizationHeaderName       = authorizationHeaderName;
                _resourceUriHeaderName         = resourceUriHeaderName;
                _authorizationPolicyHeaderName = authorizationPolicyHeaderName;
                _authenticationPath            = authenticationPath;

                _authenticationTiming  = metricFactory.CreateSummary("sas-timing", "Timing summary for authentication timing", 10, false, new string[0]);
                _authenticationSuccess = metricFactory.CreateSummary("sas-authentication-success", "Successful authorization count", 10, false, new string[0]);
                _authenticationFailure = metricFactory.CreateSummary("sas-authentication-failure", "Failure authorization count", 10, false, new string[0]);
                _validateSuccess       = metricFactory.CreateSummary("sas-validation-success", "Successful validation count", 10, false, new string[0]);
                _validateFailure       = metricFactory.CreateSummary("sas-validation-failure", "Failure validation count", 10, false, new string[0]);
            }
        }
Ejemplo n.º 9
0
        public RequestMetricMiddleware(
            RequestDelegate next,
            IOptions <RequestMetricOptions> options,
            IMetricFactory <RequestMetricMiddleware> factory)
        {
            _next    = next;
            _options = options.Value;

            var labels = new List <string>();

            if (_options.IncludeStatusCode)
            {
                labels.Add("status_code");
            }

            if (_options.IncludeMethod)
            {
                labels.Add("method");
            }

            if (_options.IncludePath)
            {
                labels.Add("path");
            }

            if (_options.CustomLabels != null)
            {
                foreach (var customLabel in _options.CustomLabels)
                {
                    labels.Add(customLabel.Key);
                }
            }

            var helpTextEnd = string.Join(", ", labels);

            _labelsCount      = labels.Count;
            _requestDurations = factory.CreateSummary(_options.RequestDurationMetricName, opts =>
            {
                opts.Help       = DurationHelpText + helpTextEnd;
                opts.LabelNames = labels;
                if (_options.RequestDurationObjectives != null)
                {
                    opts.Objectives = _options.RequestDurationObjectives;
                }
            });
        }
        /// <summary>
        /// Initializes a new instance of the type
        /// </summary>
        /// <param name="logger">The logger to write debugging and diagnostics information to</param>
        /// <param name="metricFactory">The factory to create metric recorders from</param>
        /// <param name="storageAccount">The storage account used to access the Azure BLOB store</param>
        /// <param name="containerName">The name of the container that the BLOBs are contained in</param>
        /// <param name="subContainerPrefix">The prefix for the BLOB container</param>
        public AzureStorageCheckpointManager(ILogger logger, IMetricFactory metricFactory, CloudStorageAccount storageAccount, string containerName, string subContainerPrefix)
        {
            Guard.NotNull(nameof(storageAccount), storageAccount);
            Guard.NotNull(nameof(logger), logger);
            AzureBlobCommon.ValidContainerName(nameof(containerName), containerName);

            _logger = logger;

            using (_logger.BeginScope("Azure Storage Checkpoint Manager::ctor"))
            {
                _logger.LogInformation("Creating Azure storage checkpoint manager for container {containerName}", containerName);
                _containerName      = containerName;
                _subContainerPrefix = (subContainerPrefix != null) ? subContainerPrefix.Trim() : "";

                _client = storageAccount.CreateCloudBlobClient();

                _checkpointReadCounter     = metricFactory.CreateCounter("acm-checkpoint-read", "The number of times that the Azure Storage checkpoint manager has read the checkpoint", false, new string[0]);
                _checkpointUpdateCounter   = metricFactory.CreateCounter("acm-checkpoint-update", "The number of times that the Azure Storage checkpoint manager has updated the checkpoint", false, new string[0]);
                _checkpointErrorCounter    = metricFactory.CreateCounter("acm-checkpoint-error", "The number of times that the Azure Storage checkpoint manager has errors raised", false, new string[0]);
                _storagePerformanceSummary = metricFactory.CreateSummary("acm-storage-timing", "The duration taken to access Azure Storage to perform checkpoint manager operations", 10, false, new string[0]);
            }
        }
Ejemplo n.º 11
0
 public ISummary Creation(int i)
 {
     return(_factory.CreateSummary($"summary1_{i.ToString()}", string.Empty));
 }
 /// <summary>
 ///     Create Summary.
 /// </summary>
 /// <param name="factory">Metric factory</param>
 /// <param name="name">Name.</param>
 /// <param name="help">Help text.</param>
 /// <param name="includeTimestamp">Include unix timestamp for metric.</param>
 /// <param name="labelNames">Array of label names.</param>
 public static IMetricFamily <ISummary> CreateSummary(this IMetricFactory factory, string name, string help, bool includeTimestamp, params string[] labelNames)
 {
     return(factory.CreateSummary(name, help, labelNames, includeTimestamp));
 }
 /// <summary>
 ///     Create Summary.
 /// </summary>
 /// <param name="factory">Metric factory</param>
 /// <param name="name">Name.</param>
 /// <param name="help">Help text.</param>
 /// <param name="labelNames">Array of label names.</param>
 public static IMetricFamily <ISummary> CreateSummary(this IMetricFactory factory, string name, string help, params string[] labelNames)
 {
     return(factory.CreateSummary(name, help, false, labelNames));
 }
 public ICollector <ISummary> CreateSummary(string name, string help, SummaryConfiguration?configuration = null)
 => _factory.CreateSummary(name, help, configuration);