Skip to content

Commit f5e2f17

Browse files
authored
Refactor Logs (#539)
* HTTP error logging - Code cleanup with CodeMaid * gh-386 Refactor Workflow manager logs * Adjust time zone to UTC Signed-off-by: Victor Chang <vicchang@nvidia.com>
1 parent dcdf133 commit f5e2f17

File tree

110 files changed

+1062
-616
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1062
-616
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
env:
2222
BUILD_CONFIG: "Release"
2323
SOLUTION: "Monai.Deploy.WorkflowManager.sln"
24-
24+
2525
jobs:
2626
build-and-deploy:
2727
runs-on: ubuntu-latest
@@ -36,7 +36,7 @@ jobs:
3636
outputs:
3737
semVer: ${{ steps.gitversion.outputs.semVer }}
3838
majorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }}
39-
env:
39+
env:
4040
REGISTRY: ghcr.io
4141
permissions:
4242
packages: write
@@ -106,15 +106,15 @@ jobs:
106106

107107
- name: Trivy Vulnerability Scanner
108108
uses: aquasecurity/trivy-action@master
109-
if: ${{ contains(github.ref, 'refs/heads/main') || contains(github.head_ref, 'release/') }}
109+
if: ${{ contains(github.ref, 'refs/heads/main') || contains(github.head_ref, 'release/') }}
110110
with:
111111
image-ref: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
112112
format: 'sarif'
113113
output: 'trivy-results.sarif'
114114

115115
- name: Upload Trivy SARIF Report
116116
uses: github/codeql-action/upload-sarif@v2
117-
if: ${{ contains(github.ref, 'refs/heads/main') || contains(github.head_ref, 'release/') }}
117+
if: ${{ contains(github.ref, 'refs/heads/main') || contains(github.head_ref, 'release/') }}
118118
with:
119119
sarif_file: 'trivy-results.sarif'
120120

@@ -184,7 +184,7 @@ jobs:
184184
run: |
185185
mkdir ~\release
186186
Compress-Archive -Path docs\_site\* -DestinationPath ~\release\mwm-docs-${{ env.SEMVER }}.zip
187-
Get-ChildItem ~\release -Recurse
187+
Get-ChildItem ~\release -Recurse
188188
189189
- name: Upload docs
190190
uses: actions/upload-artifact@v3.1.1

src/Monai.Deploy.WorkflowManager.sln

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Monai.Deploy.WorkflowManage
8080
EndProject
8181
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Monai.Deploy.WorkflowManager.Shared", "Shared\Shared\Monai.Deploy.WorkflowManager.Shared.csproj", "{81E3F943-B992-4C81-AA09-A17C05081236}"
8282
EndProject
83-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Monai.Deploy.WorkflowManager.Shared.Tests", "..\tests\UnitTests\Monai.Deploy.WorkflowManager.Shared.Tests\Monai.Deploy.WorkflowManager.Shared.Tests.csproj", "{C853A9E3-C53D-4B1A-BFDA-228689A8C94C}"
83+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Monai.Deploy.WorkflowManager.Shared.Tests", "..\tests\UnitTests\Monai.Deploy.WorkflowManager.Shared.Tests\Monai.Deploy.WorkflowManager.Shared.Tests.csproj", "{C853A9E3-C53D-4B1A-BFDA-228689A8C94C}"
84+
EndProject
85+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Monai.Deploy.WorkflowManager.Common.Tests", "..\tests\UnitTests\Common.Tests\Monai.Deploy.WorkflowManager.Common.Tests.csproj", "{75A4AEDA-0386-4B2D-9DBA-BC9AE733660E}"
8486
EndProject
8587
Global
8688
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -228,6 +230,10 @@ Global
228230
{C853A9E3-C53D-4B1A-BFDA-228689A8C94C}.Debug|Any CPU.Build.0 = Debug|Any CPU
229231
{C853A9E3-C53D-4B1A-BFDA-228689A8C94C}.Release|Any CPU.ActiveCfg = Release|Any CPU
230232
{C853A9E3-C53D-4B1A-BFDA-228689A8C94C}.Release|Any CPU.Build.0 = Release|Any CPU
233+
{75A4AEDA-0386-4B2D-9DBA-BC9AE733660E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
234+
{75A4AEDA-0386-4B2D-9DBA-BC9AE733660E}.Debug|Any CPU.Build.0 = Debug|Any CPU
235+
{75A4AEDA-0386-4B2D-9DBA-BC9AE733660E}.Release|Any CPU.ActiveCfg = Release|Any CPU
236+
{75A4AEDA-0386-4B2D-9DBA-BC9AE733660E}.Release|Any CPU.Build.0 = Release|Any CPU
231237
EndGlobalSection
232238
GlobalSection(SolutionProperties) = preSolution
233239
HideSolutionNode = FALSE
@@ -269,6 +275,7 @@ Global
269275
{BF6569A1-1A5A-4358-9C02-1A6A5F0FBFD9} = {71DDEE7B-E213-4E39-A7F4-4646783A27F7}
270276
{81E3F943-B992-4C81-AA09-A17C05081236} = {37A19144-CEA5-47A2-9FFD-22C522E8B895}
271277
{C853A9E3-C53D-4B1A-BFDA-228689A8C94C} = {71DDEE7B-E213-4E39-A7F4-4646783A27F7}
278+
{75A4AEDA-0386-4B2D-9DBA-BC9AE733660E} = {71DDEE7B-E213-4E39-A7F4-4646783A27F7}
272279
EndGlobalSection
273280
GlobalSection(ExtensibilityGlobals) = postSolution
274281
SolutionGuid = {DC0D56C8-D8CB-45CE-B528-F3DCF86D63ED}

src/Shared/Shared/Monai.Deploy.WorkflowManager.Shared.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<EmbeddedResource Remove="Test\**" />
4242
<None Remove="Test\**" />
4343
</ItemGroup>
44-
44+
4545
<ItemGroup>
4646
<AdditionalFiles Include="..\..\.sonarlint\project-monai_monai-deploy-workflow-manager\CSharp\SonarLint.xml" Link="SonarLint.xml" />
4747
</ItemGroup>

src/TaskManager/API/Monai.Deploy.WorkflowManager.TaskManager.API.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--
1+
<!--
22
~ Copyright 2022 MONAI Consortium
33
~
44
~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,11 +32,12 @@
3232
<ItemGroup>
3333
<Compile Include="..\..\AssemblyInfo.cs" Link="AssemblyInfo.cs" />
3434
</ItemGroup>
35-
35+
3636
<ItemGroup>
3737
<AdditionalFiles Include="..\..\.sonarlint\project-monai_monai-deploy-workflow-manager\CSharp\SonarLint.xml" Link="SonarLint.xml" />
3838
</ItemGroup>
3939

40+
4041
<ItemGroup>
4142
<PackageReference Include="Monai.Deploy.Messaging" Version="0.1.8" />
4243
<PackageReference Include="MongoDB.Bson" Version="2.18.0" />

src/TaskManager/Database/Monai.Deploy.WorkflowManager.TaskManager.Database.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--
1+
<!--
22
~ Copyright 2022 MONAI Consortium
33
~
44
~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,12 +23,14 @@
2323
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
2424
</PropertyGroup>
2525

26+
2627
<ItemGroup>
27-
<AdditionalFiles Include="..\..\.sonarlint\project-monai_monai-deploy-workflow-manager\CSharp\SonarLint.xml" Link="SonarLint.xml" />
28+
<Compile Include="..\..\AssemblyInfo.cs" Link="AssemblyInfo.cs" />
2829
</ItemGroup>
2930

31+
3032
<ItemGroup>
31-
<Compile Include="..\..\AssemblyInfo.cs" Link="AssemblyInfo.cs" />
33+
<AdditionalFiles Include="..\..\.sonarlint\project-monai_monai-deploy-workflow-manager\CSharp\SonarLint.xml" Link="SonarLint.xml" />
3234
</ItemGroup>
3335

3436
<ItemGroup>

src/TaskManager/Plug-ins/Docker/IDockerClientFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class DockerClientFactory : IDockerClientFactory
2727
{
2828
public IDockerClient CreateClient(Uri dockerEndpoint)
2929
{
30-
return new DockerClientConfiguration(dockerEndpoint).CreateClient();
30+
return new DockerClientConfiguration(dockerEndpoint).CreateClient();
3131
}
3232
}
3333
}

src/TaskManager/TaskManager/Monai.Deploy.WorkflowManager.TaskManager.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<AdditionalFiles Include="..\..\.sonarlint\project-monai_monai-deploy-workflow-manager\CSharp\SonarLint.xml" Link="SonarLint.xml" />
5656
</ItemGroup>
5757

58+
5859
<ItemGroup>
5960
<PackageReference Include="AspNetCore.HealthChecks.MongoDb" Version="6.0.2" />
6061
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.10" />

src/TaskManager/TaskManager/appsettings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,4 @@
9595
"LogHttpResponseBody": true
9696
},
9797
"AllowedHosts": "*",
98-
9998
}
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22

3-
<!--
3+
<!--
44
Copyright 2022 MONAI Consortium
55
66
Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +13,7 @@ Unless required by applicable law or agreed to in writing, software
1313
distributed under the License is distributed on an "AS IS" BASIS,
1414
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
See the License for the specific language governing permissions and
16-
limitations under the License.
16+
limitations under the License.
1717
-->
1818

1919
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
@@ -24,8 +24,8 @@ limitations under the License.
2424

2525
<!-- enable asp.net core layout renderers -->
2626
<extensions>
27-
<add assembly="NLog.Web.AspNetCore"/>
28-
<add assembly="NLog.Extensions.Logging"/>
27+
<add assembly="NLog.Web.AspNetCore" />
28+
<add assembly="NLog.Extensions.Logging" />
2929
</extensions>
3030

3131
<variable name="logDir" value="${basedir}/logs/" />
@@ -34,10 +34,10 @@ limitations under the License.
3434
<time type="AccurateUTC" />
3535

3636
<targets async="true">
37-
<target xsi:type="File" name="allfile" fileName="${logDir}/MWM-${shortdate}.log" >
37+
<target xsi:type="File" name="allfile" fileName="${logDir}/MWM-${shortdate}.log">
3838
<layout xsi:type="JsonLayout" includeEventProperties="true" includeScopeProperties="true">
3939
<attribute name="timestamp" layout="${date:format=o}" />
40-
<attribute name="level" layout="${level:upperCase=true}"/>
40+
<attribute name="level" layout="${level:upperCase=true}" />
4141
<attribute name="logger" layout="${logger}" />
4242
<attribute name="message" layout="${message:raw=true}" />
4343
<attribute name="properties" layout="${message:raw=true}" />
@@ -48,17 +48,17 @@ limitations under the License.
4848
<target xsi:type="ColoredConsole" name="lifetimeConsole" layout="${longdate}|${event-properties:item=EventId:whenEmpty=0}|${uppercase:${level}}|${logger}|${scopenested}|${message} ${exception:format=tostring}" />
4949

5050
<target name="logstash" xsi:type="Network" address="${environment:LOGSTASH_URL}" newLine="true">
51-
<layout xsi:type="JsonLayout" includeAllProperties="true" IncludeEventProperties="true" IncludeScopeProperties="true" >
51+
<layout xsi:type="JsonLayout" includeAllProperties="true" IncludeEventProperties="true" IncludeScopeProperties="true">
5252
<attribute name="Tag" layout="${environment:ENVIRONMENT_NAME}" />
5353
<attribute name="ServiceName" layout="${servicename}" />
5454
<attribute name="ServiceVersion" layout="${serviceversion}" />
5555
<attribute name="MachineName" layout="${machinename}" />
56-
<attribute name="CorrelationId" layout="${mdlc:item=correlationId}"/>
57-
<attribute name="LoggerName" layout="${logger}"/>
58-
<attribute name="Level" layout="${level:upperCase=true}"/>
59-
<attribute name="Message" layout="${message}"/>
60-
<attribute name="Exception" layout="${onexception:${literal:text=|}"/>
61-
<attribute name="Exception2" layout="${exception:format=tostring}"/>
56+
<attribute name="CorrelationId" layout="${mdlc:item=correlationId}" />
57+
<attribute name="LoggerName" layout="${logger}" />
58+
<attribute name="Level" layout="${level:upperCase=true}" />
59+
<attribute name="Message" layout="${message}" />
60+
<attribute name="Exception" layout="${onexception:${literal:text=|}" />
61+
<attribute name="Exception2" layout="${exception:format=tostring}" />
6262
</layout>
6363
</target>
6464
</targets>
@@ -67,13 +67,12 @@ limitations under the License.
6767
<rules>
6868
<!--All logs, including from Microsoft-->
6969
<logger name="*" minlevel="Trace" writeTo="allfile" />
70-
<logger name="*" minlevel="Trace" writeTo="logstash" >
70+
<logger name="*" minlevel="Trace" writeTo="logstash">
7171
<filters FilterDefaultAction="Log">
7272
<when condition="length('${environment:LOGSTASH_URL}') &lt; 10" action="Ignore" />
7373
</filters>
7474
</logger>
7575

76-
7776
<!--Output hosting lifetime messages to console target for faster startup detection -->
7877
<logger name="Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware" minlevel="Info" writeTo="lifetimeConsole" final="true" />
7978
<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole" final="true" />
@@ -82,6 +81,5 @@ limitations under the License.
8281
<!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) -->
8382
<logger name="Microsoft.*" maxlevel="Info" final="true" />
8483
<logger name="System.Net.Http.*" maxlevel="Info" final="true" />
85-
8684
</rules>
8785
</nlog>

src/WorkflowManager/Authentication/Extensions/AuthKeys.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static class AuthKeys
2525

2626
// Configuration Keys
2727
public const string ServerRealm = "ServerRealm";
28+
2829
public const string ServerRealmKey = "ServerRealmKey";
2930
public const string Claims = "Claims";
3031
public const string OpenId = "OpenId";

src/WorkflowManager/Authentication/Extensions/ConfigurationExtension.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
using Microsoft.Extensions.Configuration;
1817
using Ardalis.GuardClauses;
18+
using Microsoft.Extensions.Configuration;
1919
using Microsoft.Extensions.Logging;
20+
using Monai.Deploy.WorkflowManager.Logging;
2021

2122
namespace Monai.Deploy.WorkflowManager.Authentication.Extensions
2223
{
@@ -32,7 +33,7 @@ public static bool BypassAuth(this IConfiguration configuration, ILogger logger)
3233

3334
if (authenticationSettings[AuthKeys.OpenId] is null)
3435
{
35-
logger.LogInformation("Bypass Authentication");
36+
logger.BypassAuthentication();
3637
return true;
3738
}
3839

@@ -42,7 +43,7 @@ public static bool BypassAuth(this IConfiguration configuration, ILogger logger)
4243
/// <summary>
4344
/// Gets configuration values from the IConfiguration provider.
4445
/// under "WorkflowManagerAuthentication" key you are able to
45-
/// have any label of configuration for example could have
46+
/// have any label of configuration for example could have
4647
/// </summary>
4748
/// <param name="configuration"></param>
4849
/// <param name="serverRealm"></param>

src/WorkflowManager/Authentication/Extensions/MonaiAuthenticationExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17+
using System.Text;
18+
using Microsoft.AspNetCore.Authentication;
19+
using Microsoft.AspNetCore.Authentication.JwtBearer;
20+
using Microsoft.AspNetCore.Authorization;
1721
using Microsoft.Extensions.Configuration;
1822
using Microsoft.Extensions.DependencyInjection;
23+
using Microsoft.Extensions.Logging;
1924
using Microsoft.IdentityModel.Tokens;
20-
using Microsoft.AspNetCore.Authentication.JwtBearer;
21-
using Monai.Deploy.WorkflowManager.Common.Extensions;
22-
using System.Text;
23-
using Microsoft.AspNetCore.Authorization;
24-
using Microsoft.AspNetCore.Authentication;
2525
using Monai.Deploy.WorkflowManager.Authentication.Middleware;
26-
using Microsoft.Extensions.Logging;
26+
using Monai.Deploy.WorkflowManager.Common.Extensions;
2727

2828
namespace Monai.Deploy.WorkflowManager.Authentication.Extensions
2929
{

src/WorkflowManager/Authentication/Middleware/BypassAuthenticationHandler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
using Microsoft.AspNetCore.Authentication;
18-
using Microsoft.Extensions.Options;
1917
using System.Security.Claims;
2018
using System.Text.Encodings.Web;
19+
using Microsoft.AspNetCore.Authentication;
2120
using Microsoft.Extensions.Logging;
21+
using Microsoft.Extensions.Options;
22+
using Monai.Deploy.WorkflowManager.Logging;
2223

2324
namespace Monai.Deploy.WorkflowManager.Authentication.Middleware
2425
{
@@ -36,7 +37,7 @@ public BypassAuthenticationHandler(
3637
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
3738
{
3839
var principal = new ClaimsPrincipal(new ClaimsIdentity(Array.Empty<Claim>(), Scheme.Name));
39-
Logger.LogInformation("Bypassing request");
40+
Logger.BypassAuthentication();
4041
return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(principal, Scheme.Name)));
4142
}
4243
}

src/WorkflowManager/Authentication/Middleware/EndpointAuthorizationMiddleware.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
using Microsoft.Extensions.Configuration;
18-
using Microsoft.AspNetCore.Routing;
1917
using System.Net;
2018
using Microsoft.AspNetCore.Http;
21-
using Monai.Deploy.WorkflowManager.Authentication.Extensions;
19+
using Microsoft.AspNetCore.Routing;
20+
using Microsoft.Extensions.Configuration;
2221
using Microsoft.Extensions.Logging;
22+
using Monai.Deploy.WorkflowManager.Authentication.Extensions;
2323

2424
namespace Monai.Deploy.WorkflowManager.Authentication.Middleware
2525
{

src/WorkflowManager/Authentication/Monai.Deploy.WorkflowManager.Authentication.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
</PropertyGroup>
2626

2727
<ItemGroup>
28-
<AdditionalFiles Include="..\..\.sonarlint\project-monai_monai-deploy-workflow-manager\CSharp\SonarLint.xml" Link="SonarLint.xml" />
28+
<Compile Include="..\..\AssemblyInfo.cs" Link="AssemblyInfo.cs" />
2929
</ItemGroup>
3030

31+
3132
<ItemGroup>
32-
<Compile Include="..\..\AssemblyInfo.cs" Link="AssemblyInfo.cs" />
33+
<AdditionalFiles Include="..\..\.sonarlint\project-monai_monai-deploy-workflow-manager\CSharp\SonarLint.xml" Link="SonarLint.xml" />
3334
</ItemGroup>
3435

3536
<ItemGroup>

src/WorkflowManager/Common/Extensions/FileExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
1817
using Monai.Deploy.Storage.API;
1918

2019
namespace Monai.Deploy.WorkflowManager.Common.Extensions

src/WorkflowManager/Common/Interfaces/IWorkflowInstanceService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public interface IWorkflowInstanceService : IPaginatedApi<WorkflowInstance>
5151
/// <returns></returns>
5252
public Task<long> FilteredCountAsync(Status? status = null, string? payloadId = null);
5353

54-
5554
/// <summary>
5655
/// Get all failed workflow instance's within a time span.
5756
/// </summary>

0 commit comments

Comments
 (0)