From e13e486f4e04680e24ac379f095706d121ccd8a7 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 14 Nov 2023 08:32:14 +0100 Subject: [PATCH] chore: remove obsolete iot dependency --- .../Arcus.Observability.Telemetry.IoT.csproj | 35 ---- .../Extensions/ILoggerExtensions.cs | 152 ------------------ .../Arcus.Observability.Tests.Unit.csproj | 2 +- .../Logging/IoTHubDependencyLoggingTests.cs | 135 ++-------------- src/Arcus.Observability.sln | 6 - 5 files changed, 10 insertions(+), 320 deletions(-) delete mode 100644 src/Arcus.Observability.Telemetry.IoT/Arcus.Observability.Telemetry.IoT.csproj delete mode 100644 src/Arcus.Observability.Telemetry.IoT/Extensions/ILoggerExtensions.cs diff --git a/src/Arcus.Observability.Telemetry.IoT/Arcus.Observability.Telemetry.IoT.csproj b/src/Arcus.Observability.Telemetry.IoT/Arcus.Observability.Telemetry.IoT.csproj deleted file mode 100644 index 7f427c3b..00000000 --- a/src/Arcus.Observability.Telemetry.IoT/Arcus.Observability.Telemetry.IoT.csproj +++ /dev/null @@ -1,35 +0,0 @@ - - - - net8.0;net6.0;netstandard2.1 - Arcus - Arcus - Provides capability to improve IoT telemetry with Serilog in applications - Copyright (c) Arcus - https://observability.arcus-azure.net/ - https://github.com/arcus-azure/arcus.observability - LICENSE - icon.png - Git - README.md - Azure;Observability;Telemetry;Serilog;IoT - true - true - true - - - - - - - - - - - - - - - - - diff --git a/src/Arcus.Observability.Telemetry.IoT/Extensions/ILoggerExtensions.cs b/src/Arcus.Observability.Telemetry.IoT/Extensions/ILoggerExtensions.cs deleted file mode 100644 index aaf8bae2..00000000 --- a/src/Arcus.Observability.Telemetry.IoT/Extensions/ILoggerExtensions.cs +++ /dev/null @@ -1,152 +0,0 @@ -using System; -using System.Collections.Generic; -using Arcus.Observability.Telemetry.Core; -using GuardNet; -using Microsoft.Azure.Devices.Client; - -// ReSharper disable once CheckNamespace -namespace Microsoft.Extensions.Logging -{ - /// - /// Extensions on the related to tracking IoT dependencies. - /// - // ReSharper disable once InconsistentNaming - public static class ILoggerExtensions - { - /// - /// Logs an Azure Iot Hub Dependency. - /// - /// Logger to use - /// Name of the IoT Hub resource - /// Indication whether or not the operation was successful - /// Measuring the latency to call the dependency - /// Context that provides more insights on the dependency that was measured - [Obsolete("Use the overload with " + nameof(DurationMeasurement) + " instead to track IoT Hub dependencies")] - public static void LogIotHubDependency(this ILogger logger, string iotHubConnectionString, bool isSuccessful, DependencyMeasurement measurement, Dictionary context = null) - { - Guard.NotNull(logger, nameof(logger)); - Guard.NotNullOrWhitespace(iotHubConnectionString, nameof(iotHubConnectionString)); - - LogIotHubDependency(logger, iotHubConnectionString, isSuccessful, measurement.StartTime, measurement.Elapsed, context); - } - - /// - /// Logs an Azure Iot Hub Dependency. - /// - /// The logger instance to track the IoT Hub dependency. - /// The connection string to interact with an IoT Hub resource. - /// The indication whether or not the operation was successful. - /// The measurement of the duration to call the dependency. - /// The context that provides more insights on the dependency that was measured. - /// Thrown when the is null. - /// Thrown when the is blank or is invalid. - /// Thrown when the is invalid. - [Obsolete("Use the 'LogIotHubDependencyWithConnectionString' instead in the 'Arcus.Observability.Telemetry.Core' package and remove the 'Arcus.Observability.Telemetry.IoT' package from your project")] - public static void LogIotHubDependency( - this ILogger logger, - string iotHubConnectionString, - bool isSuccessful, - DurationMeasurement measurement, - Dictionary context = null) - { - Guard.NotNull(logger, nameof(logger), "Requires an logger instance to track the IoT Hub dependency"); - Guard.NotNullOrWhitespace(iotHubConnectionString, nameof(iotHubConnectionString), "Requires an IoT Hub connection string to retrieve the IoT host name to track the IoT Hub dependency"); - Guard.NotNull(measurement, nameof(measurement), "Requires an measurement instance to measure the duration of interaction with the IoT Hub dependency"); - - context = context ?? new Dictionary(); - - LogIotHubDependency(logger, iotHubConnectionString, isSuccessful, measurement.StartTime, measurement.Elapsed, dependencyId: null, context); - } - - /// - /// Logs an Azure Iot Hub Dependency. - /// - /// The logger instance to track the IoT Hub dependency. - /// The connection string to interact with an IoT Hub resource. - /// The indication whether or not the operation was successful. - /// The measurement of the duration to call the dependency. - /// The ID of the dependency to link as parent ID. - /// The context that provides more insights on the dependency that was measured. - /// Thrown when the is null. - /// Thrown when the is blank or is invalid. - /// Thrown when the is invalid. - [Obsolete("Use the 'LogIotHubDependencyWithConnectionString' instead in the 'Arcus.Observability.Telemetry.Core' package and remove the 'Arcus.Observability.Telemetry.IoT' package from your project")] - public static void LogIotHubDependency( - this ILogger logger, - string iotHubConnectionString, - bool isSuccessful, - DurationMeasurement measurement, - string dependencyId, - Dictionary context = null) - { - Guard.NotNull(logger, nameof(logger), "Requires an logger instance to track the IoT Hub dependency"); - Guard.NotNullOrWhitespace(iotHubConnectionString, nameof(iotHubConnectionString), "Requires an IoT Hub connection string to retrieve the IoT host name to track the IoT Hub dependency"); - Guard.NotNull(measurement, nameof(measurement), "Requires an measurement instance to measure the duration of interaction with the IoT Hub dependency"); - - context = context ?? new Dictionary(); - - LogIotHubDependency(logger, iotHubConnectionString, isSuccessful, measurement.StartTime, measurement.Elapsed, dependencyId, context); - } - - /// - /// Logs an Azure Iot Hub Dependency. - /// - /// The logger instance to track the IoT Hub dependency. - /// The connection string to interact with an IoT Hub resource. - /// The indication whether or not the operation was successful. - /// The point in time when the interaction with the dependency was started. - /// The duration of the operation. - /// The context that provides more insights on the dependency that was measured. - /// Thrown when the is null. - /// Thrown when the is blank or is invalid. - /// Thrown when the is invalid. - [Obsolete("Use the 'LogIotHubDependencyWithConnectionString' instead in the 'Arcus.Observability.Telemetry.Core' package and remove the 'Arcus.Observability.Telemetry.IoT' package from your project")] - public static void LogIotHubDependency( - this ILogger logger, - string iotHubConnectionString, - bool isSuccessful, - DateTimeOffset startTime, - TimeSpan duration, - Dictionary context = null) - { - Guard.NotNull(logger, nameof(logger), "Requires an logger instance to track the IoT Hub dependency"); - Guard.NotNullOrWhitespace(iotHubConnectionString, nameof(iotHubConnectionString), "Requires an IoT Hub connection string to retrieve the IoT host name to track the IoT Hub dependency"); - - context = context ?? new Dictionary(); - - LogIotHubDependency(logger, iotHubConnectionString, isSuccessful, startTime, duration, dependencyId: null, context); - } - - /// - /// Logs an Azure Iot Hub Dependency. - /// - /// The logger instance to track the IoT Hub dependency. - /// The connection string to interact with an IoT Hub resource. - /// The indication whether or not the operation was successful. - /// The point in time when the interaction with the dependency was started. - /// The duration of the operation. - /// The ID of the dependency to link as parent ID. - /// The context that provides more insights on the dependency that was measured. - /// Thrown when the is null. - /// Thrown when the is blank or is invalid. - /// Thrown when the is invalid. - [Obsolete("Use the 'LogIotHubDependencyWithConnectionString' instead in the 'Arcus.Observability.Telemetry.Core' package and remove the 'Arcus.Observability.Telemetry.IoT' package from your project")] - public static void LogIotHubDependency( - this ILogger logger, - string iotHubConnectionString, - bool isSuccessful, - DateTimeOffset startTime, - TimeSpan duration, - string dependencyId, - Dictionary context = null) - { - Guard.NotNull(logger, nameof(logger), "Requires an logger instance to track the IoT Hub dependency"); - Guard.NotNullOrWhitespace(iotHubConnectionString, nameof(iotHubConnectionString), "Requires an IoT Hub connection string to retrieve the IoT host name to track the IoT Hub dependency"); - - context = context ?? new Dictionary(); - - var iotHubConnection = IotHubConnectionStringBuilder.Create(iotHubConnectionString); - logger.LogIotHubDependency(iotHubName: iotHubConnection.HostName, isSuccessful, startTime, duration, dependencyId, context); - } - } -} diff --git a/src/Arcus.Observability.Tests.Unit/Arcus.Observability.Tests.Unit.csproj b/src/Arcus.Observability.Tests.Unit/Arcus.Observability.Tests.Unit.csproj index 8a09c3f3..d6f32fc5 100644 --- a/src/Arcus.Observability.Tests.Unit/Arcus.Observability.Tests.Unit.csproj +++ b/src/Arcus.Observability.Tests.Unit/Arcus.Observability.Tests.Unit.csproj @@ -17,6 +17,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + @@ -29,7 +30,6 @@ - diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/IoTHubDependencyLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/IoTHubDependencyLoggingTests.cs index 64a9cf8d..cbd68370 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/IoTHubDependencyLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/IoTHubDependencyLoggingTests.cs @@ -217,33 +217,6 @@ public void LogIotHubDependencyWithDurationMeasurementWithDependencyId_ValidArgu Assert.Equal(value, Assert.Contains(key, dependency.Context)); } - [Fact] - public void LogIotHubDependencyConnectionStringWithDurationMeasurement_ValidArguments_Succeeds() - { - // Arrange - var logger = new TestLogger(); - var iotHubName = "acme.azure-devices.net"; - var iotHubConnectionString = $"HostName={iotHubName};SharedAccessKeyName=AllAccessKey;DeviceId=fake;SharedAccessKey=dGVzdFN0cmluZzE="; - bool isSuccessful = BogusGenerator.Random.Bool(); - - var measurement = DurationMeasurement.Start(); - DateTimeOffset startTime = measurement.StartTime; - measurement.Dispose(); - TimeSpan duration = measurement.Elapsed; - - // Act - logger.LogIotHubDependency(iotHubConnectionString: iotHubConnectionString, isSuccessful, measurement); - - // Assert - DependencyLogEntry dependency = logger.GetMessageAsDependency(); - Assert.Equal(iotHubName, dependency.TargetName); - Assert.Equal("Azure IoT Hub", dependency.DependencyType); - Assert.Equal(iotHubName, dependency.DependencyName); - Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime); - Assert.Equal(duration, dependency.Duration); - Assert.Equal(isSuccessful, dependency.IsSuccessful); - } - [Fact] public void LogIotHubDependencyConnectionStringWithDurationMeasurementWithDependencyId_ValidArguments_Succeeds() { @@ -264,7 +237,7 @@ public void LogIotHubDependencyConnectionStringWithDurationMeasurementWithDepend var context = new Dictionary { [key] = value }; // Act - logger.LogIotHubDependency(iotHubConnectionString: iotHubConnectionString, isSuccessful, measurement, dependencyId, context); + logger.LogIotHubDependencyWithConnectionString(iotHubConnectionString: iotHubConnectionString, isSuccessful, measurement, dependencyId, context); // Assert DependencyLogEntry dependency = logger.GetMessageAsDependency(); @@ -338,22 +311,6 @@ public void LogIotHubDependencyWithDurationMeasurementWithDependencyId_WithoutMe () => logger.LogIotHubDependency(iotHubName: iotHubName, isSuccessful, measurement: null, dependencyId)); } - [Theory] - [ClassData(typeof(Blanks))] - public void LogIotHubDependencyConnectionStringWithDurationMeasurement_WithoutConnectionString_Fails(string iotHubConnectionString) - { - // Arrange - var logger = new TestLogger(); - bool isSuccessful = BogusGenerator.Random.Bool(); - - var measurement = DurationMeasurement.Start(); - measurement.Dispose(); - - // Act / Assert - Assert.ThrowsAny( - () => logger.LogIotHubDependency(iotHubConnectionString: iotHubConnectionString, isSuccessful, measurement)); - } - [Theory] [ClassData(typeof(Blanks))] public void LogIotHubDependencyConnectionStringWithDurationMeasurementWithDependencyId_WithoutConnectionString_Fails(string iotHubConnectionString) @@ -368,20 +325,7 @@ public void LogIotHubDependencyConnectionStringWithDurationMeasurementWithDepend // Act / Assert Assert.ThrowsAny( - () => logger.LogIotHubDependency(iotHubConnectionString: iotHubConnectionString, isSuccessful, measurement, dependencyId)); - } - - [Fact] - public void LogIotHubDependencyConnectionStringWithDurationMeasurement_WithoutMeasurement_Fails() - { - // Arrange - var logger = new TestLogger(); - bool isSuccessful = BogusGenerator.Random.Bool(); - string iotHubConnectionString = BogusGenerator.Commerce.ProductName(); - - // Act / Assert - Assert.ThrowsAny( - () => logger.LogIotHubDependency(iotHubConnectionString: iotHubConnectionString, isSuccessful, measurement: (DurationMeasurement)null)); + () => logger.LogIotHubDependencyWithConnectionString(iotHubConnectionString: iotHubConnectionString, isSuccessful, measurement, dependencyId)); } [Fact] @@ -395,35 +339,7 @@ public void LogIotHubDependencyConnectionStringWithDurationMeasurementWithDepend // Act / Assert Assert.ThrowsAny( - () => logger.LogIotHubDependency(iotHubConnectionString: iotHubConnectionString, isSuccessful, measurement: null, dependencyId)); - } - - [Fact] - public void LogIotHubConnectionStringDependency_ValidArguments_Succeeds() - { - // Arrange - var logger = new TestLogger(); - string iotHubName = BogusGenerator.Commerce.ProductName().Replace(" ", String.Empty); - string deviceId = BogusGenerator.Internet.Ip(); - string sharedAccessKey = BogusGenerator.Random.Hash(); - var iotHubConnectionString = $"HostName={iotHubName}.;DeviceId={deviceId};SharedAccessKey={sharedAccessKey}"; - bool isSuccessful = BogusGenerator.Random.Bool(); - DateTimeOffset startTime = BogusGenerator.Date.PastOffset(); - TimeSpan duration = BogusGenerator.Date.Timespan(); - - // Act - logger.LogIotHubDependency(iotHubConnectionString: iotHubConnectionString, isSuccessful, startTime, duration); - - // Assert - var logMessage = logger.WrittenMessage; - Assert.Contains(TelemetryType.Dependency.ToString(), logMessage); - Assert.Contains(iotHubName, logMessage); - Assert.Contains(iotHubName, logMessage); - Assert.Contains(isSuccessful.ToString(), logMessage); - Assert.Contains(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), logMessage); - Assert.Contains(duration.ToString(), logMessage); - string dependencyName = iotHubName; - Assert.Contains("Azure IoT Hub " + dependencyName, logMessage); + () => logger.LogIotHubDependencyWithConnectionString(iotHubConnectionString: iotHubConnectionString, isSuccessful, measurement: null, dependencyId)); } [Fact] @@ -445,7 +361,7 @@ public void LogIotHubConnectionStringDependencyWithDependencyId_ValidArguments_S var context = new Dictionary { [key] = value }; // Act - logger.LogIotHubDependency(iotHubConnectionString: iotHubConnectionString, isSuccessful, startTime, duration, dependencyId, context); + logger.LogIotHubDependencyWithConnectionString(iotHubConnectionString: iotHubConnectionString, isSuccessful, startTime, duration, dependencyId, context); // Assert DependencyLogEntry dependency = logger.GetMessageAsDependency(); @@ -459,22 +375,6 @@ public void LogIotHubConnectionStringDependencyWithDependencyId_ValidArguments_S Assert.Equal(value, Assert.Contains(key, dependency.Context)); } - [Theory] - [ClassData(typeof(Blanks))] - public void LogIotHubDependencyConnectionString_WithoutConnectionString_Fails(string iotHubConnectionString) - { - // Arrange - var logger = new TestLogger(); - bool isSuccessful = BogusGenerator.Random.Bool(); - - DateTimeOffset startTime = BogusGenerator.Date.PastOffset(); - TimeSpan duration = BogusGenerator.Date.Timespan(); - - // Act / Assert - Assert.ThrowsAny( - () => logger.LogIotHubDependency(iotHubConnectionString: iotHubConnectionString, isSuccessful, startTime, duration)); - } - [Theory] [ClassData(typeof(Blanks))] public void LogIotHubDependencyConnectionStringWithDependencyId_WithoutConnectionString_Fails(string iotHubConnectionString) @@ -489,25 +389,7 @@ public void LogIotHubDependencyConnectionStringWithDependencyId_WithoutConnectio // Act / Assert Assert.ThrowsAny( - () => logger.LogIotHubDependency(iotHubConnectionString: iotHubConnectionString, isSuccessful, startTime, duration, dependencyId)); - } - - [Fact] - public void LogIoTHubConnectionStringDependency_WithNegativeDuration_Fails() - { - // Arrange - var logger = new TestLogger(); - string iotHubName = BogusGenerator.Commerce.ProductName().Replace(" ", String.Empty); - string deviceId = BogusGenerator.Internet.Ip(); - string sharedAccessKey = BogusGenerator.Random.Hash(); - var iotHubConnectionString = $"HostName={iotHubName}.;DeviceId={deviceId};SharedAccessKey={sharedAccessKey}"; - bool isSuccessful = BogusGenerator.Random.Bool(); - DateTimeOffset startTime = BogusGenerator.Date.PastOffset(); - TimeSpan duration = TimeSpanGenerator.GeneratePositiveDuration().Negate(); - - // Act - Assert.ThrowsAny( - () => logger.LogIotHubDependency(iotHubConnectionString: iotHubConnectionString, isSuccessful, startTime, duration)); + () => logger.LogIotHubDependencyWithConnectionString(iotHubConnectionString: iotHubConnectionString, isSuccessful, startTime, duration, dependencyId)); } [Fact] @@ -526,7 +408,7 @@ public void LogIoTHubConnectionStringDependencyWithDependencyId_WithNegativeDura // Act Assert.ThrowsAny( - () => logger.LogIotHubDependency(iotHubConnectionString: iotHubConnectionString, isSuccessful, startTime, duration, dependencyId)); + () => logger.LogIotHubDependencyWithConnectionString(iotHubConnectionString: iotHubConnectionString, isSuccessful, startTime, duration, dependencyId)); } [Fact] @@ -539,14 +421,15 @@ public void LogIotHubDependencyConnectionStringWithDependencyMeasurement_ValidAr string sharedAccessKey = BogusGenerator.Random.Hash(); var iotHubConnectionString = $"HostName={iotHubName}.;DeviceId={deviceId};SharedAccessKey={sharedAccessKey}"; bool isSuccessful = BogusGenerator.Random.Bool(); + string dependencyId = BogusGenerator.Random.Guid().ToString(); - var measurement = DependencyMeasurement.Start(); + var measurement = DurationMeasurement.Start(); DateTimeOffset startTime = measurement.StartTime; measurement.Dispose(); TimeSpan duration = measurement.Elapsed; // Act - logger.LogIotHubDependency(iotHubConnectionString: iotHubConnectionString, isSuccessful: isSuccessful, measurement: measurement); + logger.LogIotHubDependencyWithConnectionString(iotHubConnectionString, isSuccessful, measurement, dependencyId); // Assert var logMessage = logger.WrittenMessage; diff --git a/src/Arcus.Observability.sln b/src/Arcus.Observability.sln index a1dfa47e..58a5d74c 100644 --- a/src/Arcus.Observability.sln +++ b/src/Arcus.Observability.sln @@ -21,8 +21,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Observability.Telemet EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Observability.Tests.Core", "Arcus.Observability.Tests.Core\Arcus.Observability.Tests.Core.csproj", "{DC18426F-4D03-4DBD-8D92-224C026BFADC}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Observability.Telemetry.IoT", "Arcus.Observability.Telemetry.IoT\Arcus.Observability.Telemetry.IoT.csproj", "{E4A6624B-C1A4-4956-9FC2-E77D6C634717}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Observability.Telemetry.AzureFunctions", "Arcus.Observability.Telemetry.AzureFunctions\Arcus.Observability.Telemetry.AzureFunctions.csproj", "{C6C0ED5D-94B4-4CD2-B17A-E72432AC4883}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Observability.Telemetry.AspNetCore", "Arcus.Observability.Telemetry.AspNetCore\Arcus.Observability.Telemetry.AspNetCore.csproj", "{72573A95-8B8A-4EE0-8067-099305B211B3}" @@ -67,10 +65,6 @@ Global {DC18426F-4D03-4DBD-8D92-224C026BFADC}.Debug|Any CPU.Build.0 = Debug|Any CPU {DC18426F-4D03-4DBD-8D92-224C026BFADC}.Release|Any CPU.ActiveCfg = Release|Any CPU {DC18426F-4D03-4DBD-8D92-224C026BFADC}.Release|Any CPU.Build.0 = Release|Any CPU - {E4A6624B-C1A4-4956-9FC2-E77D6C634717}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E4A6624B-C1A4-4956-9FC2-E77D6C634717}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E4A6624B-C1A4-4956-9FC2-E77D6C634717}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E4A6624B-C1A4-4956-9FC2-E77D6C634717}.Release|Any CPU.Build.0 = Release|Any CPU {C6C0ED5D-94B4-4CD2-B17A-E72432AC4883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C6C0ED5D-94B4-4CD2-B17A-E72432AC4883}.Debug|Any CPU.Build.0 = Debug|Any CPU {C6C0ED5D-94B4-4CD2-B17A-E72432AC4883}.Release|Any CPU.ActiveCfg = Release|Any CPU