< Summary

Class:Azure.Messaging.EventHubs.Diagnostics.PartitionLoadBalancerEventSource
Assembly:Azure.Messaging.EventHubs
File(s):C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs.Shared\src\Diagnostics\PartitionLoadBalancerEventSource.cs
Covered lines:3
Uncovered lines:30
Coverable lines:33
Total lines:197
Line coverage:9% (3 of 33)
Covered branches:0
Total branches:40
Branch coverage:0% (0 of 40)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Log()-100%100%
.ctor()-100%100%
MinimumPartitionsPerEventProcessor(...)-0%0%
CurrentOwnershipCount(...)-0%0%
UnclaimedPartitions(...)-0%0%
ClaimOwnershipStart(...)-0%0%
ClaimOwnershipError(...)-0%0%
ShouldStealPartition(...)-0%0%
StealPartition(...)-0%0%
RenewOwnershipStart(...)-0%0%
RenewOwnershipError(...)-0%0%
RenewOwnershipComplete(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs.Shared\src\Diagnostics\PartitionLoadBalancerEventSource.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Collections.Generic;
 5using System.Diagnostics.Tracing;
 6using Azure.Core.Diagnostics;
 7
 8namespace Azure.Messaging.EventHubs.Diagnostics
 9{
 10    /// <summary>
 11    ///   Serves as an ETW event source for logging of information about Partition Load Balancer.
 12    /// </summary>
 13    ///
 14    /// <remarks>
 15    ///   When defining Start/Stop tasks, it is highly recommended that the
 16    ///   the StopEvent.Id must be exactly StartEvent.Id + 1.
 17    /// </remarks>
 18    ///
 19    [EventSource(Name = EventSourceName)]
 20    internal class PartitionLoadBalancerEventSource : EventSource
 21    {
 22        /// <summary>The name to use for the event source.</summary>
 23        private const string EventSourceName = "Azure-Messaging-EventHubs-Processor-PartitionLoadBalancer";
 24
 25        /// <summary>
 26        ///   Provides a singleton instance of the event source for callers to
 27        ///   use for logging.
 28        /// </summary>
 29        ///
 21430        public static PartitionLoadBalancerEventSource Log { get; } = new PartitionLoadBalancerEventSource();
 31
 32        /// <summary>
 33        ///   Prevents an instance of the <see cref="PartitionLoadBalancerEventSource"/> class from being created
 34        ///   outside the scope of this library.
 35        /// </summary>
 36        ///
 237        internal PartitionLoadBalancerEventSource() : base(EventSourceName, EventSourceSettings.Default, AzureEventSourc
 38        {
 239        }
 40
 41        /// <summary>
 42        ///   Indicates the minimum amount of partitions every event processor needs to own when the distribution is bal
 43        /// </summary>
 44        ///
 45        /// <param name="count"> Minimum partitions per event processor.</param>
 46        ///
 47        [Event(1, Level = EventLevel.Verbose, Message = "Expected minimum partitions per event processor '{0}'.")]
 48        public virtual void MinimumPartitionsPerEventProcessor(int count)
 49        {
 050            if (IsEnabled())
 51            {
 052                WriteEvent(1, count);
 53            }
 054        }
 55
 56        /// <summary>
 57        ///   Indicates the current ownership count.
 58        /// </summary>
 59        ///
 60        /// <param name="identifier">A unique name used to identify the associated event processor.</param>
 61        /// <param name="count"> Current ownership count.</param>
 62        ///
 63        [Event(2, Level = EventLevel.Informational, Message = "Current ownership count is {0}. (Identifier: '{1}')")]
 64        public virtual void CurrentOwnershipCount(int count,
 65                                                  string identifier)
 66        {
 067            if (IsEnabled())
 68            {
 069                WriteEvent(2, count, identifier ?? string.Empty);
 70            }
 071        }
 72
 73        /// <summary>
 74        ///   Indicates the list of unclaimed partitions.
 75        /// </summary>
 76        ///
 77        /// <param name="unclaimedPartitions">List of unclaimed partitions.</param>
 78        ///
 79        [Event(3, Level = EventLevel.Informational, Message = "Unclaimed partitions: '{0}'.")]
 80        public virtual void UnclaimedPartitions(HashSet<string> unclaimedPartitions)
 81        {
 082            if (IsEnabled())
 83            {
 084                WriteEvent(3, string.Join(", ", unclaimedPartitions));
 85            }
 086        }
 87
 88        /// <summary>
 89        ///   Indicates that an attempt to claim ownership for a specific partition has started.
 90        /// </summary>
 91        ///
 92        /// <param name="partitionId">The identifier of the Event Hub partition whose ownership claim attempt is startin
 93        ///
 94        [Event(4, Level = EventLevel.Informational, Message = "Attempting to claim ownership of partition '{0}'.")]
 95        public virtual void ClaimOwnershipStart(string partitionId)
 96        {
 097            if (IsEnabled())
 98            {
 099                WriteEvent(4, partitionId ?? string.Empty);
 100            }
 0101        }
 102
 103        /// <summary>
 104        ///   Indicates that an exception was encountered while claiming ownership for a specific partition.
 105        /// </summary>
 106        ///
 107        /// <param name="partitionId">The identifier of the Event Hub partition.</param>
 108        /// <param name="errorMessage">The message for the exception that occurred.</param>
 109        ///
 110        [Event(5, Level = EventLevel.Error, Message = "Failed to claim ownership of partition '{0}'. (ErrorMessage: '{1}
 111        public virtual void ClaimOwnershipError(string partitionId,
 112                                                string errorMessage)
 113        {
 0114            if (IsEnabled())
 115            {
 0116                WriteEvent(5, partitionId ?? string.Empty, errorMessage ?? string.Empty);
 117            }
 0118        }
 119
 120        /// <summary>
 121        ///   Indicates that the load is unbalanced and the associated event processor should own more partitions.
 122        /// </summary>
 123        ///
 124        /// <param name="identifier">A unique name used to identify the associated event processor.</param>
 125        ///
 126        [Event(6, Level = EventLevel.Informational, Message = "Load is unbalanced and this load balancer should steal a 
 127        public virtual void ShouldStealPartition(string identifier)
 128        {
 0129            if (IsEnabled())
 130            {
 0131                WriteEvent(6, identifier ?? string.Empty);
 132            }
 0133        }
 134
 135        /// <summary>
 136        ///   Indicates that stealable partitions were found, so randomly picking one of them to claim.
 137        /// </summary>
 138        ///
 139        /// <param name="identifier">A unique name used to identify the associated event processor.</param>
 140        ///
 141        [Event(7, Level = EventLevel.Informational, Message = "No unclaimed partitions, stealing from another event proc
 142        public virtual void StealPartition(string identifier)
 143        {
 0144            if (IsEnabled())
 145            {
 0146                WriteEvent(7, identifier ?? string.Empty);
 147            }
 0148        }
 149
 150        /// <summary>
 151        ///   Indicates that an attempt to renew ownership has started, so they don't expire.
 152        /// </summary>
 153        ///
 154        /// <param name="identifier">A unique name used to identify the associated event processor.</param>
 155        ///
 156        [Event(8, Level = EventLevel.Verbose, Message = "Attempting to renew ownership. (Identifier: '{0}')")]
 157        public virtual void RenewOwnershipStart(string identifier)
 158        {
 0159            if (IsEnabled())
 160            {
 0161                WriteEvent(8, identifier ?? string.Empty);
 162            }
 0163        }
 164
 165        /// <summary>
 166        ///   Indicates that an exception was encountered while renewing ownership.
 167        /// </summary>
 168        ///
 169        /// <param name="identifier">A unique name used to identify the associated event processor.</param>
 170        /// <param name="errorMessage">The message for the exception that occurred.</param>
 171        ///
 172        [Event(9, Level = EventLevel.Error, Message = "Failed to renew ownership. (Identifier: '{0}'; ErrorMessage: '{0}
 173        public virtual void RenewOwnershipError(string identifier,
 174                                                string errorMessage)
 175        {
 0176            if (IsEnabled())
 177            {
 0178                WriteEvent(9, identifier ?? string.Empty, errorMessage ?? string.Empty);
 179            }
 0180        }
 181
 182        /// <summary>
 183        ///   Indicates that an attempt to renew ownership has completed, so they don't expire.
 184        /// </summary>
 185        ///
 186        /// <param name="identifier">A unique name used to identify the associated event processor.</param>
 187        ///
 188        [Event(10, Level = EventLevel.Verbose, Message = "Attempt to renew ownership has completed. (Identifier: '{0}')"
 189        public virtual void RenewOwnershipComplete(string identifier)
 190        {
 0191            if (IsEnabled())
 192            {
 0193                WriteEvent(10, identifier ?? string.Empty);
 194            }
 0195        }
 196    }
 197}