Skip to content

Commit 23f73cd

Browse files
Delete unused metrics code (#33368)
1 parent a9bb8f1 commit 23f73cd

File tree

12 files changed

+11
-300
lines changed

12 files changed

+11
-300
lines changed

sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpClient.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ internal class AmqpClient : TransportClient
7272
/// </summary>
7373
private readonly AmqpMessageConverter _messageConverter;
7474

75-
public override ServiceBusTransportMetrics TransportMetrics { get; }
76-
7775
/// <summary>
7876
/// Initializes a new instance of the <see cref="AmqpClient"/> class.
7977
/// </summary>
@@ -115,19 +113,15 @@ internal AmqpClient(
115113
}.Uri;
116114

117115
Credential = credential;
118-
if (options.EnableTransportMetrics)
119-
{
120-
TransportMetrics = new ServiceBusTransportMetrics();
121-
}
116+
122117
ConnectionScope = new AmqpConnectionScope(
123118
ServiceEndpoint,
124119
ConnectionEndpoint,
125120
credential,
126121
options.TransportType,
127122
options.WebProxy,
128123
options.EnableCrossEntityTransactions,
129-
options.RetryOptions.TryTimeout,
130-
TransportMetrics);
124+
options.RetryOptions.TryTimeout);
131125
}
132126

133127
/// <summary>

sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpConnectionScope.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,14 @@ public override bool IsDisposed
200200
/// <param name="proxy">The proxy, if any, to use for communication.</param>
201201
/// <param name="useSingleSession">If true, all links will use a single session.</param>
202202
/// <param name="operationTimeout">The timeout for operations associated with the connection.</param>
203-
/// <param name="metrics">The metrics instance to populate transport metrics. May be null.</param>
204203
public AmqpConnectionScope(
205204
Uri serviceEndpoint,
206205
Uri connectionEndpoint,
207206
ServiceBusTokenCredential credential,
208207
ServiceBusTransportType transport,
209208
IWebProxy proxy,
210209
bool useSingleSession,
211-
TimeSpan operationTimeout,
212-
ServiceBusTransportMetrics metrics)
210+
TimeSpan operationTimeout)
213211
{
214212
Argument.AssertNotNull(serviceEndpoint, nameof(serviceEndpoint));
215213
Argument.AssertNotNull(credential, nameof(credential));
@@ -223,7 +221,7 @@ public AmqpConnectionScope(
223221
TokenProvider = new CbsTokenProvider(new ServiceBusTokenCredential(credential), AuthorizationTokenExpirationBuffer, OperationCancellationSource.Token);
224222
_useSingleSession = useSingleSession;
225223
#pragma warning disable CA2214 // Do not call overridable methods in constructors. This internal method is virtual for testing purposes.
226-
Task<AmqpConnection> connectionFactory(TimeSpan timeout) => CreateAndOpenConnectionAsync(AmqpVersion, ServiceEndpoint, connectionEndpoint, Transport, Proxy, Id, timeout, metrics);
224+
Task<AmqpConnection> connectionFactory(TimeSpan timeout) => CreateAndOpenConnectionAsync(AmqpVersion, ServiceEndpoint, connectionEndpoint, Transport, Proxy, Id, timeout);
227225
#pragma warning restore CA2214 // Do not call overridable methods in constructors
228226

229227
ActiveConnection = new FaultTolerantAmqpObject<AmqpConnection>(
@@ -453,7 +451,6 @@ public override void Dispose()
453451
/// <param name="proxy">The proxy, if any, to use for communication.</param>
454452
/// <param name="scopeIdentifier">The unique identifier for the associated scope.</param>
455453
/// <param name="timeout">The timeout to consider when creating the connection.</param>
456-
/// <param name="metrics">The metrics instance to populate transport metrics. May be null.</param>
457454
/// <returns>An AMQP connection that may be used for communicating with the Service Bus service.</returns>
458455
protected virtual async Task<AmqpConnection> CreateAndOpenConnectionAsync(
459456
Version amqpVersion,
@@ -462,8 +459,7 @@ protected virtual async Task<AmqpConnection> CreateAndOpenConnectionAsync(
462459
ServiceBusTransportType transportType,
463460
IWebProxy proxy,
464461
string scopeIdentifier,
465-
TimeSpan timeout,
466-
ServiceBusTransportMetrics metrics)
462+
TimeSpan timeout)
467463
{
468464
var serviceHostName = serviceEndpoint.Host;
469465
var connectionHostName = connectionEndpoint.Host;
@@ -483,10 +479,6 @@ protected virtual async Task<AmqpConnection> CreateAndOpenConnectionAsync(
483479
TransportBase transport = await initiator.ConnectTaskAsync(timeout).ConfigureAwait(false);
484480

485481
var connection = new AmqpConnection(transport, amqpSettings, connectionSetings);
486-
if (metrics != null)
487-
{
488-
connection.UsageMeter = new AmqpUsageMeter(metrics);
489-
}
490482

491483
await OpenAmqpObjectAsync(connection, timeout.CalculateRemaining(stopWatch.GetElapsedTime())).ConfigureAwait(false);
492484

sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpUsageMeter.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

sdk/servicebus/Azure.Messaging.ServiceBus/src/Client/ServiceBusClient.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,6 @@ public virtual async ValueTask DisposeAsync()
9393
}
9494
}
9595

96-
/// <summary>
97-
/// Gets the metrics associated with this <see cref="ServiceBusClient"/> instance. The metrics returned represent a snapshot and will not be updated.
98-
/// To get updated metrics, this method should be called again.
99-
/// In order to use this property, <see cref="ServiceBusClientOptions.EnableTransportMetrics"/> must be set to <value>true</value>.
100-
/// </summary>
101-
internal virtual ServiceBusTransportMetrics GetTransportMetrics()
102-
=> Connection.InnerClient.TransportMetrics?.Clone() ??
103-
throw new InvalidOperationException("Transport metrics are not enabled. To enable transport metrics, set the EnableTransportMetrics property on the ServiceBusClientOptions.");
104-
10596
/// <summary>
10697
/// The connection that is used for the client.
10798
/// </summary>

sdk/servicebus/Azure.Messaging.ServiceBus/src/Client/ServiceBusClientOptions.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,6 @@ public ServiceBusRetryOptions RetryOptions
8181
///</value>
8282
public bool EnableCrossEntityTransactions { get; set; }
8383

84-
/// <summary>
85-
/// Gets or sets whether or not to enable metrics for the associated <see cref="ServiceBusClient"/> instance.
86-
/// If set to <value>true</value>, <see cref="ServiceBusClient.GetTransportMetrics"/> can be called.
87-
/// </summary>
88-
internal bool EnableTransportMetrics { get; set; }
89-
9084
/// <summary>
9185
/// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
9286
/// </summary>
@@ -129,7 +123,6 @@ internal ServiceBusClientOptions Clone() =>
129123
WebProxy = WebProxy,
130124
RetryOptions = RetryOptions.Clone(),
131125
EnableCrossEntityTransactions = EnableCrossEntityTransactions,
132-
EnableTransportMetrics = EnableTransportMetrics,
133126
CustomEndpointAddress = CustomEndpointAddress,
134127
Identifier = Identifier
135128
};

sdk/servicebus/Azure.Messaging.ServiceBus/src/Client/ServiceBusTransportMetrics.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

sdk/servicebus/Azure.Messaging.ServiceBus/src/Core/TransportClient.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ internal abstract class TransportClient : IAsyncDisposable
3535
///
3636
public virtual Uri ServiceEndpoint { get; }
3737

38-
/// <summary>
39-
/// The metrics related to the client.
40-
/// </summary>
41-
public virtual ServiceBusTransportMetrics TransportMetrics { get; }
42-
4338
/// <summary>
4439
/// Creates a sender strongly aligned with the active protocol and transport,
4540
/// responsible for sending <see cref="ServiceBusMessage" /> to the entity.

sdk/servicebus/Azure.Messaging.ServiceBus/src/Primitives/ServiceBusModelFactory.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -428,24 +428,6 @@ public static ServiceBusMessageBatch ServiceBusMessageBatch(long batchSizeBytes,
428428
return new ServiceBusMessageBatch(transportBatch, new EntityScopeFactory("mock", "mock"));
429429
}
430430

431-
/// <summary>
432-
/// Creates a new <see cref="ServiceBusTransportMetrics"/> instance for mocking.
433-
/// </summary>
434-
/// <param name="lastHeartbeat">The last time that a heartbeat was received from the service.</param>
435-
/// <param name="lastConnectionOpen">The last time that a connection was opened.</param>
436-
/// <param name="lastConnectionClose">The last time that a connection was closed.</param>
437-
/// <returns></returns>
438-
internal static ServiceBusTransportMetrics ServiceBusTransportMetrics(
439-
DateTimeOffset? lastHeartbeat = default,
440-
DateTimeOffset? lastConnectionOpen = default,
441-
DateTimeOffset? lastConnectionClose = default)
442-
=> new()
443-
{
444-
LastHeartBeat = lastHeartbeat,
445-
LastConnectionOpen = lastConnectionOpen,
446-
LastConnectionClose = lastConnectionClose
447-
};
448-
449431
/// <summary>
450432
/// Allows for the transport event batch created by the factory to be injected for testing purposes.
451433
/// </summary>

sdk/servicebus/Azure.Messaging.ServiceBus/tests/Amqp/AmqpConnectionScopeTests.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public async Task OpenLinkAssociatesSendLinkSource()
146146
var cancellationSource = new CancellationTokenSource();
147147
var mockSession = new AmqpSession(mockConnection, new AmqpSessionSettings(), Mock.Of<ILinkFactory>());
148148

149-
var mockScope = new Mock<AmqpConnectionScope>(endpoint, endpoint, credential.Object, ServiceBusTransportType.AmqpTcp, null, false, default, default)
149+
var mockScope = new Mock<AmqpConnectionScope>(endpoint, endpoint, credential.Object, ServiceBusTransportType.AmqpTcp, null, false, default)
150150
{
151151
CallBase = true,
152152
};
@@ -160,8 +160,7 @@ public async Task OpenLinkAssociatesSendLinkSource()
160160
ItExpr.IsAny<ServiceBusTransportType>(),
161161
ItExpr.IsAny<IWebProxy>(),
162162
ItExpr.IsAny<string>(),
163-
ItExpr.IsAny<TimeSpan>(),
164-
ItExpr.IsAny<ServiceBusTransportMetrics>())
163+
ItExpr.IsAny<TimeSpan>())
165164
.Returns(Task.FromResult(mockConnection))
166165
.Verifiable();
167166

@@ -215,7 +214,7 @@ public async Task OpenLinkAssociatesReceiveLinkTarget()
215214
var cancellationSource = new CancellationTokenSource();
216215
var mockSession = new AmqpSession(mockConnection, new AmqpSessionSettings(), Mock.Of<ILinkFactory>());
217216

218-
var mockScope = new Mock<AmqpConnectionScope>(endpoint, endpoint, credential.Object, ServiceBusTransportType.AmqpTcp, null, false, default, default)
217+
var mockScope = new Mock<AmqpConnectionScope>(endpoint, endpoint, credential.Object, ServiceBusTransportType.AmqpTcp, null, false, default)
219218
{
220219
CallBase = true,
221220
};
@@ -229,8 +228,7 @@ public async Task OpenLinkAssociatesReceiveLinkTarget()
229228
ItExpr.IsAny<ServiceBusTransportType>(),
230229
ItExpr.IsAny<IWebProxy>(),
231230
ItExpr.IsAny<string>(),
232-
ItExpr.IsAny<TimeSpan>(),
233-
ItExpr.IsAny<ServiceBusTransportMetrics>())
231+
ItExpr.IsAny<TimeSpan>())
234232
.Returns(Task.FromResult(mockConnection))
235233
.Verifiable();
236234

@@ -357,7 +355,7 @@ public MockConnectionScope(
357355
Uri customConnectionEndpoint,
358356
ServiceBusTokenCredential credential,
359357
ServiceBusTransportType transport,
360-
IWebProxy proxy) : base(serviceEndpoint, customConnectionEndpoint, credential, transport, proxy, false, default, default)
358+
IWebProxy proxy) : base(serviceEndpoint, customConnectionEndpoint, credential, transport, proxy, false, default)
361359
{
362360
MockConnection = new Mock<AmqpConnection>(new MockTransport(), CreateMockAmqpSettings(), new AmqpConnectionSettings());
363361
}
@@ -377,8 +375,7 @@ protected override Task<AmqpConnection> CreateAndOpenConnectionAsync(Version amq
377375
ServiceBusTransportType transportType,
378376
IWebProxy proxy,
379377
string scopeIdentifier,
380-
TimeSpan timeout,
381-
ServiceBusTransportMetrics metrics)
378+
TimeSpan timeout)
382379
{
383380
return Task.FromResult(MockConnection.Object);
384381
}

sdk/servicebus/Azure.Messaging.ServiceBus/tests/Client/ServiceBusClientLiveTests.cs

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -267,72 +267,5 @@ public async Task CanAcceptBlankSession()
267267
Assert.AreEqual("", receiver.SessionId);
268268
}
269269
}
270-
271-
[Test]
272-
public async Task MetricsAreUpdatedCorrectly()
273-
{
274-
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: false))
275-
{
276-
await using var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, new ServiceBusClientOptions { EnableTransportMetrics = true });
277-
278-
ServiceBusSender sender = client.CreateSender(scope.QueueName);
279-
280-
await sender.SendMessageAsync(new ServiceBusMessage());
281-
var metrics = client.GetTransportMetrics();
282-
var firstHeartBeat = metrics.LastHeartBeat;
283-
var firstOpen = metrics.LastConnectionOpen;
284-
Assert.GreaterOrEqual(firstOpen, firstHeartBeat);
285-
286-
SimulateNetworkFailure(client);
287-
await sender.SendMessageAsync(new ServiceBusMessage());
288-
289-
metrics = client.GetTransportMetrics();
290-
var secondOpen = metrics.LastConnectionOpen;
291-
Assert.Greater(secondOpen, firstOpen);
292-
293-
SimulateNetworkFailure(client);
294-
var receiver = client.CreateReceiver(scope.QueueName);
295-
await receiver.ReceiveMessageAsync(TimeSpan.FromSeconds(30));
296-
297-
metrics = client.GetTransportMetrics();
298-
var thirdOpen = metrics.LastConnectionOpen;
299-
Assert.Greater(thirdOpen, secondOpen);
300-
301-
await client.DisposeAsync();
302-
// The close frame does not come back from the service before the DisposeAsync
303-
// call is returned.
304-
await Task.Delay(1000);
305-
metrics = client.GetTransportMetrics();
306-
Assert.Greater(metrics.LastConnectionClose, thirdOpen);
307-
Assert.Greater(metrics.LastHeartBeat, firstHeartBeat);
308-
}
309-
}
310-
311-
[Test]
312-
public async Task MetricsInstanceIsNotMutated()
313-
{
314-
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: false))
315-
{
316-
await using var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, new ServiceBusClientOptions { EnableTransportMetrics = true });
317-
318-
ServiceBusSender sender = client.CreateSender(scope.QueueName);
319-
320-
await sender.SendMessageAsync(new ServiceBusMessage());
321-
var metrics = client.GetTransportMetrics();
322-
var firstHeartBeat = metrics.LastHeartBeat;
323-
var firstOpen = metrics.LastConnectionOpen;
324-
Assert.GreaterOrEqual(firstOpen, firstHeartBeat);
325-
326-
SimulateNetworkFailure(client);
327-
await sender.SendMessageAsync(new ServiceBusMessage());
328-
Assert.AreEqual(firstOpen, metrics.LastConnectionOpen);
329-
330-
await client.DisposeAsync();
331-
// The close frame does not come back from the service before the DisposeAsync
332-
// call is returned.
333-
await Task.Delay(500);
334-
Assert.IsNull(metrics.LastConnectionClose);
335-
}
336-
}
337270
}
338271
}

0 commit comments

Comments
 (0)