From 5c906e8033d3004d20ec56b071ebbfd6b345ebdb Mon Sep 17 00:00:00 2001 From: David Boike Date: Wed, 10 Jul 2019 16:38:20 -0500 Subject: [PATCH 01/11] Deprecate the ScriptBuilderTask --- ...ServiceBus.Metrics.PerformanceCounters.sln | 6 - ...etrics.PerformanceCounters.sln.DotSettings | 3 + .../CounterNameConventions.cs | 0 ...viceBus.Metrics.PerformanceCounters.csproj | 4 - .../PerformanceCounterSettingsAttribute.cs | 2 + ...CodeGenerationTests.Generates.approved.txt | 60 ---------- ...CodeGenerationTests.Generates.approved.txt | 45 -------- .../CSharpCodeGenerationTests.cs | 43 -------- .../PowershellCodeGenerationTests.cs | 43 -------- .../ScriptBuilderTask.Tests.csproj | 21 ---- src/ScriptBuilderTask/BuildLogger.cs | 32 ------ src/ScriptBuilderTask/BuildScriptVariant.cs | 8 -- src/ScriptBuilderTask/CSharpCounterWriter.cs | 99 ----------------- src/ScriptBuilderTask/CecilExtensions.cs | 82 -------------- src/ScriptBuilderTask/CounterWriter.cs | 41 ------- src/ScriptBuilderTask/DirectoryExtensions.cs | 29 ----- .../Durations/AllDurationsDefinitionReader.cs | 29 ----- .../Durations/DurationDefinition.cs | 15 --- .../Durations/DurationDefinitionReader.cs | 27 ----- src/ScriptBuilderTask/ErrorsException.cs | 13 --- src/ScriptBuilderTask/ExceptionExtensions.cs | 49 --------- src/ScriptBuilderTask/InnerTask.cs | 65 ----------- ...Metrics.PerformanceCounters.MsBuild.nuspec | 2 - ...etrics.PerformanceCounters.MsBuild.targets | 53 +-------- .../PowerShellCounterWriter.cs | 85 -------------- src/ScriptBuilderTask/ScriptBuilderTask.cs | 104 ------------------ .../ScriptBuilderTask.csproj | 4 +- .../ScriptPromotionPathReader.cs | 31 ------ src/ScriptBuilderTask/ScriptVariantReader.cs | 38 ------- .../Signals/AllSignalsDefinitionReader.cs | 29 ----- .../Signals/SignalDefinition.cs | 15 --- .../Signals/SignalDefinitionReader.cs | 26 ----- 32 files changed, 8 insertions(+), 1095 deletions(-) rename src/{ScriptBuilderTask => NServiceBus.Metrics.PerformanceCounters}/CounterNameConventions.cs (100%) delete mode 100644 src/ScriptBuilderTask.Tests/ApprovalFiles/CSharpCodeGenerationTests.Generates.approved.txt delete mode 100644 src/ScriptBuilderTask.Tests/ApprovalFiles/PowershellCodeGenerationTests.Generates.approved.txt delete mode 100644 src/ScriptBuilderTask.Tests/CSharpCodeGenerationTests.cs delete mode 100644 src/ScriptBuilderTask.Tests/PowershellCodeGenerationTests.cs delete mode 100644 src/ScriptBuilderTask.Tests/ScriptBuilderTask.Tests.csproj delete mode 100644 src/ScriptBuilderTask/BuildLogger.cs delete mode 100644 src/ScriptBuilderTask/BuildScriptVariant.cs delete mode 100644 src/ScriptBuilderTask/CSharpCounterWriter.cs delete mode 100644 src/ScriptBuilderTask/CecilExtensions.cs delete mode 100644 src/ScriptBuilderTask/CounterWriter.cs delete mode 100644 src/ScriptBuilderTask/DirectoryExtensions.cs delete mode 100644 src/ScriptBuilderTask/Durations/AllDurationsDefinitionReader.cs delete mode 100644 src/ScriptBuilderTask/Durations/DurationDefinition.cs delete mode 100644 src/ScriptBuilderTask/Durations/DurationDefinitionReader.cs delete mode 100644 src/ScriptBuilderTask/ErrorsException.cs delete mode 100644 src/ScriptBuilderTask/ExceptionExtensions.cs delete mode 100644 src/ScriptBuilderTask/InnerTask.cs mode change 100644 => 100755 src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.nuspec mode change 100644 => 100755 src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets delete mode 100644 src/ScriptBuilderTask/PowerShellCounterWriter.cs delete mode 100644 src/ScriptBuilderTask/ScriptBuilderTask.cs mode change 100644 => 100755 src/ScriptBuilderTask/ScriptBuilderTask.csproj delete mode 100644 src/ScriptBuilderTask/ScriptPromotionPathReader.cs delete mode 100644 src/ScriptBuilderTask/ScriptVariantReader.cs delete mode 100644 src/ScriptBuilderTask/Signals/AllSignalsDefinitionReader.cs delete mode 100644 src/ScriptBuilderTask/Signals/SignalDefinition.cs delete mode 100644 src/ScriptBuilderTask/Signals/SignalDefinitionReader.cs diff --git a/src/NServiceBus.Metrics.PerformanceCounters.sln b/src/NServiceBus.Metrics.PerformanceCounters.sln index e86d426..563fe62 100644 --- a/src/NServiceBus.Metrics.PerformanceCounters.sln +++ b/src/NServiceBus.Metrics.PerformanceCounters.sln @@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NServiceBus.Metrics.Perform EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScriptBuilderTask", "ScriptBuilderTask\ScriptBuilderTask.csproj", "{08FD76CB-6988-485A-A535-B3129AF89C60}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScriptBuilderTask.Tests", "ScriptBuilderTask.Tests\ScriptBuilderTask.Tests.csproj", "{8174164E-52B8-4878-BFB0-34C81A31930E}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1B573EC5-07D6-4E25-9687-FB5A536B4FD9}" ProjectSection(SolutionItems) = preProject Directory.Build.props = Directory.Build.props @@ -35,10 +33,6 @@ Global {08FD76CB-6988-485A-A535-B3129AF89C60}.Debug|Any CPU.Build.0 = Debug|Any CPU {08FD76CB-6988-485A-A535-B3129AF89C60}.Release|Any CPU.ActiveCfg = Release|Any CPU {08FD76CB-6988-485A-A535-B3129AF89C60}.Release|Any CPU.Build.0 = Release|Any CPU - {8174164E-52B8-4878-BFB0-34C81A31930E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8174164E-52B8-4878-BFB0-34C81A31930E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8174164E-52B8-4878-BFB0-34C81A31930E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8174164E-52B8-4878-BFB0-34C81A31930E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/NServiceBus.Metrics.PerformanceCounters.sln.DotSettings b/src/NServiceBus.Metrics.PerformanceCounters.sln.DotSettings index 611eecc..5bbdbe3 100644 --- a/src/NServiceBus.Metrics.PerformanceCounters.sln.DotSettings +++ b/src/NServiceBus.Metrics.PerformanceCounters.sln.DotSettings @@ -557,6 +557,9 @@ II.2.12 <HandlesEvent /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> True + True + True + True True True True diff --git a/src/ScriptBuilderTask/CounterNameConventions.cs b/src/NServiceBus.Metrics.PerformanceCounters/CounterNameConventions.cs similarity index 100% rename from src/ScriptBuilderTask/CounterNameConventions.cs rename to src/NServiceBus.Metrics.PerformanceCounters/CounterNameConventions.cs diff --git a/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj b/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj index f4ddb28..d8b60d9 100644 --- a/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj +++ b/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj @@ -16,8 +16,4 @@ - - - - \ No newline at end of file diff --git a/src/NServiceBus.Metrics.PerformanceCounters/PerformanceCounterSettingsAttribute.cs b/src/NServiceBus.Metrics.PerformanceCounters/PerformanceCounterSettingsAttribute.cs index 8ef822b..fab5cad 100644 --- a/src/NServiceBus.Metrics.PerformanceCounters/PerformanceCounterSettingsAttribute.cs +++ b/src/NServiceBus.Metrics.PerformanceCounters/PerformanceCounterSettingsAttribute.cs @@ -6,6 +6,8 @@ /// Configuration options that are evaluated at compile time. /// [AttributeUsage(AttributeTargets.Assembly)] + [ObsoleteEx(Message = "The NServiceBus.Metrics.PerformanceCounters.MsBuild package is deprecated. There is no longer any need to configure its output.", + RemoveInVersion = "4.0", TreatAsErrorFromVersion = "3.1")] public sealed class PerformanceCounterSettingsAttribute : Attribute { /// diff --git a/src/ScriptBuilderTask.Tests/ApprovalFiles/CSharpCodeGenerationTests.Generates.approved.txt b/src/ScriptBuilderTask.Tests/ApprovalFiles/CSharpCodeGenerationTests.Generates.approved.txt deleted file mode 100644 index e22dc50..0000000 --- a/src/ScriptBuilderTask.Tests/ApprovalFiles/CSharpCodeGenerationTests.Generates.approved.txt +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Diagnostics; -using System.Security; -using System.Runtime.CompilerServices; - -[CompilerGenerated] -public static class CounterCreator -{ - public static void Create() - { - var counterCreationCollection = new CounterCreationDataCollection(Counters); - try - { - var categoryName = "NServiceBus"; - - if (PerformanceCounterCategory.Exists(categoryName)) - { - foreach (CounterCreationData counter in counterCreationCollection) - { - if (!PerformanceCounterCategory.CounterExists(counter.CounterName, categoryName)) - { - PerformanceCounterCategory.Delete(categoryName); - break; - } - } - } - - if (PerformanceCounterCategory.Exists(categoryName) == false) - { - PerformanceCounterCategory.Create( - categoryName: categoryName, - categoryHelp: "NServiceBus statistics", - categoryType: PerformanceCounterCategoryType.MultiInstance, - counterData: counterCreationCollection); - } - - PerformanceCounter.CloseSharedResources(); - } - catch (Exception ex) when(ex is SecurityException || ex is UnauthorizedAccessException) - { - throw new Exception("Execution requires elevated permissions", ex); - } - } - - static CounterCreationData[] Counters = new CounterCreationData[] - { - new CounterCreationData("SLA violation countdown", "Seconds until the SLA for this endpoint is breached.", PerformanceCounterType.NumberOfItems32), - new CounterCreationData("Critical Time Average", "The time it took from sending to processing the message.", PerformanceCounterType.AverageTimer32), - new CounterCreationData("Critical Time AverageBase", "The time it took from sending to processing the message.", PerformanceCounterType.AverageBase), - new CounterCreationData("Critical Time", "The time it took from sending to processing the message.", PerformanceCounterType.NumberOfItems32), - new CounterCreationData("Processing Time Average", "The time it took to successfully process a message.", PerformanceCounterType.AverageTimer32), - new CounterCreationData("Processing Time AverageBase", "The time it took to successfully process a message.", PerformanceCounterType.AverageBase), - new CounterCreationData("Processing Time", "The time it took to successfully process a message.", PerformanceCounterType.NumberOfItems32), - new CounterCreationData("# of msgs failures / sec", "The current number of failed processed messages by the transport per second.", PerformanceCounterType.RateOfCountsPerSecond32), - new CounterCreationData("# of msgs successfully processed / sec", "The current number of messages processed successfully by the transport per second.", PerformanceCounterType.RateOfCountsPerSecond32), - new CounterCreationData("# of msgs pulled from the input queue /sec", "The current number of messages pulled from the input queue by the transport per second.", PerformanceCounterType.RateOfCountsPerSecond32), - new CounterCreationData("Retries", "A message has been scheduled for retry (FLR or SLR)", PerformanceCounterType.RateOfCountsPerSecond32), - - }; -} \ No newline at end of file diff --git a/src/ScriptBuilderTask.Tests/ApprovalFiles/PowershellCodeGenerationTests.Generates.approved.txt b/src/ScriptBuilderTask.Tests/ApprovalFiles/PowershellCodeGenerationTests.Generates.approved.txt deleted file mode 100644 index 53d1d67..0000000 --- a/src/ScriptBuilderTask.Tests/ApprovalFiles/PowershellCodeGenerationTests.Generates.approved.txt +++ /dev/null @@ -1,45 +0,0 @@ - -#requires -RunAsAdministrator -Function InstallNSBPerfCounters { - - $category = @{Name="NServiceBus"; Description="NServiceBus statistics"} - $counters = New-Object System.Diagnostics.CounterCreationDataCollection - $counters.AddRange(@( - New-Object System.Diagnostics.CounterCreationData "SLA violation countdown", "Seconds until the SLA for this endpoint is breached.", NumberOfItems32 - New-Object System.Diagnostics.CounterCreationData "Critical Time Average", "The time it took from sending to processing the message.", AverageTimer32 - New-Object System.Diagnostics.CounterCreationData "Critical Time AverageBase", "The time it took from sending to processing the message.", AverageBase - New-Object System.Diagnostics.CounterCreationData "Critical Time", "The time it took from sending to processing the message.", NumberOfItems32 - New-Object System.Diagnostics.CounterCreationData "Processing Time Average", "The time it took to successfully process a message.", AverageTimer32 - New-Object System.Diagnostics.CounterCreationData "Processing Time AverageBase", "The time it took to successfully process a message.", AverageBase - New-Object System.Diagnostics.CounterCreationData "Processing Time", "The time it took to successfully process a message.", NumberOfItems32 - New-Object System.Diagnostics.CounterCreationData "# of msgs failures / sec", "The current number of failed processed messages by the transport per second.", RateOfCountsPerSecond32 - New-Object System.Diagnostics.CounterCreationData "# of msgs successfully processed / sec", "The current number of messages processed successfully by the transport per second.", RateOfCountsPerSecond32 - New-Object System.Diagnostics.CounterCreationData "# of msgs pulled from the input queue /sec", "The current number of messages pulled from the input queue by the transport per second.", RateOfCountsPerSecond32 - New-Object System.Diagnostics.CounterCreationData "Retries", "A message has been scheduled for retry (FLR or SLR)", RateOfCountsPerSecond32 - - )) - - if ([System.Diagnostics.PerformanceCounterCategory]::Exists($category.Name)) { - - foreach($counter in $counters){ - $exists = [System.Diagnostics.PerformanceCounterCategory]::CounterExists($counter.CounterName, $category.Name) - if (!$exists){ - Write-Host "One or more counters are missing.The performance counter category will be recreated" - [System.Diagnostics.PerformanceCounterCategory]::Delete($category.Name) - - break - } - } - } - - if (![System.Diagnostics.PerformanceCounterCategory]::Exists($category.Name)) { - Write-Host "Creating the performance counter category" - [void] [System.Diagnostics.PerformanceCounterCategory]::Create($category.Name, $category.Description, [System.Diagnostics.PerformanceCounterCategoryType]::MultiInstance, $counters) - } - else { - Write-Host "No performance counters have to be created" - } - - [System.Diagnostics.PerformanceCounter]::CloseSharedResources() -} -InstallNSBPerfCounters diff --git a/src/ScriptBuilderTask.Tests/CSharpCodeGenerationTests.cs b/src/ScriptBuilderTask.Tests/CSharpCodeGenerationTests.cs deleted file mode 100644 index 948e3a9..0000000 --- a/src/ScriptBuilderTask.Tests/CSharpCodeGenerationTests.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace ScriptBuilderTask.Tests -{ - using System; - using System.IO; - using System.Linq; - using NServiceBus.Metrics.PerformanceCounters; - using NUnit.Framework; - using Particular.Approvals; - - [TestFixture] - public class CSharpCodeGenerationTests - { - InnerTask task; - string tempPath; - - [SetUp] - public void SetUp() - { - var testDirectory = TestContext.CurrentContext.TestDirectory; - tempPath = testDirectory; - var assemblyPath = Path.Combine(testDirectory, "ScriptBuilderTask.Tests.dll"); - var metricsAssemblyPath = Path.Combine(testDirectory, "NServiceBus.Metrics.dll"); - var intermediatePath = Path.Combine(tempPath, "IntermediatePath"); - var promotePath = Path.Combine(tempPath, "PromotePath"); - Directory.CreateDirectory(tempPath); - Directory.CreateDirectory(intermediatePath); - - Action logError = (error, s1) => { throw new Exception(error); }; - task = new InnerTask(assemblyPath, metricsAssemblyPath, intermediatePath, "TheProjectDir", promotePath, logError); - } - - [Test] - public void Generates() - { - task.Execute(); - - var cSharpCode = Directory.EnumerateFiles(tempPath, "*.g.cs", SearchOption.AllDirectories).Single(); - var content = File.ReadAllText(cSharpCode); - - Approver.Verify(content); - } - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask.Tests/PowershellCodeGenerationTests.cs b/src/ScriptBuilderTask.Tests/PowershellCodeGenerationTests.cs deleted file mode 100644 index c25513b..0000000 --- a/src/ScriptBuilderTask.Tests/PowershellCodeGenerationTests.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace ScriptBuilderTask.Tests -{ - using System; - using System.IO; - using System.Linq; - using NServiceBus.Metrics.PerformanceCounters; - using NUnit.Framework; - using Particular.Approvals; - - [TestFixture] - public class PowershellCodeGenerationTests - { - InnerTask task; - string tempPath; - - [SetUp] - public void SetUp() - { - var testDirectory = TestContext.CurrentContext.TestDirectory; - tempPath = testDirectory; - var assemblyPath = Path.Combine(testDirectory, "ScriptBuilderTask.Tests.dll"); - var metricsAssemblyPath = Path.Combine(testDirectory, "NServiceBus.Metrics.dll"); - var intermediatePath = Path.Combine(tempPath, "IntermediatePath"); - var promotePath = Path.Combine(tempPath, "PromotePath"); - Directory.CreateDirectory(tempPath); - Directory.CreateDirectory(intermediatePath); - - Action logError = (error, s1) => { throw new Exception(error); }; - task = new InnerTask(assemblyPath, metricsAssemblyPath, intermediatePath, "TheProjectDir", promotePath, logError); - } - - [Test] - public void Generates() - { - task.Execute(); - - var powershell = Directory.EnumerateFiles(tempPath, "*.ps1", SearchOption.AllDirectories).Single(); - var content = File.ReadAllText(powershell); - - Approver.Verify(content); - } - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask.Tests/ScriptBuilderTask.Tests.csproj b/src/ScriptBuilderTask.Tests/ScriptBuilderTask.Tests.csproj deleted file mode 100644 index 659506c..0000000 --- a/src/ScriptBuilderTask.Tests/ScriptBuilderTask.Tests.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - net452 - true - $(SolutionDir)NServiceBus.snk - - - - - - - - - - - - - - - diff --git a/src/ScriptBuilderTask/BuildLogger.cs b/src/ScriptBuilderTask/BuildLogger.cs deleted file mode 100644 index 054d28d..0000000 --- a/src/ScriptBuilderTask/BuildLogger.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using Microsoft.Build.Framework; - - class BuildLogger - { - public BuildLogger(IBuildEngine buildEngine) - { - this.buildEngine = buildEngine; - } - - public void LogInfo(string message) - { - buildEngine.LogMessageEvent(new BuildMessageEventArgs(PrependMessage(message), "", "PerformanceCounterScriptTask", MessageImportance.Normal)); - } - - static string PrependMessage(string message) - { - return $"PerformanceCounterScriptTask: {message}"; - } - - public void LogError(string message, string file = null) - { - ErrorOccurred = true; - buildEngine.LogErrorEvent(new BuildErrorEventArgs("", "", file, 0, 0, 0, 0, PrependMessage(message), "", "PerformanceCounterScriptTask")); - } - - public bool ErrorOccurred; - - IBuildEngine buildEngine; - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/BuildScriptVariant.cs b/src/ScriptBuilderTask/BuildScriptVariant.cs deleted file mode 100644 index 3f5fb8c..0000000 --- a/src/ScriptBuilderTask/BuildScriptVariant.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - public enum BuildScriptVariant - { - CSharp, - Powershell - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/CSharpCounterWriter.cs b/src/ScriptBuilderTask/CSharpCounterWriter.cs deleted file mode 100644 index 22d2459..0000000 --- a/src/ScriptBuilderTask/CSharpCounterWriter.cs +++ /dev/null @@ -1,99 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System.Collections.Generic; - using System.IO; - using System.Text; - - static class CSharpCounterWriter - { - public static void WriteCode(string scriptPath, IEnumerable durations, IEnumerable signals, Dictionary legacyInstanceNameMap) - { - var outputPath = Path.Combine(scriptPath, "Counters.g.cs"); - using (var streamWriter = File.CreateText(outputPath)) - { - var stringBuilder = new StringBuilder(); - - var slaCounterDefinition = @"new CounterCreationData(""SLA violation countdown"", ""Seconds until the SLA for this endpoint is breached."", PerformanceCounterType.NumberOfItems32),"; - stringBuilder.AppendLine(slaCounterDefinition.PadLeft(slaCounterDefinition.Length + 8)); - - foreach (var duration in durations) - { - var averageTimerName = duration.Name.GetAverageTimerCounterName(); - var averageTimerBase = duration.Name.GetAverageTimerBaseCounterName(); - - var durationAverageDefinition = $@"new CounterCreationData(""{averageTimerName}"", ""{duration.Description}"", PerformanceCounterType.AverageTimer32),"; - stringBuilder.AppendLine(durationAverageDefinition.PadLeft(durationAverageDefinition.Length + 8)); - - var durationBaseDefinition = $@"new CounterCreationData(""{averageTimerBase}"", ""{duration.Description}"", PerformanceCounterType.AverageBase),"; - stringBuilder.AppendLine(durationBaseDefinition.PadLeft(durationBaseDefinition.Length + 8)); - - if (duration.Name == CounterNameConventions.ProcessingTime || duration.Name == CounterNameConventions.CriticalTime) - { - var legacyTimerDefinition = $@"new CounterCreationData(""{duration.Name}"", ""{duration.Description}"", PerformanceCounterType.NumberOfItems32),"; - stringBuilder.AppendLine(legacyTimerDefinition.PadLeft(legacyTimerDefinition.Length + 8)); - } - } - - foreach (var signal in signals) - { - legacyInstanceNameMap.TryGetValue(signal.Name, out var instanceName); - - var signalDefinition = $@"new CounterCreationData(""{instanceName ?? signal.Name}"", ""{signal.Description}"", PerformanceCounterType.RateOfCountsPerSecond32),"; - stringBuilder.AppendLine(signalDefinition.PadLeft(signalDefinition.Length + 8)); - } - - streamWriter.Write(Template, stringBuilder); - } - } - - const string Template = @"using System; -using System.Diagnostics; -using System.Security; -using System.Runtime.CompilerServices; - -[CompilerGenerated] -public static class CounterCreator -{{ - public static void Create() - {{ - var counterCreationCollection = new CounterCreationDataCollection(Counters); - try - {{ - var categoryName = ""NServiceBus""; - - if (PerformanceCounterCategory.Exists(categoryName)) - {{ - foreach (CounterCreationData counter in counterCreationCollection) - {{ - if (!PerformanceCounterCategory.CounterExists(counter.CounterName, categoryName)) - {{ - PerformanceCounterCategory.Delete(categoryName); - break; - }} - }} - }} - - if (PerformanceCounterCategory.Exists(categoryName) == false) - {{ - PerformanceCounterCategory.Create( - categoryName: categoryName, - categoryHelp: ""NServiceBus statistics"", - categoryType: PerformanceCounterCategoryType.MultiInstance, - counterData: counterCreationCollection); - }} - - PerformanceCounter.CloseSharedResources(); - }} - catch (Exception ex) when(ex is SecurityException || ex is UnauthorizedAccessException) - {{ - throw new Exception(""Execution requires elevated permissions"", ex); - }} - }} - - static CounterCreationData[] Counters = new CounterCreationData[] - {{ -{0} - }}; -}}"; - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/CecilExtensions.cs b/src/ScriptBuilderTask/CecilExtensions.cs deleted file mode 100644 index 01eebd2..0000000 --- a/src/ScriptBuilderTask/CecilExtensions.cs +++ /dev/null @@ -1,82 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System.Collections.Generic; - using System.Linq; - using Mono.Cecil; - - static class CecilExtensions - { - public static CustomAttribute GetSingleAttribute(this FieldDefinition field, string attributeName) - { - return field.CustomAttributes.SingleOrDefault(x => x.AttributeType.FullName == attributeName); - } - - public static MethodDefinition SingleConstructor(this TypeDefinition type) - { - return type.Methods.Single(method => method.IsConstructor && !method.IsStatic); - } - public static int ParameterIndex(this MethodDefinition method, string name) - { - return method.Parameters.Single(x=>x.Name == name).Index; - } - - public static T ParameterValue(this CustomAttribute attribute, string name) - { - var constructor = attribute.AttributeType.Resolve().SingleConstructor(); - return (T)attribute.ConstructorArguments[constructor.ParameterIndex(name)].Value; - } - - public static string GetStringProperty(this CustomAttribute attribute, string name) - { - return (string)attribute.Properties - .SingleOrDefault(argument => argument.Name == name) - .Argument.Value; - } - - public static bool GetBoolProperty(this CustomAttribute attribute, string name) - { - var value = attribute.Properties - .SingleOrDefault(argument => argument.Name == name) - .Argument.Value; - return value != null && (bool)value; - } - - public static IEnumerable AllClasses(this ModuleDefinition module) - { - return module.GetTypes() - .Where(x => x.IsClass); - } - - - public static string GetFileName(this TypeDefinition type) - { - foreach (var method in type.Methods) - { - var debugInformation = method.DebugInformation; - if (debugInformation == null) - { - continue; - } - if (!debugInformation.HasSequencePoints != true) - { - continue; - } - var body = method.Body; - if (body?.Instructions == null) - { - continue; - } - foreach (var instruction in body.Instructions) - { - var point = debugInformation.GetSequencePoint(instruction); - if (point?.Document?.Url == null) - { - continue; - } - return point.Document.Url; - } - } - return null; - } - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/CounterWriter.cs b/src/ScriptBuilderTask/CounterWriter.cs deleted file mode 100644 index d3bdab2..0000000 --- a/src/ScriptBuilderTask/CounterWriter.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System; - using System.Collections.Generic; - using Mono.Cecil; - - public static class CounterWriter - { - public static void WriteScript(string scriptPath, BuildScriptVariant variant, ModuleDefinition module, Action logError) - { - var timers = AllDurationsDefinitionReader.GetDurations(module, (exception, type) => - { - logError($"Error in '{type.FullName}'. Error:{exception.Message}", type.GetFileName()); - }); - - var meters = AllSignalsDefinitionReader.GetSignals(module, (exception, type) => - { - logError($"Error in '{type.FullName}'. Error:{exception.Message}", type.GetFileName()); - }); - - switch (variant) - { - case BuildScriptVariant.CSharp: - CSharpCounterWriter.WriteCode(scriptPath, timers, meters, legacyInstanceNameMap); - break; - case BuildScriptVariant.Powershell: - PowerShellCounterWriter.WriteScript(scriptPath, timers, meters, legacyInstanceNameMap); - break; - default: - throw new ArgumentOutOfRangeException(nameof(variant), variant, null); - } - } - - static Dictionary legacyInstanceNameMap = new Dictionary - { - {"# of message failures / sec", "# of msgs failures / sec"}, - {"# of messages pulled from the input queue / sec", "# of msgs pulled from the input queue /sec"}, - {"# of messages successfully processed / sec", "# of msgs successfully processed / sec"} - }; - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/DirectoryExtensions.cs b/src/ScriptBuilderTask/DirectoryExtensions.cs deleted file mode 100644 index 38d14db..0000000 --- a/src/ScriptBuilderTask/DirectoryExtensions.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System.IO; - - static class DirectoryExtensions - { - public static void Delete(string path) - { - if (!Directory.Exists(path)) - { - return; - } - Directory.Delete(path, true); - } - - public static void DuplicateDirectory(string source, string destination) - { - foreach (var dirPath in Directory.GetDirectories(source, "*", SearchOption.AllDirectories)) - { - Directory.CreateDirectory(dirPath.Replace(source, destination)); - } - - foreach (var newPath in Directory.GetFiles(source, "*.*", SearchOption.AllDirectories)) - { - File.Copy(newPath, newPath.Replace(source, destination), true); - } - } - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/Durations/AllDurationsDefinitionReader.cs b/src/ScriptBuilderTask/Durations/AllDurationsDefinitionReader.cs deleted file mode 100644 index 6220f5a..0000000 --- a/src/ScriptBuilderTask/Durations/AllDurationsDefinitionReader.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System; - using System.Collections.Generic; - using Mono.Cecil; - - static class AllDurationsDefinitionReader - { - public static IEnumerable GetDurations(ModuleDefinition module, Action logError) - { - var timerDefinitions = new List(); - foreach (var type in module.AllClasses()) - { - try - { - if (DurationDefinitionReader.TryGetDurationDefinition(type, out var definition)) - { - timerDefinitions.AddRange(definition); - } - } - catch (ErrorsException exception) - { - logError(exception, type); - } - } - return timerDefinitions; - } - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/Durations/DurationDefinition.cs b/src/ScriptBuilderTask/Durations/DurationDefinition.cs deleted file mode 100644 index 86ee1df..0000000 --- a/src/ScriptBuilderTask/Durations/DurationDefinition.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - class DurationDefinition - { - public DurationDefinition(string name, string description) - { - Name = name; - Description = description; - } - - public readonly string Description; - - public readonly string Name; - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/Durations/DurationDefinitionReader.cs b/src/ScriptBuilderTask/Durations/DurationDefinitionReader.cs deleted file mode 100644 index 5a38e35..0000000 --- a/src/ScriptBuilderTask/Durations/DurationDefinitionReader.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System.Collections.Generic; - using System.Linq; - using Mono.Cecil; - - static class DurationDefinitionReader - { - public static bool TryGetDurationDefinition(TypeDefinition type, out List definitions) - { - definitions = new List(); - if (type.BaseType != null && type.BaseType.FullName == "DurationProbeBuilder") - { - var attributes = type.CustomAttributes.Where(a => a.AttributeType.FullName == "ProbePropertiesAttribute"); - - foreach (var attribute in attributes) - { - var name = attribute.ParameterValue("name"); - var description = attribute.ParameterValue("description"); - - definitions.Add(new DurationDefinition(name, description)); - } - } - return definitions.Count > 0; - } - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/ErrorsException.cs b/src/ScriptBuilderTask/ErrorsException.cs deleted file mode 100644 index 4463714..0000000 --- a/src/ScriptBuilderTask/ErrorsException.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System; - - public class ErrorsException : Exception - { - public ErrorsException(string message) : base(message) - { - } - - public string FileName { get; set; } - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/ExceptionExtensions.cs b/src/ScriptBuilderTask/ExceptionExtensions.cs deleted file mode 100644 index de0bcf6..0000000 --- a/src/ScriptBuilderTask/ExceptionExtensions.cs +++ /dev/null @@ -1,49 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System; - using System.Text; - - static class ExceptionExtensions - { - public static string ToFriendlyString(this Exception exception) - { - var stringBuilder = new StringBuilder(); - stringBuilder.Append("An unhandled exception occurred:"); - stringBuilder.Append(Environment.NewLine); - stringBuilder.Append("Exception:"); - stringBuilder.Append(Environment.NewLine); - while (exception != null) - { - stringBuilder.Append(exception.Message); - stringBuilder.Append(Environment.NewLine); - - foreach (var i in exception.Data) - { - stringBuilder.Append("Data :"); - stringBuilder.Append(i); - stringBuilder.Append(Environment.NewLine); - } - - if (exception.StackTrace != null) - { - stringBuilder.Append("StackTrace:"); - stringBuilder.Append(Environment.NewLine); - stringBuilder.Append(exception.StackTrace); - stringBuilder.Append(Environment.NewLine); - } - - if (exception.Source != null) - { - stringBuilder.Append("Source:"); - stringBuilder.Append(Environment.NewLine); - stringBuilder.Append(exception.Source); - stringBuilder.Append(Environment.NewLine); - } - - exception = exception.InnerException; - } - - return stringBuilder.ToString(); - } - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/InnerTask.cs b/src/ScriptBuilderTask/InnerTask.cs deleted file mode 100644 index 62e83aa..0000000 --- a/src/ScriptBuilderTask/InnerTask.cs +++ /dev/null @@ -1,65 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System; - using System.IO; - using Mono.Cecil; - - public class InnerTask - { - public InnerTask(string assemblyPath, string metricsAssemblyPath, string intermediateDirectory, string projectDirectory, string solutionDirectory, Action logError) - { - this.metricsAssemblyPath = metricsAssemblyPath; - this.assemblyPath = assemblyPath; - this.intermediateDirectory = intermediateDirectory; - this.projectDirectory = projectDirectory; - this.solutionDirectory = solutionDirectory; - this.logError = logError; - } - - public void Execute() - { - var scriptPath = Path.Combine(intermediateDirectory, "NServiceBus.Metrics.PerformanceCounters"); - DirectoryExtensions.Delete(scriptPath); - Directory.CreateDirectory(scriptPath); - - var assemblyModuleDefinition = ModuleDefinition.ReadModule(assemblyPath, new ReaderParameters(ReadingMode.Deferred)); - var metricsAssemblyModuleDefinition = ModuleDefinition.ReadModule(metricsAssemblyPath, new ReaderParameters(ReadingMode.Deferred)); - - foreach (var variant in ScriptVariantReader.Read(assemblyModuleDefinition)) - { - var variantPath = Path.Combine(scriptPath, variant.ToString()); - Directory.CreateDirectory(variantPath); - CounterWriter.WriteScript(variantPath, variant, metricsAssemblyModuleDefinition, logError); - } - - PromoteFiles(assemblyModuleDefinition, scriptPath); - } - - void PromoteFiles(ModuleDefinition moduleDefinition, string scriptPath) - { - if (!ScriptPromotionPathReader.TryRead(moduleDefinition, out var customPath)) - { - return; - } - var replicationPath = customPath - .Replace("$(ProjectDir)", projectDirectory) - .Replace("$(SolutionDir)", solutionDirectory); - try - { - DirectoryExtensions.Delete(replicationPath); - DirectoryExtensions.DuplicateDirectory(scriptPath, replicationPath); - } - catch (Exception exception) - { - throw new ErrorsException($"Failed to promote scripts to '{replicationPath}'. Error: {exception.Message}"); - } - } - - string assemblyPath; - string intermediateDirectory; - string projectDirectory; - string solutionDirectory; - Action logError; - string metricsAssemblyPath; - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.nuspec b/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.nuspec old mode 100644 new mode 100755 index b7fd5ae..cbd192c --- a/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.nuspec +++ b/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.nuspec @@ -18,8 +18,6 @@ - - diff --git a/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets b/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets old mode 100644 new mode 100755 index 8bf8673..358e9e8 --- a/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets +++ b/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets @@ -1,57 +1,8 @@  - - - - $(MSBuildThisFileDirectory)..\netstandard\NServiceBus.Metrics.PerformanceCounters.Task.dll - - - - - $(MSBuildThisFileDirectory)..\netclassic\NServiceBus.Metrics.PerformanceCounters.Task.dll - - - - - - - - $(ProjectDir)$(IntermediateOutputPath)NServiceBus.Metrics.PerformanceCounters\ - - - - - - - - - - - - - - - + + - - - - - \ No newline at end of file diff --git a/src/ScriptBuilderTask/PowerShellCounterWriter.cs b/src/ScriptBuilderTask/PowerShellCounterWriter.cs deleted file mode 100644 index 461e338..0000000 --- a/src/ScriptBuilderTask/PowerShellCounterWriter.cs +++ /dev/null @@ -1,85 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System.Collections.Generic; - using System.IO; - using System.Text; - - static class PowerShellCounterWriter - { - public static void WriteScript(string scriptPath, IEnumerable durations, IEnumerable signals, Dictionary legacyInstanceNameMap) - { - var outputPath = Path.Combine(scriptPath, "CreateNSBPerfCounters.ps1"); - using (var streamWriter = File.CreateText(outputPath)) - { - var stringBuilder = new StringBuilder(); - - var slaCounterDefinition = @"New-Object System.Diagnostics.CounterCreationData ""SLA violation countdown"", ""Seconds until the SLA for this endpoint is breached."", NumberOfItems32"; - stringBuilder.AppendLine(slaCounterDefinition.PadLeft(slaCounterDefinition.Length + 8)); - - foreach (var duration in durations) - { - var averageTimerName = duration.Name.GetAverageTimerCounterName(); - var averageTimerBase = duration.Name.GetAverageTimerBaseCounterName(); - - var durationAverageDefinition = $@"New-Object System.Diagnostics.CounterCreationData ""{averageTimerName}"", ""{duration.Description}"", AverageTimer32"; - stringBuilder.AppendLine(durationAverageDefinition.PadLeft(durationAverageDefinition.Length + 8)); - - var durationBaseDefinition = $@"New-Object System.Diagnostics.CounterCreationData ""{averageTimerBase}"", ""{duration.Description}"", AverageBase"; - stringBuilder.AppendLine(durationBaseDefinition.PadLeft(durationBaseDefinition.Length + 8)); - - if (duration.Name == CounterNameConventions.ProcessingTime || duration.Name == CounterNameConventions.CriticalTime) - { - var legacyTimerDefinition = $@"New-Object System.Diagnostics.CounterCreationData ""{duration.Name}"", ""{duration.Description}"", NumberOfItems32"; - stringBuilder.AppendLine(legacyTimerDefinition.PadLeft(legacyTimerDefinition.Length + 8)); - } - } - - foreach (var signal in signals) - { - legacyInstanceNameMap.TryGetValue(signal.Name, out var instanceName); - - var signalDefinition = $@"New-Object System.Diagnostics.CounterCreationData ""{instanceName ?? signal.Name}"", ""{signal.Description}"", RateOfCountsPerSecond32"; - stringBuilder.AppendLine(signalDefinition.PadLeft(signalDefinition.Length + 8)); - } - - streamWriter.Write(Template, stringBuilder); - } - } - - const string Template = @" -#requires -RunAsAdministrator -Function InstallNSBPerfCounters {{ - - $category = @{{Name=""NServiceBus""; Description=""NServiceBus statistics""}} - $counters = New-Object System.Diagnostics.CounterCreationDataCollection - $counters.AddRange(@( -{0} - )) - - if ([System.Diagnostics.PerformanceCounterCategory]::Exists($category.Name)) {{ - - foreach($counter in $counters){{ - $exists = [System.Diagnostics.PerformanceCounterCategory]::CounterExists($counter.CounterName, $category.Name) - if (!$exists){{ - Write-Host ""One or more counters are missing.The performance counter category will be recreated"" - [System.Diagnostics.PerformanceCounterCategory]::Delete($category.Name) - - break - }} - }} - }} - - if (![System.Diagnostics.PerformanceCounterCategory]::Exists($category.Name)) {{ - Write-Host ""Creating the performance counter category"" - [void] [System.Diagnostics.PerformanceCounterCategory]::Create($category.Name, $category.Description, [System.Diagnostics.PerformanceCounterCategoryType]::MultiInstance, $counters) - }} - else {{ - Write-Host ""No performance counters have to be created"" - }} - - [System.Diagnostics.PerformanceCounter]::CloseSharedResources() -}} -InstallNSBPerfCounters -"; - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/ScriptBuilderTask.cs b/src/ScriptBuilderTask/ScriptBuilderTask.cs deleted file mode 100644 index 215a37c..0000000 --- a/src/ScriptBuilderTask/ScriptBuilderTask.cs +++ /dev/null @@ -1,104 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.IO; - using System.Linq; - using System.Reflection; - using Microsoft.Build.Framework; - using Microsoft.Build.Utilities; - - public class ScriptBuilderTask : Task - { - [Required] - public string AssemblyPath { get; set; } - - [Required] - public string References { get; set; } - - [Required] - public ITaskItem[] ReferenceCopyLocalPaths { get; set; } - - [Required] - public string IntermediateDirectory { get; set; } - - [Required] - public string ProjectDirectory { get; set; } - - [Required] - public string SolutionDirectory { get; set; } - - public Dictionary ReferenceDictionary { get; } = new Dictionary(StringComparer.OrdinalIgnoreCase); - - public override bool Execute() - { - logger = new BuildLogger(BuildEngine); - logger.LogInfo($"ScriptBuilderTask (version {typeof(ScriptBuilderTask).GetTypeInfo().Assembly.GetName().Version}) Executing"); - - var stopwatch = Stopwatch.StartNew(); - - var referenceCopyLocalPaths = ReferenceCopyLocalPaths.Select(x => x.ItemSpec); - var splitReferences = References.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Union(referenceCopyLocalPaths, StringComparer.OrdinalIgnoreCase); - foreach (var filePath in splitReferences) - { - var fileNameWithExtension = Path.GetFileName(filePath); - ReferenceDictionary[fileNameWithExtension] = filePath; - - logger.LogInfo($"ScriptBuilderTask (Reference {fileNameWithExtension} located at {filePath})"); - } - - try - { - ValidateInputs(); - Action logError = (error, file) => { logger.LogError(error, file); }; - var innerTask = new InnerTask(AssemblyPath, ReferenceDictionary["NServiceBus.Metrics.dll"], IntermediateDirectory, ProjectDirectory, SolutionDirectory, logError); - innerTask.Execute(); - } - catch (ErrorsException exception) - { - logger.LogError(exception.Message, exception.FileName); - } - catch (Exception exception) - { - logger.LogError(exception.ToFriendlyString()); - } - finally - { - logger.LogInfo($" Finished ScriptBuilderTask {stopwatch.ElapsedMilliseconds}ms."); - } - return !logger.ErrorOccurred; - } - - - void ValidateInputs() - { - if (!File.Exists(AssemblyPath)) - { - throw new ErrorsException($"AssemblyPath '{AssemblyPath}' does not exist."); - } - - if (!Directory.Exists(IntermediateDirectory)) - { - throw new ErrorsException($"IntermediateDirectory '{IntermediateDirectory}' does not exist."); - } - - if (!Directory.Exists(ProjectDirectory)) - { - throw new ErrorsException($"ProjectDirectory '{ProjectDirectory}' does not exist."); - } - - if (!Directory.Exists(SolutionDirectory)) - { - throw new ErrorsException($"SolutionDirectory '{SolutionDirectory}' does not exist."); - } - - if (!ReferenceDictionary.TryGetValue("NServiceBus.Metrics.dll", out _)) - { - throw new ErrorsException("NServiceBus.Metrics.dll is not referenced in this assembly."); - } - } - - BuildLogger logger; - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/ScriptBuilderTask.csproj b/src/ScriptBuilderTask/ScriptBuilderTask.csproj old mode 100644 new mode 100755 index 6881c22..ccbcdf6 --- a/src/ScriptBuilderTask/ScriptBuilderTask.csproj +++ b/src/ScriptBuilderTask/ScriptBuilderTask.csproj @@ -11,8 +11,6 @@ - - @@ -32,7 +30,7 @@ NServiceBus.Metrics.PerformanceCounters.MsBuild - MsBuild Task for building deployment scripts for the NServiceBus.Metrics.PerformanceCounters package. + This package is deprecated and should no longer be referenced. The functionality was merged into the NServiceBus.Metrics.PerformanceCounters package. $(MSBuildThisFileDirectory)$(PackageId).nuspec true diff --git a/src/ScriptBuilderTask/ScriptPromotionPathReader.cs b/src/ScriptBuilderTask/ScriptPromotionPathReader.cs deleted file mode 100644 index 8fde430..0000000 --- a/src/ScriptBuilderTask/ScriptPromotionPathReader.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System.Linq; - using Mono.Cecil; - - public static class ScriptPromotionPathReader - { - public static bool TryRead(ModuleDefinition moduleDefinition, out string target) - { - var customAttribute = moduleDefinition.Assembly.CustomAttributes - .FirstOrDefault(x => x.AttributeType.FullName == "NServiceBus.Metrics.PerformanceCounters.PerformanceCounterSettingsAttribute"); - if (customAttribute == null) - { - target = null; - return false; - } - - target = customAttribute.GetStringProperty("ScriptPromotionPath"); - if (target == null) - { - return false; - } - if (!string.IsNullOrWhiteSpace(target)) - { - return true; - } - throw new ErrorsException("PerformanceCounterSettingsAttribute contains an empty ScriptPromotionPath."); - } - - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/ScriptVariantReader.cs b/src/ScriptBuilderTask/ScriptVariantReader.cs deleted file mode 100644 index d1a3171..0000000 --- a/src/ScriptBuilderTask/ScriptVariantReader.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Mono.Cecil; - -namespace NServiceBus.Metrics.PerformanceCounters -{ - public static class ScriptVariantReader - { - public static IEnumerable Read(ModuleDefinition moduleDefinition) - { - var attribute = moduleDefinition.Assembly.CustomAttributes - .FirstOrDefault(x => x.AttributeType.FullName == "NServiceBus.Metrics.PerformanceCounters.PerformanceCounterSettingsAttribute"); - if (attribute == null) - { - yield return BuildScriptVariant.CSharp; - yield return BuildScriptVariant.Powershell; - yield break; - } - - var csharpScripts = attribute.GetBoolProperty("CSharp"); - if (csharpScripts) - { - yield return BuildScriptVariant.CSharp; - } - - var powerShellScripts = attribute.GetBoolProperty("Powershell"); - if (powerShellScripts) - { - yield return BuildScriptVariant.Powershell; - } - - if (!csharpScripts && !powerShellScripts) - { - throw new ErrorsException("Must define either CSharpScripts, PowershellScripts, or both. Add a [PerformanceCounterSettingsAttribute] to the assembly."); - } - } - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/Signals/AllSignalsDefinitionReader.cs b/src/ScriptBuilderTask/Signals/AllSignalsDefinitionReader.cs deleted file mode 100644 index 6b1be48..0000000 --- a/src/ScriptBuilderTask/Signals/AllSignalsDefinitionReader.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System; - using System.Collections.Generic; - using Mono.Cecil; - - static class AllSignalsDefinitionReader - { - public static IEnumerable GetSignals(ModuleDefinition module, Action logError) - { - var timerDefinitions = new List(); - foreach (var type in module.AllClasses()) - { - try - { - if (SignalDefinitionReader.TryGetSignalDefinition(type, out var definition)) - { - timerDefinitions.AddRange(definition); - } - } - catch (ErrorsException exception) - { - logError(exception, type); - } - } - return timerDefinitions; - } - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/Signals/SignalDefinition.cs b/src/ScriptBuilderTask/Signals/SignalDefinition.cs deleted file mode 100644 index 4a8ee3c..0000000 --- a/src/ScriptBuilderTask/Signals/SignalDefinition.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - class SignalDefinition - { - public SignalDefinition(string name, string description) - { - Name = name; - Description = description; - } - - public readonly string Description; - - public readonly string Name; - } -} \ No newline at end of file diff --git a/src/ScriptBuilderTask/Signals/SignalDefinitionReader.cs b/src/ScriptBuilderTask/Signals/SignalDefinitionReader.cs deleted file mode 100644 index 76e7693..0000000 --- a/src/ScriptBuilderTask/Signals/SignalDefinitionReader.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System.Collections.Generic; - using System.Linq; - using Mono.Cecil; - - static class SignalDefinitionReader - { - public static bool TryGetSignalDefinition(TypeDefinition type, out List definitions) - { - definitions = new List(); - if (type.BaseType != null && type.BaseType.FullName == "SignalProbeBuilder") - { - var attributes = type.CustomAttributes.Where(a => a.AttributeType.FullName == "ProbePropertiesAttribute"); - - foreach (var attribute in attributes) - { - var name = attribute.ParameterValue("name"); - var description = attribute.ParameterValue("description"); - definitions.Add(new SignalDefinition(name, description)); - } - } - return definitions.Count > 0; - } - } -} \ No newline at end of file From 6f5a47b1780eb1d5be8c4f12246151ed0089199f Mon Sep 17 00:00:00 2001 From: David Boike Date: Thu, 11 Jul 2019 13:56:21 -0500 Subject: [PATCH 02/11] Include scripts in build output --- ...viceBus.Metrics.PerformanceCounters.csproj | 9 +++ .../Scripts/Counters.g.cs | 65 +++++++++++++++++++ .../Scripts/CreateNSBPerfCounters.ps1 | 45 +++++++++++++ ...rviceBus.Metrics.PerformanceCounters.props | 16 +++++ 4 files changed, 135 insertions(+) mode change 100644 => 100755 src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj create mode 100755 src/NServiceBus.Metrics.PerformanceCounters/Scripts/Counters.g.cs create mode 100755 src/NServiceBus.Metrics.PerformanceCounters/Scripts/CreateNSBPerfCounters.ps1 create mode 100755 src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props diff --git a/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj b/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj old mode 100644 new mode 100755 index d8b60d9..a0bdadc --- a/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj +++ b/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj @@ -6,8 +6,17 @@ $(SolutionDir)NServiceBus.snk ..\..\binaries\ Enables access to performance counters + + $(NoWarn);NU5110;NU5111 + + + + + + + diff --git a/src/NServiceBus.Metrics.PerformanceCounters/Scripts/Counters.g.cs b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/Counters.g.cs new file mode 100755 index 0000000..b0fdcec --- /dev/null +++ b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/Counters.g.cs @@ -0,0 +1,65 @@ +using System; +using System.Diagnostics; +using System.Security; +using System.Runtime.CompilerServices; + +/// +/// Provides a utility method to create PerformanceCounter objects +/// +public static class CounterCreator +{ + /// + /// Create PerformanceCounter objects + /// + public static void Create() + { + var counterCreationCollection = new CounterCreationDataCollection(Counters); + try + { + var categoryName = "NServiceBus"; + + if (PerformanceCounterCategory.Exists(categoryName)) + { + foreach (CounterCreationData counter in counterCreationCollection) + { + if (!PerformanceCounterCategory.CounterExists(counter.CounterName, categoryName)) + { + PerformanceCounterCategory.Delete(categoryName); + break; + } + } + } + + if (PerformanceCounterCategory.Exists(categoryName) == false) + { + PerformanceCounterCategory.Create( + categoryName: categoryName, + categoryHelp: "NServiceBus statistics", + categoryType: PerformanceCounterCategoryType.MultiInstance, + counterData: counterCreationCollection); + } + + PerformanceCounter.CloseSharedResources(); + } + catch (Exception ex) when(ex is SecurityException || ex is UnauthorizedAccessException) + { + throw new Exception("Execution requires elevated permissions", ex); + } + } + + static CounterCreationData[] Counters = new CounterCreationData[] + { + new CounterCreationData("SLA violation countdown", "Seconds until the SLA for this endpoint is breached.", PerformanceCounterType.NumberOfItems32), + new CounterCreationData("Critical Time Average", "The time it took from sending to processing the message.", PerformanceCounterType.AverageTimer32), + new CounterCreationData("Critical Time AverageBase", "The time it took from sending to processing the message.", PerformanceCounterType.AverageBase), + new CounterCreationData("Critical Time", "The time it took from sending to processing the message.", PerformanceCounterType.NumberOfItems32), + new CounterCreationData("Processing Time Average", "The time it took to successfully process a message.", PerformanceCounterType.AverageTimer32), + new CounterCreationData("Processing Time AverageBase", "The time it took to successfully process a message.", PerformanceCounterType.AverageBase), + new CounterCreationData("Processing Time", "The time it took to successfully process a message.", PerformanceCounterType.NumberOfItems32), + new CounterCreationData("# of msgs failures / sec", "The current number of failed processed messages by the transport per second.", PerformanceCounterType.RateOfCountsPerSecond32), + new CounterCreationData("# of msgs successfully processed / sec", "The current number of messages processed successfully by the transport per second.", PerformanceCounterType.RateOfCountsPerSecond32), + new CounterCreationData("# of msgs pulled from the input queue /sec", "The current number of messages pulled from the input queue by the transport per second.", PerformanceCounterType.RateOfCountsPerSecond32), + new CounterCreationData("Retries", "A message has been scheduled for retry (FLR or SLR)", PerformanceCounterType.RateOfCountsPerSecond32), + + }; +} \ No newline at end of file diff --git a/src/NServiceBus.Metrics.PerformanceCounters/Scripts/CreateNSBPerfCounters.ps1 b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/CreateNSBPerfCounters.ps1 new file mode 100755 index 0000000..53d1d67 --- /dev/null +++ b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/CreateNSBPerfCounters.ps1 @@ -0,0 +1,45 @@ + +#requires -RunAsAdministrator +Function InstallNSBPerfCounters { + + $category = @{Name="NServiceBus"; Description="NServiceBus statistics"} + $counters = New-Object System.Diagnostics.CounterCreationDataCollection + $counters.AddRange(@( + New-Object System.Diagnostics.CounterCreationData "SLA violation countdown", "Seconds until the SLA for this endpoint is breached.", NumberOfItems32 + New-Object System.Diagnostics.CounterCreationData "Critical Time Average", "The time it took from sending to processing the message.", AverageTimer32 + New-Object System.Diagnostics.CounterCreationData "Critical Time AverageBase", "The time it took from sending to processing the message.", AverageBase + New-Object System.Diagnostics.CounterCreationData "Critical Time", "The time it took from sending to processing the message.", NumberOfItems32 + New-Object System.Diagnostics.CounterCreationData "Processing Time Average", "The time it took to successfully process a message.", AverageTimer32 + New-Object System.Diagnostics.CounterCreationData "Processing Time AverageBase", "The time it took to successfully process a message.", AverageBase + New-Object System.Diagnostics.CounterCreationData "Processing Time", "The time it took to successfully process a message.", NumberOfItems32 + New-Object System.Diagnostics.CounterCreationData "# of msgs failures / sec", "The current number of failed processed messages by the transport per second.", RateOfCountsPerSecond32 + New-Object System.Diagnostics.CounterCreationData "# of msgs successfully processed / sec", "The current number of messages processed successfully by the transport per second.", RateOfCountsPerSecond32 + New-Object System.Diagnostics.CounterCreationData "# of msgs pulled from the input queue /sec", "The current number of messages pulled from the input queue by the transport per second.", RateOfCountsPerSecond32 + New-Object System.Diagnostics.CounterCreationData "Retries", "A message has been scheduled for retry (FLR or SLR)", RateOfCountsPerSecond32 + + )) + + if ([System.Diagnostics.PerformanceCounterCategory]::Exists($category.Name)) { + + foreach($counter in $counters){ + $exists = [System.Diagnostics.PerformanceCounterCategory]::CounterExists($counter.CounterName, $category.Name) + if (!$exists){ + Write-Host "One or more counters are missing.The performance counter category will be recreated" + [System.Diagnostics.PerformanceCounterCategory]::Delete($category.Name) + + break + } + } + } + + if (![System.Diagnostics.PerformanceCounterCategory]::Exists($category.Name)) { + Write-Host "Creating the performance counter category" + [void] [System.Diagnostics.PerformanceCounterCategory]::Create($category.Name, $category.Description, [System.Diagnostics.PerformanceCounterCategoryType]::MultiInstance, $counters) + } + else { + Write-Host "No performance counters have to be created" + } + + [System.Diagnostics.PerformanceCounter]::CloseSharedResources() +} +InstallNSBPerfCounters diff --git a/src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props new file mode 100755 index 0000000..d5c985c --- /dev/null +++ b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props @@ -0,0 +1,16 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + + + + PreserveNewest + NServiceBus.Metrics.PerformanceCounters\CSharp\%(Filename)%(Extension) + + + PreserveNewest + NServiceBus.Metrics.PerformanceCounters\Powershell\%(Filename)%(Extension) + + + \ No newline at end of file From cae6426f3fc9121a77d6e887564e057f31a4a6c0 Mon Sep 17 00:00:00 2001 From: David Boike Date: Thu, 11 Jul 2019 15:36:57 -0500 Subject: [PATCH 03/11] New major, remove C# script, adjust deprecations to errors --- GitVersion.yml | 2 +- ...viceBus.Metrics.PerformanceCounters.csproj | 2 - .../PerformanceCounterSettingsAttribute.cs | 4 +- .../Scripts/Counters.g.cs | 65 ------------------- ...rviceBus.Metrics.PerformanceCounters.props | 6 +- ...etrics.PerformanceCounters.MsBuild.targets | 2 +- 6 files changed, 5 insertions(+), 76 deletions(-) mode change 100644 => 100755 GitVersion.yml mode change 100644 => 100755 src/NServiceBus.Metrics.PerformanceCounters/PerformanceCounterSettingsAttribute.cs delete mode 100755 src/NServiceBus.Metrics.PerformanceCounters/Scripts/Counters.g.cs diff --git a/GitVersion.yml b/GitVersion.yml old mode 100644 new mode 100755 index 9f8957b..71b10bb --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,5 +1,5 @@ assembly-versioning-scheme: Major -next-version: 3.0 +next-version: 4.0 branches: develop: tag: beta diff --git a/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj b/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj index a0bdadc..4a3bd40 100755 --- a/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj +++ b/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj @@ -11,8 +11,6 @@ - - diff --git a/src/NServiceBus.Metrics.PerformanceCounters/PerformanceCounterSettingsAttribute.cs b/src/NServiceBus.Metrics.PerformanceCounters/PerformanceCounterSettingsAttribute.cs old mode 100644 new mode 100755 index fab5cad..0c31399 --- a/src/NServiceBus.Metrics.PerformanceCounters/PerformanceCounterSettingsAttribute.cs +++ b/src/NServiceBus.Metrics.PerformanceCounters/PerformanceCounterSettingsAttribute.cs @@ -6,8 +6,8 @@ /// Configuration options that are evaluated at compile time. /// [AttributeUsage(AttributeTargets.Assembly)] - [ObsoleteEx(Message = "The NServiceBus.Metrics.PerformanceCounters.MsBuild package is deprecated. There is no longer any need to configure its output.", - RemoveInVersion = "4.0", TreatAsErrorFromVersion = "3.1")] + [ObsoleteEx(Message = "The NServiceBus.Metrics.PerformanceCounters.MsBuild package is deprecated. There is no longer any need to configure its output. To promote the script outside the build directory, use a post-build event.", + RemoveInVersion = "5.0", TreatAsErrorFromVersion = "4.0")] public sealed class PerformanceCounterSettingsAttribute : Attribute { /// diff --git a/src/NServiceBus.Metrics.PerformanceCounters/Scripts/Counters.g.cs b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/Counters.g.cs deleted file mode 100755 index b0fdcec..0000000 --- a/src/NServiceBus.Metrics.PerformanceCounters/Scripts/Counters.g.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Diagnostics; -using System.Security; -using System.Runtime.CompilerServices; - -/// -/// Provides a utility method to create PerformanceCounter objects -/// -public static class CounterCreator -{ - /// - /// Create PerformanceCounter objects - /// - public static void Create() - { - var counterCreationCollection = new CounterCreationDataCollection(Counters); - try - { - var categoryName = "NServiceBus"; - - if (PerformanceCounterCategory.Exists(categoryName)) - { - foreach (CounterCreationData counter in counterCreationCollection) - { - if (!PerformanceCounterCategory.CounterExists(counter.CounterName, categoryName)) - { - PerformanceCounterCategory.Delete(categoryName); - break; - } - } - } - - if (PerformanceCounterCategory.Exists(categoryName) == false) - { - PerformanceCounterCategory.Create( - categoryName: categoryName, - categoryHelp: "NServiceBus statistics", - categoryType: PerformanceCounterCategoryType.MultiInstance, - counterData: counterCreationCollection); - } - - PerformanceCounter.CloseSharedResources(); - } - catch (Exception ex) when(ex is SecurityException || ex is UnauthorizedAccessException) - { - throw new Exception("Execution requires elevated permissions", ex); - } - } - - static CounterCreationData[] Counters = new CounterCreationData[] - { - new CounterCreationData("SLA violation countdown", "Seconds until the SLA for this endpoint is breached.", PerformanceCounterType.NumberOfItems32), - new CounterCreationData("Critical Time Average", "The time it took from sending to processing the message.", PerformanceCounterType.AverageTimer32), - new CounterCreationData("Critical Time AverageBase", "The time it took from sending to processing the message.", PerformanceCounterType.AverageBase), - new CounterCreationData("Critical Time", "The time it took from sending to processing the message.", PerformanceCounterType.NumberOfItems32), - new CounterCreationData("Processing Time Average", "The time it took to successfully process a message.", PerformanceCounterType.AverageTimer32), - new CounterCreationData("Processing Time AverageBase", "The time it took to successfully process a message.", PerformanceCounterType.AverageBase), - new CounterCreationData("Processing Time", "The time it took to successfully process a message.", PerformanceCounterType.NumberOfItems32), - new CounterCreationData("# of msgs failures / sec", "The current number of failed processed messages by the transport per second.", PerformanceCounterType.RateOfCountsPerSecond32), - new CounterCreationData("# of msgs successfully processed / sec", "The current number of messages processed successfully by the transport per second.", PerformanceCounterType.RateOfCountsPerSecond32), - new CounterCreationData("# of msgs pulled from the input queue /sec", "The current number of messages pulled from the input queue by the transport per second.", PerformanceCounterType.RateOfCountsPerSecond32), - new CounterCreationData("Retries", "A message has been scheduled for retry (FLR or SLR)", PerformanceCounterType.RateOfCountsPerSecond32), - - }; -} \ No newline at end of file diff --git a/src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props index d5c985c..41ecaa4 100755 --- a/src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props +++ b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props @@ -4,13 +4,9 @@ $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - - PreserveNewest - NServiceBus.Metrics.PerformanceCounters\CSharp\%(Filename)%(Extension) - PreserveNewest - NServiceBus.Metrics.PerformanceCounters\Powershell\%(Filename)%(Extension) + NServiceBus.Metrics.PerformanceCounters\%(Filename)%(Extension) \ No newline at end of file diff --git a/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets b/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets index 358e9e8..3e9ec44 100755 --- a/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets +++ b/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets @@ -2,7 +2,7 @@ - + \ No newline at end of file From 3395185438289a94e0e7d80fd61ea46f80be9226 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Thu, 11 Jul 2019 17:02:39 -0400 Subject: [PATCH 04/11] Simplify ScriptBuilderTask --- ...etrics.PerformanceCounters.MsBuild.targets | 3 +- .../ScriptBuilderTask.csproj | 53 +++---------------- 2 files changed, 7 insertions(+), 49 deletions(-) diff --git a/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets b/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets index 3e9ec44..3e60d3f 100755 --- a/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets +++ b/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets @@ -1,5 +1,4 @@ - - + diff --git a/src/ScriptBuilderTask/ScriptBuilderTask.csproj b/src/ScriptBuilderTask/ScriptBuilderTask.csproj index ccbcdf6..ae083b1 100755 --- a/src/ScriptBuilderTask/ScriptBuilderTask.csproj +++ b/src/ScriptBuilderTask/ScriptBuilderTask.csproj @@ -1,63 +1,22 @@  - net452;netstandard1.5 - true - NServiceBus.Metrics.PerformanceCounters.Task - $(SolutionDir)NServiceBus.snk - ..\..\binaries\ - $(NoWarn);CS1591 - - - - - - - - - - - - - - - - - - - - - - + net452 NServiceBus.Metrics.PerformanceCounters.MsBuild This package is deprecated and should no longer be referenced. The functionality was merged into the NServiceBus.Metrics.PerformanceCounters package. $(MSBuildThisFileDirectory)$(PackageId).nuspec true + false + + + + id=$(PackageId);version=$(PackageVersion);authors=$(Authors);owners=$(Authors);licenseUrl=$(PackageLicenseUrl);requireLicenseAcceptance=$(PackageRequireLicenseAcceptance);iconUrl=$(PackageIconUrl);projectUrl=$(PackageProjectUrl);description=$(Description);copyright=$(Copyright);tags=$(PackageTags) - - - true - - - - - $(ProjectDir)$(OutputPath)temp - - - - - - - - - - - \ No newline at end of file From 3201137b2024d445165a26ae9f9b5b41def569f5 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Thu, 11 Jul 2019 17:05:25 -0400 Subject: [PATCH 05/11] Remove leftover files --- src/ScriptBuilder/CSharpCounterWriter.cs | 88 -------------------- src/ScriptBuilder/PowerShellCounterWriter.cs | 71 ---------------- 2 files changed, 159 deletions(-) delete mode 100644 src/ScriptBuilder/CSharpCounterWriter.cs delete mode 100644 src/ScriptBuilder/PowerShellCounterWriter.cs diff --git a/src/ScriptBuilder/CSharpCounterWriter.cs b/src/ScriptBuilder/CSharpCounterWriter.cs deleted file mode 100644 index bc84923..0000000 --- a/src/ScriptBuilder/CSharpCounterWriter.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System.Collections.Generic; - using System.IO; - using System.Text; - - static class CSharpCounterWriter - { - public static void WriteCode(string scriptPath, IEnumerable timers, IEnumerable meters, Dictionary legacyInstanceNameMap) - { - var outputPath = Path.Combine(scriptPath, "Counters.g.cs"); - using (var streamWriter = File.CreateText(outputPath)) - { - var stringBuilder = new StringBuilder(); - - var slaCounterDefinition = @"new CounterCreationData(""SLA violation countdown"", ""Seconds until the SLA for this endpoint is breached."", PerformanceCounterType.NumberOfItems32),"; - stringBuilder.AppendLine(slaCounterDefinition.PadLeft(slaCounterDefinition.Length + 8)); - - foreach (var timer in timers) - { - var timerDefinition = $@"new CounterCreationData(""{timer.Name}"", ""{timer.Description}"", PerformanceCounterType.NumberOfItems32),"; - stringBuilder.AppendLine(timerDefinition.PadLeft(timerDefinition.Length + 8)); - } - - foreach (var meter in meters) - { - string instanceName; - legacyInstanceNameMap.TryGetValue(meter.Name, out instanceName); - - var meterDefinition = $@"new CounterCreationData(""{instanceName ?? meter.Name}"", ""{meter.Description}"", PerformanceCounterType.RateOfCountsPerSecond32),"; - stringBuilder.AppendLine(meterDefinition.PadLeft(meterDefinition.Length + 8)); - } - - streamWriter.Write(Template, stringBuilder); - } - } - - const string Template = @"using System; -using System.Diagnostics; -using System.Security; -using System.Runtime.CompilerServices; - -[CompilerGenerated] -public static class CounterCreator -{{ - public static void Create() - {{ - var counterCreationCollection = new CounterCreationDataCollection(Counters); - try - {{ - var categoryName = ""NServiceBus""; - - if (PerformanceCounterCategory.Exists(categoryName)) - {{ - foreach (CounterCreationData counter in counterCreationCollection) - {{ - if (!PerformanceCounterCategory.CounterExists(counter.CounterName, categoryName)) - {{ - PerformanceCounterCategory.Delete(categoryName); - break; - }} - }} - }} - - if (PerformanceCounterCategory.Exists(categoryName) == false) - {{ - PerformanceCounterCategory.Create( - categoryName: categoryName, - categoryHelp: ""NServiceBus statistics"", - categoryType: PerformanceCounterCategoryType.MultiInstance, - counterData: counterCreationCollection); - }} - - PerformanceCounter.CloseSharedResources(); - }} - catch (Exception ex) when (ex is SecurityException || ex is UnauthorizedAccessException) - {{ - throw new Exception(""Execution requires elevated permissions"", ex); - }} - }} - - static CounterCreationData[] Counters = new CounterCreationData[] - {{ -{0} - }}; -}}"; - } -} \ No newline at end of file diff --git a/src/ScriptBuilder/PowerShellCounterWriter.cs b/src/ScriptBuilder/PowerShellCounterWriter.cs deleted file mode 100644 index 7821f1a..0000000 --- a/src/ScriptBuilder/PowerShellCounterWriter.cs +++ /dev/null @@ -1,71 +0,0 @@ -namespace NServiceBus.Metrics.PerformanceCounters -{ - using System.Collections.Generic; - using System.IO; - using System.Text; - - static class PowerShellCounterWriter - { - public static void WriteScript(string scriptPath, IEnumerable timers, IEnumerable meters, Dictionary legacyInstanceNameMap) - { - var outputPath = Path.Combine(scriptPath, "CreateNSBPerfCounters.ps1"); - using (var streamWriter = File.CreateText(outputPath)) - { - var stringBuilder = new StringBuilder(); - - var slaCounterDefinition = @"New-Object System.Diagnostics.CounterCreationData ""SLA violation countdown"", ""Seconds until the SLA for this endpoint is breached."", NumberOfItems32"; - stringBuilder.AppendLine(slaCounterDefinition.PadLeft(slaCounterDefinition.Length + 8)); - - foreach (var timer in timers) - { - var timerDefinition = $@"New-Object System.Diagnostics.CounterCreationData ""{timer.Name}"", ""{timer.Description}"", NumberOfItems32"; - stringBuilder.AppendLine(timerDefinition.PadLeft(timerDefinition.Length + 8)); - } - - foreach (var meter in meters) - { - string instanceName; - legacyInstanceNameMap.TryGetValue(meter.Name, out instanceName); - - var meterDefinition = $@"New-Object System.Diagnostics.CounterCreationData ""{instanceName ?? meter.Name}"", ""{meter.Description}"", RateOfCountsPerSecond32"; - stringBuilder.AppendLine(meterDefinition.PadLeft(meterDefinition.Length + 8)); - } - - streamWriter.Write(Template, stringBuilder); - } - } - - const string Template = @"#requires -RunAsAdministrator -Function InstallNSBPerfCounters {{ - - $category = @{{Name=""NServiceBus""; Description=""NServiceBus statistics""}} - $counters = New-Object System.Diagnostics.CounterCreationDataCollection - $counters.AddRange(@( -{0} - )) - - if ([System.Diagnostics.PerformanceCounterCategory]::Exists($category.Name)) {{ - foreach($counter in $counters){{ - $exists = [System.Diagnostics.PerformanceCounterCategory]::CounterExists($counter.CounterName, $category.Name) - if (!$exists){{ - Write-Host ""One or more counters are missing.The performance counter category will be recreated"" - [System.Diagnostics.PerformanceCounterCategory]::Delete($category.Name) - - break - }} - }} - }} - - if (![System.Diagnostics.PerformanceCounterCategory]::Exists($category.Name)) {{ - Write-Host ""Creating the performance counter category"" - [void] [System.Diagnostics.PerformanceCounterCategory]::Create($category.Name, $category.Description, [System.Diagnostics.PerformanceCounterCategoryType]::MultiInstance, $counters) - }} - else {{ - Write-Host ""No performance counters have to be created"" - }} - - [System.Diagnostics.PerformanceCounter]::CloseSharedResources() -}} -InstallNSBPerfCounters"; - } -} \ No newline at end of file From 4dc64337e6a7d3567310328c8b4327d329096369 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Thu, 11 Jul 2019 17:08:12 -0400 Subject: [PATCH 06/11] Trailing whitespace --- .../Scripts/CreateNSBPerfCounters.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NServiceBus.Metrics.PerformanceCounters/Scripts/CreateNSBPerfCounters.ps1 b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/CreateNSBPerfCounters.ps1 index 53d1d67..9c0c67b 100755 --- a/src/NServiceBus.Metrics.PerformanceCounters/Scripts/CreateNSBPerfCounters.ps1 +++ b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/CreateNSBPerfCounters.ps1 @@ -1,7 +1,7 @@ #requires -RunAsAdministrator Function InstallNSBPerfCounters { - + $category = @{Name="NServiceBus"; Description="NServiceBus statistics"} $counters = New-Object System.Diagnostics.CounterCreationDataCollection $counters.AddRange(@( From eb4b0fae4a5d9be1d59e6ef0fa71588477cdca57 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Thu, 11 Jul 2019 17:12:16 -0400 Subject: [PATCH 07/11] Simplify props file --- .../Scripts/NServiceBus.Metrics.PerformanceCounters.props | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props index 41ecaa4..4e09e3a 100755 --- a/src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props +++ b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props @@ -1,8 +1,4 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - + PreserveNewest From d9bc7882528eec5f78c51e9afb3e284e37d0ffb5 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Thu, 11 Jul 2019 17:21:48 -0400 Subject: [PATCH 08/11] Change script project settings to work with multi-targeting --- .../NServiceBus.Metrics.PerformanceCounters.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj b/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj index 4a3bd40..9eef184 100755 --- a/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj +++ b/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj @@ -11,8 +11,8 @@ - - + + From 936d6308d2fd18528f4abfc950f877d0602b0ec3 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Thu, 11 Jul 2019 17:23:03 -0400 Subject: [PATCH 09/11] Stop setting OutputPath --- .../NServiceBus.Metrics.PerformanceCounters.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj b/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj index 9eef184..0a43fb8 100755 --- a/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj +++ b/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj @@ -4,7 +4,6 @@ net452 true $(SolutionDir)NServiceBus.snk - ..\..\binaries\ Enables access to performance counters $(NoWarn);NU5110;NU5111 From 92b60d4a755ce9dc8b6e61b99148728593719474 Mon Sep 17 00:00:00 2001 From: David Boike Date: Fri, 12 Jul 2019 08:20:49 -0500 Subject: [PATCH 10/11] Fix permissions --- GitVersion.yml | 0 .../NServiceBus.Metrics.PerformanceCounters.csproj | 0 .../PerformanceCounterSettingsAttribute.cs | 0 .../Scripts/CreateNSBPerfCounters.ps1 | 0 .../Scripts/NServiceBus.Metrics.PerformanceCounters.props | 0 .../NServiceBus.Metrics.PerformanceCounters.MsBuild.nuspec | 0 .../NServiceBus.Metrics.PerformanceCounters.MsBuild.targets | 0 src/ScriptBuilderTask/ScriptBuilderTask.csproj | 0 8 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 GitVersion.yml mode change 100755 => 100644 src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj mode change 100755 => 100644 src/NServiceBus.Metrics.PerformanceCounters/PerformanceCounterSettingsAttribute.cs mode change 100755 => 100644 src/NServiceBus.Metrics.PerformanceCounters/Scripts/CreateNSBPerfCounters.ps1 mode change 100755 => 100644 src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props mode change 100755 => 100644 src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.nuspec mode change 100755 => 100644 src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets mode change 100755 => 100644 src/ScriptBuilderTask/ScriptBuilderTask.csproj diff --git a/GitVersion.yml b/GitVersion.yml old mode 100755 new mode 100644 diff --git a/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj b/src/NServiceBus.Metrics.PerformanceCounters/NServiceBus.Metrics.PerformanceCounters.csproj old mode 100755 new mode 100644 diff --git a/src/NServiceBus.Metrics.PerformanceCounters/PerformanceCounterSettingsAttribute.cs b/src/NServiceBus.Metrics.PerformanceCounters/PerformanceCounterSettingsAttribute.cs old mode 100755 new mode 100644 diff --git a/src/NServiceBus.Metrics.PerformanceCounters/Scripts/CreateNSBPerfCounters.ps1 b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/CreateNSBPerfCounters.ps1 old mode 100755 new mode 100644 diff --git a/src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props b/src/NServiceBus.Metrics.PerformanceCounters/Scripts/NServiceBus.Metrics.PerformanceCounters.props old mode 100755 new mode 100644 diff --git a/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.nuspec b/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.nuspec old mode 100755 new mode 100644 diff --git a/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets b/src/ScriptBuilderTask/NServiceBus.Metrics.PerformanceCounters.MsBuild.targets old mode 100755 new mode 100644 diff --git a/src/ScriptBuilderTask/ScriptBuilderTask.csproj b/src/ScriptBuilderTask/ScriptBuilderTask.csproj old mode 100755 new mode 100644 From 717f45bd19921017391813356d548b0e2892a7c0 Mon Sep 17 00:00:00 2001 From: David Boike Date: Fri, 12 Jul 2019 08:31:11 -0500 Subject: [PATCH 11/11] Approval test --- .../ApprovalFiles/APIApprovals.Approve.approved.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/NServiceBus.Metrics.PerformanceCounters.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt b/src/NServiceBus.Metrics.PerformanceCounters.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt index c251ccb..753518e 100644 --- a/src/NServiceBus.Metrics.PerformanceCounters.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt +++ b/src/NServiceBus.Metrics.PerformanceCounters.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt @@ -3,6 +3,9 @@ namespace NServiceBus.Metrics.PerformanceCounters { [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.All)] + [System.ObsoleteAttribute("The NServiceBus.Metrics.PerformanceCounters.MsBuild package is deprecated. There " + + "is no longer any need to configure its output. To promote the script outside the" + + " build directory, use a post-build event. Will be removed in version 5.0.0.", true)] public sealed class PerformanceCounterSettingsAttribute : System.Attribute { public PerformanceCounterSettingsAttribute() { }