-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Defensively handle null source address in MassTransit instrument…
…ation. (#2060) * Defensively handle null source address * Also handle sourceAddress with no underscores Added unit tests * Refactor MassTransitHelpers and tests to extensions project
- Loading branch information
1 parent
70dfcf9
commit 0249582
Showing
9 changed files
with
171 additions
and
160 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Helpers/MassTransit.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System; | ||
using NewRelic.Agent.Extensions.Providers.Wrapper; | ||
|
||
|
||
namespace NewRelic.Agent.Extensions.Helpers | ||
{ | ||
public class MassTransitQueueData | ||
{ | ||
public string QueueName { get; set; } = "Unknown"; | ||
public MessageBrokerDestinationType DestinationType { get; set; } = MessageBrokerDestinationType.Queue; | ||
} | ||
|
||
public class MassTransitHelpers | ||
{ | ||
public static MassTransitQueueData GetQueueData(Uri sourceAddress) | ||
{ | ||
var data = new MassTransitQueueData(); | ||
|
||
if (sourceAddress != null) | ||
{ | ||
// rabbitmq://localhost/SomeHostname_MassTransitTest_bus_iyeoyyge44oc7yijbdp5i1opfd?temporary=true | ||
var items = sourceAddress.AbsoluteUri.Split('_'); | ||
if (items.Length > 1) | ||
{ | ||
var queueData = items[items.Length - 1].Split('?'); | ||
data.QueueName = queueData[0]; | ||
if (queueData.Length == 2 && queueData[1] == "temporary=true") | ||
{ | ||
data.DestinationType = MessageBrokerDestinationType.TempQueue; | ||
} | ||
} | ||
} | ||
return data; | ||
} | ||
} | ||
} |
47 changes: 0 additions & 47 deletions
47
src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/MassTransit/MassTransitHelpers.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
...Agent/NewRelic/Agent/Extensions/Providers/Wrapper/MassTransitLegacy/MassTransitHelpers.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/Agent/IntegrationTests/IntegrationTests/MassTransit/MassTransitTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tests/Agent/UnitTests/NewRelic.Agent.Extensions.Tests/Helpers/MassTransitHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System; | ||
using NUnit.Framework; | ||
using NewRelic.Agent.Extensions.Providers.Wrapper; | ||
using NewRelic.Agent.Extensions.Helpers; | ||
|
||
namespace Agent.Extensions.Tests.Helpers | ||
{ | ||
[TestFixture] | ||
public class MassTransitHelperTests | ||
{ | ||
|
||
[Test] | ||
[TestCase("rabbitmq://localhost/SomeHostname_MassTransitTest_bus_myqueuename?temporary=true", "myqueuename")] | ||
[TestCase("rabbitmq://localhost/SomeHostname_MassTransitTest_bus_myqueuename", "myqueuename")] | ||
[TestCase("rabbitmq://localhost/bogus", "Unknown")] | ||
[TestCase(null, "Unknown")] | ||
public void GetQueueName(Uri uri, string expectedQueueName) | ||
{ | ||
// Act | ||
var queueName = MassTransitHelpers.GetQueueData(uri).QueueName; | ||
|
||
// Assert | ||
Assert.AreEqual(expectedQueueName, queueName, "Did not get expected queue name"); | ||
} | ||
|
||
[Test] | ||
[TestCase("rabbitmq://localhost/NRHXPSQL3_MassTransitTest_bus_myqueuename?temporary=true", MessageBrokerDestinationType.TempQueue)] | ||
[TestCase("rabbitmq://localhost/NRHXPSQL3_MassTransitTest_bus_myqueuename?temporary=false", MessageBrokerDestinationType.Queue)] | ||
[TestCase("rabbitmq://localhost/NRHXPSQL3_MassTransitTest_bus_myqueuename", MessageBrokerDestinationType.Queue)] | ||
[TestCase(null, MessageBrokerDestinationType.Queue)] | ||
public void GetBrokerDestinationType(Uri uri, MessageBrokerDestinationType expectedDestType) | ||
{ | ||
// Act | ||
var destType = MassTransitHelpers.GetQueueData(uri).DestinationType; | ||
|
||
// Assert | ||
Assert.AreEqual(expectedDestType, destType, "Did not get expected queue type"); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.