Skip to content

Commit 40b267a

Browse files
committed
Check for DisableStats in TestConnectionCore
1 parent 7781b76 commit 40b267a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/ServiceControl.Transports.RabbitMQ/RabbitMQQuery.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ async Task GetRabbitDetails(CancellationToken cancellationToken)
117117

118118
ValidateResponse(response);
119119

120-
if (response.Value!.DisableStats)
120+
if (response.Value?.DisableStats ?? false)
121121
{
122-
throw new Exception("The RabbitMQ broker is configured with 'management.disable_stats = true' or 'management_agent.disable_metrics_collector = true' " +
123-
"and as a result queue statistics cannot be collected using this tool. Consider changing the configuration of the RabbitMQ broker.");
122+
throw new Exception(disableStatsErrorMessage);
124123
}
125124

126125
Data["RabbitMQVersion"] = response.Value?.BrokerVersion ?? "Unknown";
@@ -189,6 +188,11 @@ void ValidateResponse<T>((HttpStatusCode StatusCode, string Reason, T? Value) re
189188

190189
if (value is not null)
191190
{
191+
if (value.DisableStats)
192+
{
193+
return (false, [disableStatsErrorMessage]);
194+
}
195+
192196
return (true, []);
193197
}
194198
else
@@ -203,5 +207,7 @@ void ValidateResponse<T>((HttpStatusCode StatusCode, string Reason, T? Value) re
203207
}
204208

205209
protected override void InitializeCore(ReadOnlyDictionary<string, string> settings) => Diagnostics.AppendLine("Using settings from connection string");
210+
211+
const string disableStatsErrorMessage = "The RabbitMQ broker is configured with 'management.disable_stats = true' or 'management_agent.disable_metrics_collector = true' and as a result queue statistics cannot be collected using this tool. Consider changing the configuration of the RabbitMQ broker.";
206212
}
207213

0 commit comments

Comments
 (0)