Skip to content

Commit 2f4a153

Browse files
Fix metrics client construction
1 parent d0705d6 commit 2f4a153

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

src/ServiceControl.Transports.ASBS/AzureQuery.cs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class AzureQuery(ILogger<AzureQuery> logger, TimeProvider timeProvider, T
2929
MetricsClient? client;
3030
ArmClient? armClient;
3131
TokenCredential? credential;
32-
Uri? metricsEndpoint;
3332
string? resourceId;
3433
ArmEnvironment armEnvironment;
3534
MetricsClientAudience metricsQueryAudience;
@@ -275,26 +274,21 @@ public override async IAsyncEnumerable<IBrokerQueue> GetQueueNames(
275274
var regionName = serviceBusNamespaceResource.Data.Location.Name;
276275

277276
// Build the regional Azure Monitor Metrics endpoint from the audience
278-
var newEndpoint = BuildMetricsEndpointFromAudience(metricsQueryAudience, regionName);
277+
var metricsEndpoint = BuildMetricsEndpointFromAudience(metricsQueryAudience, regionName);
279278

280-
// Create or refresh the MetricsClient if it's missing or points to a different region
281-
if (client is null || metricsEndpoint?.ToString() != newEndpoint.ToString())
282-
{
283-
metricsEndpoint = newEndpoint;
284-
285-
client = new MetricsClient(
286-
metricsEndpoint,
287-
credential!,
288-
new MetricsClientOptions
289-
{
290-
Audience = metricsQueryAudience,
291-
Transport = new HttpClientTransport(
292-
new HttpClient(new SocketsHttpHandler
293-
{
294-
PooledConnectionIdleTimeout = TimeSpan.FromMinutes(2)
295-
}))
296-
});
297-
}
279+
// CreateNewOnMetadataUpdateAttribute the MetricsClient for this namespace
280+
client = new MetricsClient(
281+
metricsEndpoint,
282+
credential!,
283+
new MetricsClientOptions
284+
{
285+
Audience = metricsQueryAudience,
286+
Transport = new HttpClientTransport(
287+
new HttpClient(new SocketsHttpHandler
288+
{
289+
PooledConnectionIdleTimeout = TimeSpan.FromMinutes(2)
290+
}))
291+
});
298292

299293
await foreach (var queue in serviceBusNamespaceResource.GetServiceBusQueues()
300294
.WithCancellation(cancellationToken))

0 commit comments

Comments
 (0)