Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ public class EndpointThroughputSummary
public bool IsKnownEndpoint { get; set; }
public string UserIndicator { get; set; }
public long MaxDailyThroughput { get; set; }
public MonthlyThroughput[] MonthlyThroughput { get; set; }
public long MaxMonthlyThroughput { get; set; }
}

public class UpdateUserIndicator
{
public string Name { get; set; }
public string UserIndicator { get; set; }
}
}

public record MonthlyThroughput(string Month, long Throughput);
1 change: 1 addition & 0 deletions src/Particular.LicensingComponent/ThroughputCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public async Task<List<EndpointThroughputSummary>> GetThroughputSummary(Cancella
UserIndicator = endpointData.UserIndicator ?? (endpointData.IsKnownEndpoint ? Contracts.UserIndicator.NServiceBusEndpoint.ToString() : string.Empty),
IsKnownEndpoint = endpointData.IsKnownEndpoint,
MaxDailyThroughput = endpointData.ThroughputData.MaxDailyThroughput(),
MonthlyThroughput = endpointData.ThroughputData.MonthlyThroughput(),
MaxMonthlyThroughput = endpointData.ThroughputData.MaxMonthlyThroughput()
};

Expand Down
5 changes: 5 additions & 0 deletions src/Particular.LicensingComponent/ThroughputDataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public static long MaxDailyThroughput(this List<ThroughputData> throughputs)
return 0;
}

public static MonthlyThroughput[] MonthlyThroughput(this List<ThroughputData> throughputs) => [.. throughputs
.SelectMany(data => data)
.GroupBy(kvp => $"{kvp.Key.Year}-{kvp.Key.Month.ToString().PadLeft(2, '0')}")
.Select(group => new MonthlyThroughput(group.Key, group.Sum(kvp => kvp.Value)))];

public static long MaxMonthlyThroughput(this List<ThroughputData> throughputs)
{
var monthlySums = throughputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public async Task<IDictionary<string, IEnumerable<ThroughputData>>> GetEndpointT
.IncrementalTimeSeriesFor(document.GenerateDocumentId(), ThroughputTimeSeriesName)
.GetAsync(from, token: cancellationToken);

if (results.TryGetValue(document.SanitizedName, out var throughputDatas) &&
if (timeSeries is not null && results.TryGetValue(document.SanitizedName, out var throughputDatas) &&
throughputDatas is List<ThroughputData> throughputDataList)
{
var endpointDailyThroughputs = timeSeries.Select(entry => new EndpointDailyThroughput(DateOnly.FromDateTime(entry.Timestamp), (long)entry.Value));
Expand Down
Loading