Skip to content

Commit ffe53a5

Browse files
committed
fix: queue gauge metric
1 parent bb61dd7 commit ffe53a5

File tree

16 files changed

+134
-127
lines changed

16 files changed

+134
-127
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ sample:
55

66
sample-clean:
77
@docker compose -f docker-compose.sample.yaml down
8+
9+
benchmark:
10+
dotnet run -c Release --project ./tests/benchmark/Farfetch.LoadShedding.BenchmarkTests/Farfetch.LoadShedding.BenchmarkTests.csproj

src/Farfetch.LoadShedding/Events/Args/ItemDequeuedEventArgs.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,17 @@ namespace Farfetch.LoadShedding.Events.Args
66
/// <summary>
77
/// Event args for the task dequeued event.
88
/// </summary>
9-
public class ItemDequeuedEventArgs : ItemEventArgs
9+
public class ItemDequeuedEventArgs : TaskQueueEventArgs
1010
{
11-
internal ItemDequeuedEventArgs(Priority priority, TimeSpan queueTime, int queueLimit, int queueCount)
12-
: base(priority)
11+
internal ItemDequeuedEventArgs(Priority priority, TimeSpan queueTime, IReadOnlyCounter queueCounter)
12+
: base(priority, queueCounter)
1313
{
1414
this.QueueTime = queueTime;
15-
this.QueueLimit = queueLimit;
16-
this.QueueCount = queueCount;
1715
}
1816

1917
/// <summary>
2018
/// Gets the time waiting in the queue.
2119
/// </summary>
2220
public TimeSpan QueueTime { get; }
23-
24-
/// <summary>
25-
/// Gets the maximum number of items in the queue.
26-
/// </summary>
27-
public int QueueLimit { get; }
28-
29-
/// <summary>
30-
/// Gets the current number of items in the queue.
31-
/// </summary>
32-
public int QueueCount { get; }
3321
}
3422
}

src/Farfetch.LoadShedding/Events/Args/ItemEnqueuedEventArgs.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,11 @@ namespace Farfetch.LoadShedding.Events.Args
55
/// <summary>
66
/// Event args for the task enqueued event.
77
/// </summary>
8-
public class ItemEnqueuedEventArgs : ItemEventArgs
8+
public class ItemEnqueuedEventArgs : TaskQueueEventArgs
99
{
10-
internal ItemEnqueuedEventArgs(Priority priority, int queueLimit, int queueCount)
11-
: base(priority)
10+
internal ItemEnqueuedEventArgs(Priority priority, IReadOnlyCounter queueCounter)
11+
: base(priority, queueCounter)
1212
{
13-
this.QueueLimit = queueLimit;
14-
this.QueueCount = queueCount;
1513
}
16-
17-
/// <summary>
18-
/// Gets the maximum number of items in the queue.
19-
/// </summary>
20-
public int QueueLimit { get; }
21-
22-
/// <summary>
23-
/// Gets the current number of items in the queue.
24-
/// </summary>
25-
public int QueueCount { get; }
2614
}
2715
}
Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,22 @@
1-
using System;
1+
using System;
22
using Farfetch.LoadShedding.Tasks;
33

44
namespace Farfetch.LoadShedding.Events.Args
55
{
66
/// <summary>
77
/// Event args for task processed event.
88
/// </summary>
9-
public class ItemProcessedEventArgs : ItemEventArgs
9+
public class ItemProcessedEventArgs : TaskItemEventArgs
1010
{
11-
internal ItemProcessedEventArgs(Priority priority, TimeSpan processingTime, int concurrencyLimit, int concurrencyCount)
12-
: base(priority)
11+
internal ItemProcessedEventArgs(Priority priority, TimeSpan processingTime, IReadOnlyCounter concurrencyCounter)
12+
: base(priority, concurrencyCounter)
1313
{
1414
this.ProcessingTime = processingTime;
15-
this.ConcurrencyLimit = concurrencyLimit;
16-
this.ConcurrencyCount = concurrencyCount;
1715
}
1816

1917
/// <summary>
2018
/// Gets time spent to process the task.
2119
/// </summary>
2220
public TimeSpan ProcessingTime { get; }
23-
24-
/// <summary>
25-
/// Gets the current concurrency limit.
26-
/// </summary>
27-
public int ConcurrencyLimit { get; }
28-
29-
/// <summary>
30-
/// Gets the current concurrency items count.
31-
/// </summary>
32-
public int ConcurrencyCount { get; }
3321
}
3422
}
Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
using Farfetch.LoadShedding.Tasks;
1+
using Farfetch.LoadShedding.Tasks;
22

33
namespace Farfetch.LoadShedding.Events.Args
44
{
55
/// <summary>
6-
/// Event args for task procssing event.
6+
/// Event args for task processing event.
77
/// </summary>
8-
public class ItemProcessingEventArgs : ItemEventArgs
8+
public class ItemProcessingEventArgs : TaskItemEventArgs
99
{
10-
internal ItemProcessingEventArgs(Priority priority, int concurrencyLimit, int concurrencyCount)
11-
: base(priority)
10+
internal ItemProcessingEventArgs(Priority priority, IReadOnlyCounter concurrencyCounter)
11+
: base(priority, concurrencyCounter)
1212
{
13-
this.ConcurrencyLimit = concurrencyLimit;
14-
this.ConcurrencyCount = concurrencyCount;
1513
}
16-
17-
/// <summary>
18-
/// Gets the current concurrency limit.
19-
/// </summary>
20-
public int ConcurrencyLimit { get; }
21-
22-
/// <summary>
23-
/// Gets the current concurrency items count.
24-
/// </summary>
25-
public int ConcurrencyCount { get; }
2614
}
2715
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Farfetch.LoadShedding.Tasks;
2+
3+
namespace Farfetch.LoadShedding.Events.Args
4+
{
5+
/// <summary>
6+
/// Event args for task item event.
7+
/// </summary>
8+
public class TaskItemEventArgs : ItemEventArgs
9+
{
10+
private readonly IReadOnlyCounter _concurrencyCounter;
11+
12+
internal TaskItemEventArgs(Priority priority, IReadOnlyCounter concurrencyCounter)
13+
: base(priority)
14+
{
15+
_concurrencyCounter = concurrencyCounter;
16+
}
17+
18+
/// <summary>
19+
/// Gets the current concurrency limit.
20+
/// </summary>
21+
public int ConcurrencyLimit => _concurrencyCounter.Limit;
22+
23+
/// <summary>
24+
/// Gets the current concurrency items count.
25+
/// </summary>
26+
public int ConcurrencyCount => _concurrencyCounter.Count;
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Farfetch.LoadShedding.Tasks;
2+
3+
namespace Farfetch.LoadShedding.Events.Args
4+
{
5+
/// <summary>
6+
/// Event args for the task queue event.
7+
/// </summary>
8+
public class TaskQueueEventArgs : ItemEventArgs
9+
{
10+
private readonly IReadOnlyCounter _queueCounter;
11+
12+
internal TaskQueueEventArgs(Priority priority, IReadOnlyCounter queueCounter)
13+
: base(priority)
14+
{
15+
this._queueCounter = queueCounter;
16+
}
17+
18+
/// <summary>
19+
/// Gets the maximum number of items in the queue.
20+
/// </summary>
21+
public int QueueLimit => _queueCounter.Limit;
22+
23+
/// <summary>
24+
/// Gets the current number of items in the queue.
25+
/// </summary>
26+
public int QueueCount => _queueCounter.Count;
27+
}
28+
}

src/Farfetch.LoadShedding/Tasks/ConcurrentCounter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace Farfetch.LoadShedding.Tasks
22
{
3-
internal class ConcurrentCounter
3+
internal class ConcurrentCounter : IReadOnlyCounter
44
{
5-
private readonly object _locker = new object();
5+
private readonly object _locker = new();
66

77
private int _count = 0;
88

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Farfetch.LoadShedding.Tasks
2+
{
3+
internal interface IReadOnlyCounter
4+
{
5+
int Count { get; }
6+
7+
int Limit { get; }
8+
}
9+
}

src/Farfetch.LoadShedding/Tasks/Priority.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ namespace Farfetch.LoadShedding.Tasks
66
public enum Priority
77
{
88
/// <summary>
9-
/// Priority as critical.
9+
/// Priority as Critical.
1010
/// </summary>
1111
Critical = 0,
1212

1313
/// <summary>
14-
/// Priority as normal.
14+
/// Priority as Normal.
1515
/// </summary>
1616
Normal = 1,
1717

1818
/// <summary>
19-
/// Priority as critical.
19+
/// Priority as Non Critical.
2020
/// </summary>
2121
NonCritical = 2,
2222
}

0 commit comments

Comments
 (0)