Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Foundatio.TestHarness/Utility/InMemoryMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public double Value<T>(string name) where T : struct
{
var measurement = GetMeasurements<T>(name)
.Where(m => m.Name == name)
.OrderByDescending(m => m.Timestamp)
.OrderByDescending(m => m.Sequence)
.FirstOrDefault();

return Convert.ToDouble(measurement.Value);
Expand Down Expand Up @@ -385,6 +385,10 @@ public void Dispose()
[DebuggerDisplay("{Name}={Value}")]
public struct RecordedMeasurement<T> where T : struct
{
private static long _sequenceCounter;

private static long GetNextSequence() => Interlocked.Increment(ref _sequenceCounter);

public RecordedMeasurement(Instrument instrument, T value, ref ReadOnlySpan<KeyValuePair<string, object?>> tags,
object? state)
{
Expand All @@ -395,13 +399,13 @@ public RecordedMeasurement(Instrument instrument, T value, ref ReadOnlySpan<KeyV
? ImmutableDictionary.CreateRange(tags.ToArray())
: ImmutableDictionary<string, object?>.Empty;
State = state;
Timestamp = DateTime.UtcNow;
Sequence = GetNextSequence();
}

public Instrument Instrument { get; }
public string Name { get; }
public T Value { get; }
public IReadOnlyDictionary<string, object?> Tags { get; }
public object? State { get; }
public DateTime Timestamp { get; }
public long Sequence { get; }
}
Comment thread
niemyjski marked this conversation as resolved.
Resolved
Loading