From 67879ce2689c79d177f839639ad0c0df24050b33 Mon Sep 17 00:00:00 2001 From: Bart Robertson Date: Sat, 3 Jun 2023 12:29:02 -0500 Subject: [PATCH] update to dotnet 7 (#37) * updated to dotnet 7 * removed correlation vector (deprecated) * updated build * updated nuget packages * updated change log * updated ci-cd to dotnet 7 --- .github/CHANGELOG.md | 5 +++++ .github/workflows/codeql.yaml | 4 ++-- .github/workflows/dockerCI.yaml | 6 ++--- Dockerfile | 6 ++--- build | 16 ++++++++++++++ push | 13 +++++++++++ src/app/WebValidation/Main.cs | 22 +++++-------------- src/app/WebValidation/Model/PerfLog.cs | 7 +----- src/app/WebValidation/ReadValidateJson.cs | 4 ++-- .../Validators/ResponseValidator.cs | 4 ++-- src/app/core/CommandLine.cs | 20 ++++++++--------- src/app/core/startup.cs | 5 +---- src/app/webvalidate.csproj | 11 +++++----- src/tests/tests.csproj | 10 ++++----- 14 files changed, 74 insertions(+), 59 deletions(-) create mode 100755 build create mode 100755 push diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 17ae989..9ed2c2c 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## v7.0.0 - May 2023 + +- updated to dotnet 7 +- removed correlation vector (deprecated) + ## v2.5.0 - June 2022 - updated condition to run webhost without `--prometheus` diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml index 55e5ee7..fc6f246 100644 --- a/.github/workflows/codeql.yaml +++ b/.github/workflows/codeql.yaml @@ -2,7 +2,7 @@ name: CodeQL on: workflow_dispatch: - + push: branches: - main @@ -58,7 +58,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: '6.0' + dotnet-version: '7.0' include-prerelease: True # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). diff --git a/.github/workflows/dockerCI.yaml b/.github/workflows/dockerCI.yaml index f62b79b..5ff66ca 100644 --- a/.github/workflows/dockerCI.yaml +++ b/.github/workflows/dockerCI.yaml @@ -2,7 +2,7 @@ name: DockerBuild on: workflow_dispatch: - + push: branches: - main @@ -27,8 +27,8 @@ jobs: - name: Docker Pull run: | - docker pull mcr.microsoft.com/dotnet/sdk:6.0 - docker pull mcr.microsoft.com/dotnet/aspnet:6.0-alpine + docker pull mcr.microsoft.com/dotnet/sdk:7.0 + docker pull mcr.microsoft.com/dotnet/aspnet:7.0-alpine - name: Build Container run: | diff --git a/Dockerfile b/Dockerfile index 00f0be2..d63f056 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ ### build the app -FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build # Copy the source COPY src /src @@ -12,12 +12,12 @@ RUN dotnet test WORKDIR /src/app RUN dotnet publish -c Release -o /app - + ########################################################### ### build the runtime container -FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine AS runtime +FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS runtime ### create a user ### dotnet needs a home directory diff --git a/build b/build new file mode 100755 index 0000000..bd513a6 --- /dev/null +++ b/build @@ -0,0 +1,16 @@ +#!/bin/bash + +dotnet build src/app -o "$HOME/bin" + +docker pull mcr.microsoft.com/dotnet/sdk:7.0 +docker pull mcr.microsoft.com/dotnet/aspnet:7.0 + +docker build . -t ghcr.io/cse-labs/webvalidate:beta +#docker build . -t ghcr.io/cse-labs/webvalidate:latest +#docker build . -t ghcr.io/cse-labs/webvalidate:7.0.0 +#docker build . -t ghcr.io/cse-labs/webvalidate:7.0 + +docker build . -t retaildevcrew/webvalidate:beta +#docker build . -t retaildevcrew/webvalidate:latest +#docker build . -t retaildevcrew/webvalidate:7.0.0 +#docker build . -t retaildevcrew/webvalidate:7.0 diff --git a/push b/push new file mode 100755 index 0000000..5f9216c --- /dev/null +++ b/push @@ -0,0 +1,13 @@ +#!/bin/bash + +./build + +docker push ghcr.io/cse-labs/webvalidate:beta +#docker push ghcr.io/cse-labs/webvalidate:latest +#docker push ghcr.io/cse-labs/webvalidate:7.0.0 +#docker push ghcr.io/cse-labs/webvalidate:7.0 + +docker push retaildevcrew/webvalidate:beta +#docker push retaildevcrew/webvalidate:latest +#docker push retaildevcrew/webvalidate:7.0.0 +#docker push retaildevcrew/webvalidate:7.0 diff --git a/src/app/WebValidation/Main.cs b/src/app/WebValidation/Main.cs index 86c328f..402aaa6 100644 --- a/src/app/WebValidation/Main.cs +++ b/src/app/WebValidation/Main.cs @@ -13,7 +13,6 @@ using System.Threading.Tasks; using CSE.WebValidate.Model; using CSE.WebValidate.Validators; -using Microsoft.CorrelationVector; using Prometheus; namespace CSE.WebValidate @@ -429,10 +428,6 @@ public async Task ExecuteRequest(HttpClient client, string server, Requ } } - // create correlation vector and add to headers - CorrelationVector cv = new (CorrelationVectorVersion.V2); - req.Headers.Add(CorrelationVector.HeaderName, cv.Value); - // add the body to the http request if (!string.IsNullOrWhiteSpace(request.Body)) { @@ -458,7 +453,7 @@ public async Task ExecuteRequest(HttpClient client, string server, Requ valid = ResponseValidator.Validate(request, resp, body, duration); // check the performance - perfLog = CreatePerfLog(server, request, valid, path, duration, (long)resp.Content.Headers.ContentLength, (int)resp.StatusCode, cv.Value); + perfLog = CreatePerfLog(server, request, valid, path, duration, (long)resp.Content.Headers.ContentLength, (int)resp.StatusCode); if (config.Summary == SummaryFormat.Xml) { @@ -472,7 +467,7 @@ public async Task ExecuteRequest(HttpClient client, string server, Requ double duration = Math.Round(DateTime.UtcNow.Subtract(dt).TotalMilliseconds, 0); valid = new ValidationResult { Failed = true }; valid.ValidationErrors.Add($"Exception: {ex.Message}"); - perfLog = CreatePerfLog(server, request, valid, path, duration, 0, 500, cv.Value); + perfLog = CreatePerfLog(server, request, valid, path, duration, 0, 500); if (config.Summary == SummaryFormat.Xml) { @@ -525,9 +520,8 @@ public async Task ExecuteRequest(HttpClient client, string server, Requ /// duration /// content length /// status code - /// Correlation Vector /// PerfLog - public PerfLog CreatePerfLog(string server, Request request, ValidationResult validationResult, string path, double duration, long contentLength, int statusCode, string correlationVector = "") + public PerfLog CreatePerfLog(string server, Request request, ValidationResult validationResult, string path, double duration, long contentLength, int statusCode) { if (validationResult == null) { @@ -548,17 +542,13 @@ public PerfLog CreatePerfLog(string server, Request request, ValidationResult va ContentLength = contentLength, Failed = validationResult.Failed, Verb = request.Verb, - CorrelationVector = correlationVector, Region = config.Region, Zone = config.Zone, }; // determine the Performance Level based on category - if (targets.ContainsKey(log.Category)) + if (targets.TryGetValue(log.Category, out PerfTarget target)) { - // lookup the target - PerfTarget target = targets[log.Category]; - if (target != null && !string.IsNullOrWhiteSpace(target.Category) && target.Quartiles != null && @@ -788,8 +778,8 @@ private void LogToConsole(Request request, ValidationResult valid, PerfLog perfL throw new ArgumentNullException(nameof(perfLog)); } - // always log on error - if (config.Verbose || perfLog.StatusCode >= 400 || perfLog.Failed || perfLog.ErrorCount > 0) + // always log on error and --verbose + if (config.Verbose || perfLog.Failed || perfLog.ErrorCount > 0 || !perfLog.Validated) { switch (config.LogFormat) { diff --git a/src/app/WebValidation/Model/PerfLog.cs b/src/app/WebValidation/Model/PerfLog.cs index f381093..f8a96ed 100644 --- a/src/app/WebValidation/Model/PerfLog.cs +++ b/src/app/WebValidation/Model/PerfLog.cs @@ -68,11 +68,6 @@ public PerfLog() /// public bool Validated { get; set; } = true; - /// - /// Gets or sets a the correlation vector for distributed tracing - /// - public string CorrelationVector { get; set; } - /// /// Gets the error count /// @@ -157,7 +152,7 @@ public string ToTsv(bool verboseErrors) Zone = string.IsNullOrWhiteSpace(Zone) ? "-" : Zone; // log tab delimited - string log = $"{Date:o}\t{TestName}\t{Server}\t{StatusCode}\t{ErrorCount}\t{Duration}\t{ContentLength}\t{Region}\t{Zone}\t{CorrelationVector}\t{Tag}\t{quartile}\t{Category}\t{Verb}\t{Path}"; + string log = $"{Date:o}\t{TestName}\t{Server}\t{StatusCode}\t{ErrorCount}\t{Duration}\t{ContentLength}\t{Region}\t{Zone}\t{Tag}\t{quartile}\t{Category}\t{Verb}\t{Path}"; // log error details if (verboseErrors && ErrorCount > 0) diff --git a/src/app/WebValidation/ReadValidateJson.cs b/src/app/WebValidation/ReadValidateJson.cs index cedd093..97db107 100644 --- a/src/app/WebValidation/ReadValidateJson.cs +++ b/src/app/WebValidation/ReadValidateJson.cs @@ -219,9 +219,9 @@ private List LoadJson(string json) // Add the default perf targets if exists if (r.PerfTarget != null && r.PerfTarget.Quartiles == null) { - if (targets.ContainsKey(r.PerfTarget.Category)) + if (targets.TryGetValue(r.PerfTarget.Category, out PerfTarget target)) { - r.PerfTarget.Quartiles = targets[r.PerfTarget.Category].Quartiles; + r.PerfTarget.Quartiles = target.Quartiles; } } diff --git a/src/app/WebValidation/Validators/ResponseValidator.cs b/src/app/WebValidation/Validators/ResponseValidator.cs index a061dc1..fe586d4 100644 --- a/src/app/WebValidation/Validators/ResponseValidator.cs +++ b/src/app/WebValidation/Validators/ResponseValidator.cs @@ -153,7 +153,7 @@ public static ValidationResult Validate(List properties, string body) foreach (JsonItem property in properties) { - if (!string.IsNullOrEmpty(property.Field) && dict.ContainsKey(property.Field)) + if (!string.IsNullOrEmpty(property.Field) && dict.TryGetValue(property.Field, out object value)) { if (property.Validation != null) { @@ -167,7 +167,7 @@ public static ValidationResult Validate(List properties, string body) } } - object element = dict[property.Field]; + object element = value; // compare the values as strings if (property.Value != null && element.ToString() != property.Value.ToString()) diff --git a/src/app/core/CommandLine.cs b/src/app/core/CommandLine.cs index 1ac05e9..e6d00b7 100644 --- a/src/app/core/CommandLine.cs +++ b/src/app/core/CommandLine.cs @@ -63,7 +63,7 @@ public static RootCommand BuildRootCommand() // check option for deprecation private static string CheckForDeprecation(CommandResult result, string option) { - if (!(result.Children.FirstOrDefault(c => c.Symbol.Name == option) as OptionResult).IsImplicit) + if (result.Children.FirstOrDefault(c => c.Symbol.Name == option) is OptionResult optRes && !optRes.IsImplicit) { return $"--{option} will be deprecated in the 2.6 release\n\n"; } @@ -78,16 +78,16 @@ private static void DisplayDeprecationWarnings(CommandResult result) { messageFlag = true; - // uncomment to add deprecated messages - // string msg = CheckForDeprecation(result, "deprecatedCommand1"); - // msg += CheckForDeprecation(result, "deprecatedCommand2"); + // add deprecated messages + string msg = CheckForDeprecation(result, "deprecatedCommand1"); + msg += CheckForDeprecation(result, "deprecatedCommand2"); - // if (!string.IsNullOrWhiteSpace(msg)) - // { - // Console.ForegroundColor = ConsoleColor.DarkYellow; - // Console.WriteLine(msg); - // Console.ResetColor(); - // } + if (!string.IsNullOrWhiteSpace(msg)) + { + Console.ForegroundColor = ConsoleColor.DarkYellow; + Console.WriteLine(msg); + Console.ResetColor(); + } } } diff --git a/src/app/core/startup.cs b/src/app/core/startup.cs index c73bbbb..cdd9513 100644 --- a/src/app/core/startup.cs +++ b/src/app/core/startup.cs @@ -49,10 +49,7 @@ public static void Configure(IApplicationBuilder app, IHostApplicationLifetime l // signal run loop life.ApplicationStopping.Register(() => { - if (App.TokenSource != null) - { - App.TokenSource.Cancel(false); - } + App.TokenSource?.Cancel(false); }); // version handler diff --git a/src/app/webvalidate.csproj b/src/app/webvalidate.csproj index 5470b77..c62f037 100644 --- a/src/app/webvalidate.csproj +++ b/src/app/webvalidate.csproj @@ -1,9 +1,9 @@  - net6.0 + net7.0 CSE.WebValidate - 2.6.0 + 7.0.0 $([System.DateTime]::UtcNow.ToString(`MMdd-HHmm`)) Microsoft Corporation Copyright (c) Microsoft Corporation. All rights reserved. @@ -23,13 +23,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/tests/tests.csproj b/src/tests/tests.csproj index e7e229e..1daa80a 100644 --- a/src/tests/tests.csproj +++ b/src/tests/tests.csproj @@ -1,27 +1,27 @@ - net6.0 + net7.0 CSE.WebValidate.Tests.Unit false - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + runtime; build; native; contentfiles; analyzers; buildtransitive all