-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Http Operations] [Logs] Preconditional failures logs (#3598)
* Clean config file. Bundle orchestrator improvements. * Logging to conditional updates * Adding more logs to conditional operations * Undo fix in bundle to isolate the PR changes * Adding validations to arguments * Improvements in logging. Adding new component to track statistics. * Improvements in logs
- Loading branch information
Showing
19 changed files
with
293 additions
and
74 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/Microsoft.Health.Fhir.Core.UnitTests/Logging/LongRunningOperationStatisticsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Threading; | ||
using Microsoft.Health.Fhir.Core.Logging; | ||
using Microsoft.Health.Fhir.Tests.Common; | ||
using Microsoft.Health.Test.Utilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.Fhir.Core.UnitTests.Logging | ||
{ | ||
[Trait(Traits.OwningTeam, OwningTeam.Fhir)] | ||
[Trait(Traits.Category, Categories.Operations)] | ||
public class LongRunningOperationStatisticsTests | ||
{ | ||
[Fact] | ||
public void GivenALongRunningOperation_WhenUsingStatistics_ThenComputeOperationsAsExpected() | ||
{ | ||
const int count = 10; | ||
const int sleeptime = 10; | ||
|
||
LongRunningOperationStatistics statistics = new LongRunningOperationStatistics("operation"); | ||
|
||
statistics.StartCollectingResults(); | ||
|
||
for (int i = 0; i < count; i++) | ||
{ | ||
statistics.Iterate(); | ||
Thread.Sleep(sleeptime); | ||
} | ||
|
||
statistics.StopCollectingResults(); | ||
string json = statistics.GetStatisticsAsJson(); | ||
|
||
Assert.Equal(count, statistics.IterationCount); | ||
Assert.True(statistics.ElapsedMilliseconds > 0, "Elapsed Milliseconds is not greater than ZERO."); | ||
Assert.True(statistics.ElapsedMilliseconds >= (count * sleeptime), "Elapsed Milliseconds is not than the expected time."); | ||
Assert.Contains(statistics.GetLoggingCategory(), json); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Microsoft.Health.Fhir.Core/Logging/BaseOperationStatistics.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Diagnostics; | ||
|
||
namespace Microsoft.Health.Fhir.Core.Logging | ||
{ | ||
public abstract class BaseOperationStatistics | ||
{ | ||
private readonly Stopwatch _stopwatch; | ||
|
||
protected BaseOperationStatistics() | ||
{ | ||
_stopwatch = new Stopwatch(); | ||
} | ||
|
||
public long ElapsedMilliseconds | ||
{ | ||
get { return _stopwatch.ElapsedMilliseconds; } | ||
} | ||
|
||
public abstract string GetStatisticsAsJson(); | ||
|
||
public abstract string GetLoggingCategory(); | ||
|
||
public virtual void StartCollectingResults() | ||
{ | ||
_stopwatch.Start(); | ||
} | ||
|
||
public virtual void StopCollectingResults() | ||
{ | ||
_stopwatch.Stop(); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/Microsoft.Health.Fhir.Core/Logging/LongRunningOperationStatistics.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Threading; | ||
using EnsureThat; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Microsoft.Health.Fhir.Core.Logging | ||
{ | ||
public sealed class LongRunningOperationStatistics : BaseOperationStatistics | ||
{ | ||
private readonly string _operationName; | ||
|
||
private int _iterationCount; | ||
|
||
public LongRunningOperationStatistics(string operationName) | ||
: base() | ||
{ | ||
EnsureArg.IsNotNull(operationName, nameof(operationName)); | ||
|
||
_operationName = operationName; | ||
_iterationCount = 0; | ||
} | ||
|
||
public int IterationCount | ||
{ | ||
get | ||
{ | ||
return _iterationCount; | ||
} | ||
} | ||
|
||
public void Iterate() | ||
{ | ||
Interlocked.Increment(ref _iterationCount); | ||
} | ||
|
||
public override string GetLoggingCategory() => _operationName; | ||
|
||
public override string GetStatisticsAsJson() | ||
{ | ||
JObject serializableEntity = JObject.FromObject(new | ||
{ | ||
label = GetLoggingCategory(), | ||
iterationCount = _iterationCount, | ||
executionTime = ElapsedMilliseconds, | ||
}); | ||
|
||
return serializableEntity.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.