Skip to content

Commit b5f07bf

Browse files
authored
Merge pull request #1047 from Particular/john/queue-names-only
Adding support to run only in queue mode collection
2 parents 72c190f + bdf9ca5 commit b5f07bf

3 files changed

Lines changed: 71 additions & 32 deletions

File tree

src/AppCommon/Commands/AzureServiceBusCommand.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public static Command CreateCommand()
5353

5454
readonly AzureClient azure;
5555

56+
string[] queueNames;
5657

5758
public AzureServiceBusCommand(SharedOptions shared, string resourceId, string serviceBusDomain)
5859
: base(shared)
@@ -65,14 +66,8 @@ protected override async Task<QueueDetails> GetData(CancellationToken cancellati
6566
{
6667
try
6768
{
68-
Out.WriteLine($"Getting data from {azure.FullyQualifiedNamespace}...");
6969
var endTime = DateTime.UtcNow.Date.AddDays(1);
7070
var startTime = endTime.AddDays(-30);
71-
72-
var queueNames = await azure.GetQueueNames(cancellationToken);
73-
74-
Out.WriteLine($"Found {queueNames.Length} queues");
75-
7671
var results = new List<QueueThroughput>();
7772

7873
azure.ResetConnectionQueue();
@@ -116,13 +111,20 @@ protected override async Task<QueueDetails> GetData(CancellationToken cancellati
116111
}
117112
}
118113

119-
protected override Task<EnvironmentDetails> GetEnvironment(CancellationToken cancellationToken = default)
114+
protected override async Task<EnvironmentDetails> GetEnvironment(CancellationToken cancellationToken = default)
120115
{
121-
return Task.FromResult(new EnvironmentDetails
116+
Out.WriteLine($"Getting data from {azure.FullyQualifiedNamespace}...");
117+
118+
queueNames = await azure.GetQueueNames(cancellationToken);
119+
120+
Out.WriteLine($"Found {queueNames.Length} queues");
121+
122+
return new EnvironmentDetails
122123
{
123124
MessageTransport = "AzureServiceBus",
124125
ReportMethod = $"AzureServiceBus Metrics: {azure.FullyQualifiedNamespace}",
126+
QueueNames = queueNames,
125127
SkipEndpointListCheck = true
126-
});
128+
};
127129
}
128130
}

src/AppCommon/Commands/BaseCommand.cs

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -198,34 +198,61 @@ async Task RunInternal(CancellationToken cancellationToken)
198198
}
199199
Out.WriteLine();
200200

201-
var data = await GetData(cancellationToken);
201+
Report reportData;
202202

203-
foreach (var q in data.Queues)
203+
if (!shared.SkipThroughputCollection)
204204
{
205-
q.QueueName = shared.Mask(q.QueueName);
206-
if (q.Throughput.HasValue)
205+
var data = await GetData(cancellationToken);
206+
207+
foreach (var q in data.Queues)
207208
{
208-
q.Throughput = Math.Abs(q.Throughput.Value);
209+
q.QueueName = shared.Mask(q.QueueName);
210+
if (q.Throughput.HasValue)
211+
{
212+
q.Throughput = Math.Abs(q.Throughput.Value);
213+
}
209214
}
210-
}
211215

212-
var reportData = new Report
213-
{
214-
CustomerName = shared.CustomerName,
215-
MessageTransport = metadata.MessageTransport,
216-
ReportMethod = shared.Mask(metadata.ReportMethod),
217-
ToolType = "Throughput Tool",
218-
ToolVersion = Versioning.NuGetVersion,
219-
Prefix = metadata.Prefix,
220-
ScopeType = data.ScopeType,
221-
StartTime = data.StartTime,
222-
EndTime = data.EndTime,
223-
ReportDuration = data.TimeOfObservation ?? data.EndTime - data.StartTime,
224-
Queues = data.Queues,
225-
TotalThroughput = data.Queues.Sum(q => q.Throughput ?? 0),
226-
TotalQueues = data.Queues.Length,
227-
IgnoredQueues = metadata.IgnoredQueues?.Select(q => shared.Mask(q)).ToArray()
228-
};
216+
reportData = new Report
217+
{
218+
CustomerName = shared.CustomerName,
219+
MessageTransport = metadata.MessageTransport,
220+
ReportMethod = shared.Mask(metadata.ReportMethod),
221+
ToolType = "Throughput Tool",
222+
ToolVersion = Versioning.NuGetVersion,
223+
Prefix = metadata.Prefix,
224+
ScopeType = data.ScopeType,
225+
StartTime = data.StartTime,
226+
EndTime = data.EndTime,
227+
ReportDuration = data.TimeOfObservation ?? data.EndTime - data.StartTime,
228+
Queues = data.Queues,
229+
TotalThroughput = data.Queues.Sum(q => q.Throughput ?? 0),
230+
TotalQueues = data.Queues.Length,
231+
IgnoredQueues = metadata.IgnoredQueues?.Select(q => shared.Mask(q)).ToArray()
232+
};
233+
}
234+
else
235+
{
236+
var mappedQueueNames = metadata.QueueNames
237+
.Select(name => new { Name = name, Masked = shared.Mask(name) })
238+
.ToArray();
239+
reportData = new Report
240+
{
241+
CustomerName = shared.CustomerName,
242+
MessageTransport = metadata.MessageTransport,
243+
ReportMethod = shared.Mask(metadata.ReportMethod),
244+
ToolType = "Throughput Tool",
245+
ToolVersion = Versioning.NuGetVersion,
246+
Prefix = metadata.Prefix,
247+
StartTime = new DateTimeOffset(DateTime.UtcNow.Date, TimeSpan.Zero),
248+
EndTime = new DateTimeOffset(DateTime.UtcNow.Date.AddDays(1), TimeSpan.Zero),
249+
ReportDuration = TimeSpan.FromDays(1),
250+
Queues = mappedQueueNames.Select(map => new QueueThroughput { QueueName = map.Masked, Throughput = 0 }).ToArray(),
251+
TotalThroughput = 0,
252+
TotalQueues = mappedQueueNames.Length,
253+
IgnoredQueues = metadata.IgnoredQueues?.Select(q => shared.Mask(q)).ToArray()
254+
};
255+
}
229256

230257
var report = new SignedReport
231258
{

src/AppCommon/Infra/SharedOptions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,20 @@ class SharedOptions
2727
Arity = ArgumentArity.ZeroOrOne
2828
};
2929

30+
public static readonly Option<bool> skipThroughputCollection =
31+
new("--skipThroughputCollection")
32+
{
33+
Description = "It returns only the queue names with zero throughput.",
34+
Arity = ArgumentArity.ZeroOrOne
35+
};
36+
3037
public static readonly Option<int> runtimeInHours =
3138
new(name: "--runtime", getDefaultValue: () => 24) { IsHidden = true };
3239

3340
public string CustomerName { get; set; }
3441
public bool RunUnattended { get; private set; }
3542
public bool SkipVersionCheck { get; private set; }
43+
public bool SkipThroughputCollection { get; private set; }
3644
public int RuntimeInHours { get; private set; }
3745

3846
(string Mask, string Replacement)[] masks;
@@ -53,6 +61,7 @@ public static void Register(Command command)
5361
command.AddGlobalOption(customerName);
5462
command.AddGlobalOption(runUnattended);
5563
command.AddGlobalOption(skipVersionCheck);
64+
command.AddGlobalOption(skipThroughputCollection);
5665
command.AddGlobalOption(runtimeInHours);
5766
}
5867

@@ -61,6 +70,7 @@ public static void Register(Command command)
6170
CustomerName = parse.GetValueForOption(customerName);
6271
RunUnattended = parse.GetValueForOption(runUnattended);
6372
SkipVersionCheck = parse.GetValueForOption(skipVersionCheck);
73+
SkipThroughputCollection = parse.GetValueForOption(skipThroughputCollection);
6474
RuntimeInHours = parse.GetValueForOption(runtimeInHours);
6575

6676
int number = 0;

0 commit comments

Comments
 (0)