Skip to content

Commit

Permalink
update to dotnet 7 (#37)
Browse files Browse the repository at this point in the history
* updated to dotnet 7
* removed correlation vector (deprecated)
* updated build
* updated nuget packages
* updated change log
* updated ci-cd to dotnet 7
  • Loading branch information
bartr authored Jun 3, 2023
1 parent 7ee68a8 commit 67879ce
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 59 deletions.
5 changes: 5 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CodeQL

on:
workflow_dispatch:

push:
branches:
- main
Expand Down Expand Up @@ -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).
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/dockerCI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: DockerBuild

on:
workflow_dispatch:

push:
branches:
- main
Expand All @@ -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: |
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions push
Original file line number Diff line number Diff line change
@@ -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
22 changes: 6 additions & 16 deletions src/app/WebValidation/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using System.Threading.Tasks;
using CSE.WebValidate.Model;
using CSE.WebValidate.Validators;
using Microsoft.CorrelationVector;
using Prometheus;

namespace CSE.WebValidate
Expand Down Expand Up @@ -429,10 +428,6 @@ public async Task<PerfLog> 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))
{
Expand All @@ -458,7 +453,7 @@ public async Task<PerfLog> 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)
{
Expand All @@ -472,7 +467,7 @@ public async Task<PerfLog> 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)
{
Expand Down Expand Up @@ -525,9 +520,8 @@ public async Task<PerfLog> ExecuteRequest(HttpClient client, string server, Requ
/// <param name="duration">duration</param>
/// <param name="contentLength">content length</param>
/// <param name="statusCode">status code</param>
/// <param name="correlationVector">Correlation Vector</param>
/// <returns>PerfLog</returns>
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)
{
Expand All @@ -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 &&
Expand Down Expand Up @@ -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)
{
Expand Down
7 changes: 1 addition & 6 deletions src/app/WebValidation/Model/PerfLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ public PerfLog()
/// </summary>
public bool Validated { get; set; } = true;

/// <summary>
/// Gets or sets a the correlation vector for distributed tracing
/// </summary>
public string CorrelationVector { get; set; }

/// <summary>
/// Gets the error count
/// </summary>
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/app/WebValidation/ReadValidateJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ private List<Request> 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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/WebValidation/Validators/ResponseValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static ValidationResult Validate(List<JsonItem> 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)
{
Expand All @@ -167,7 +167,7 @@ public static ValidationResult Validate(List<JsonItem> 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())
Expand Down
20 changes: 10 additions & 10 deletions src/app/core/CommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand All @@ -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();
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/app/core/startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions src/app/webvalidate.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>CSE.WebValidate</RootNamespace>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionPrefix>7.0.0</VersionPrefix>
<VersionSuffix>$([System.DateTime]::UtcNow.ToString(`MMdd-HHmm`))</VersionSuffix>
<Company>Microsoft Corporation</Company>
<Copyright>Copyright (c) Microsoft Corporation. All rights reserved.</Copyright>
Expand All @@ -23,13 +23,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CorrelationVector" Version="1.0.42" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="prometheus-net.AspNetCore" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="prometheus-net.AspNetCore" Version="8.0.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
10 changes: 5 additions & 5 deletions src/tests/tests.csproj
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>CSE.WebValidate.Tests.Unit</RootNamespace>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit 67879ce

Please sign in to comment.