Skip to content

Commit d4fd1ef

Browse files
authored
provide monthly throughput values to the licensing API (#5532)
1 parent d79bb60 commit d4fd1ef

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/Particular.LicensingComponent.Contracts/EndpointThroughputSummary.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ public class EndpointThroughputSummary
77
public bool IsKnownEndpoint { get; set; }
88
public string UserIndicator { get; set; }
99
public long MaxDailyThroughput { get; set; }
10+
public MonthlyThroughput[] MonthlyThroughput { get; set; }
1011
public long MaxMonthlyThroughput { get; set; }
1112
}
1213

1314
public class UpdateUserIndicator
1415
{
1516
public string Name { get; set; }
1617
public string UserIndicator { get; set; }
17-
}
18+
}
19+
20+
public record MonthlyThroughput(string Month, long Throughput);

src/Particular.LicensingComponent/ThroughputCollector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public async Task<List<EndpointThroughputSummary>> GetThroughputSummary(Cancella
7373
UserIndicator = endpointData.UserIndicator ?? (endpointData.IsKnownEndpoint ? Contracts.UserIndicator.NServiceBusEndpoint.ToString() : string.Empty),
7474
IsKnownEndpoint = endpointData.IsKnownEndpoint,
7575
MaxDailyThroughput = endpointData.ThroughputData.MaxDailyThroughput(),
76+
MonthlyThroughput = endpointData.ThroughputData.MonthlyThroughput(),
7677
MaxMonthlyThroughput = endpointData.ThroughputData.MaxMonthlyThroughput()
7778
};
7879

src/Particular.LicensingComponent/ThroughputDataExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public static long MaxDailyThroughput(this List<ThroughputData> throughputs)
2323
return 0;
2424
}
2525

26+
public static MonthlyThroughput[] MonthlyThroughput(this List<ThroughputData> throughputs) => [.. throughputs
27+
.SelectMany(data => data)
28+
.GroupBy(kvp => $"{kvp.Key:yyyy-MM}")
29+
.Select(group => new MonthlyThroughput(group.Key, group.Sum(kvp => kvp.Value)))];
30+
2631
public static long MaxMonthlyThroughput(this List<ThroughputData> throughputs)
2732
{
2833
var monthlySums = throughputs

src/ServiceControl.Persistence.RavenDB/Throughput/LicensingDataStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public async Task<IDictionary<string, IEnumerable<ThroughputData>>> GetEndpointT
140140
.IncrementalTimeSeriesFor(document.GenerateDocumentId(), ThroughputTimeSeriesName)
141141
.GetAsync(from, token: cancellationToken);
142142

143-
if (results.TryGetValue(document.SanitizedName, out var throughputDatas) &&
143+
if (timeSeries is not null && results.TryGetValue(document.SanitizedName, out var throughputDatas) &&
144144
throughputDatas is List<ThroughputData> throughputDataList)
145145
{
146146
var endpointDailyThroughputs = timeSeries.Select(entry => new EndpointDailyThroughput(DateOnly.FromDateTime(entry.Timestamp), (long)entry.Value));

0 commit comments

Comments
 (0)