-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Measure time messages wait in the work item queue (#3934)
- Loading branch information
Showing
10 changed files
with
90 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/ProductConstructionService/ProductConstructionService.Common/MetricRecorder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.Metrics; | ||
using Azure.Storage.Queues.Models; | ||
|
||
namespace ProductConstructionService.Common; | ||
|
||
public interface IMetricRecorder | ||
{ | ||
void QueueMessageReceived(QueueMessage message, TimeSpan delay); | ||
} | ||
|
||
public class MetricRecorder : IMetricRecorder | ||
{ | ||
public const string PcsMetricsNamespace = "ProductConstructionService.Metrics"; | ||
private const string WaitTimeMetricName = "pcs.queue.wait_time"; | ||
|
||
private readonly Counter<int> _queueWaitTimeCounter; | ||
|
||
public MetricRecorder(IMeterFactory meterFactory) | ||
{ | ||
var meter = meterFactory.Create(PcsMetricsNamespace); | ||
_queueWaitTimeCounter = meter.CreateCounter<int>(WaitTimeMetricName); | ||
} | ||
|
||
public void QueueMessageReceived(QueueMessage message, TimeSpan delay) | ||
{ | ||
TimeSpan timeInQueue = DateTimeOffset.UtcNow - message.InsertedOn!.Value - delay; | ||
_queueWaitTimeCounter.Add((int)timeInQueue.TotalSeconds); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
src/ProductConstructionService/ProductConstructionService.WorkItems/WorkItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Text.Json.Serialization; | ||
|
||
namespace ProductConstructionService.WorkItems; | ||
|
||
public abstract class WorkItem | ||
{ | ||
public Guid Id { get; init; } = Guid.NewGuid(); | ||
/// <summary> | ||
/// Type of the message for easier deserialization. | ||
/// </summary> | ||
public string Type => GetType().Name; | ||
|
||
/// <summary> | ||
/// Period of time before the WorkItem becomes visible in the queue. | ||
/// </summary> | ||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault | JsonIgnoreCondition.WhenWritingNull)] | ||
public TimeSpan? Delay { get; internal set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters