Skip to content

Commit

Permalink
Dev/saars/csv health reporter options (#152)
Browse files Browse the repository at this point in the history
* Update the configuration name for ensure output can be saved

* Update readme accordingly

* Bump up version number

Made a configuration property name change and that is a small break
change.

* Rewords a bit in README.md

Make the description of EnsureOutuputCanBeSaved clearer.
  • Loading branch information
xiaomi7732 authored Nov 17, 2017
1 parent 4fb15f8 commit 27164cc
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,8 @@ This health reporter writes all errors, warnings, and informational traces gener
"minReportLevel": "Warning",
"throttlingPeriodMsec": "1000",
"singleLogFileMaximumSizeInMBytes": "8192",
"logRetentionInDays": "30"
"logRetentionInDays": "30",
"ensureOutputCanBeSaved": "false"
}
```
| Field | Values/Types | Required | Description |
Expand All @@ -862,9 +863,9 @@ This health reporter writes all errors, warnings, and informational traces gener
| `throttlingPeriodMsec` | number of milliseconds | No | Specifies the throttling time period. This setting protects the health reporter from being overwhelmed, which can happen if a message is repeatedly generated due to an error in the pipeline. Default is 0, for no throttling. |
| `singleLogFileMaximumSizeInMBytes` | File size in MB/number | No | Specifies the size of the log file in MB before rotating happens. The default value is 8192 MB (8 GB). Once the size of log file exceeds the value, it will be renamed from fileName.csv to fileName_last.csv. Then logs will be written to a new fileName.csv. This setting prevents a single log file become too big. |
| `logRetentionInDays` | number of days for the logs files retain | No | Specifies how long log files will be retained. The default value is 30 days. Any log files created earlier than the specified number of days ago will be removed automatically. This prevents continuous generation of logs that might lead to storage exhaustion. |
| `ensureOutputCanBeSaved` | boolean | No | Specifies whether the health reporter is going to ensure the permission to write to the log folder. The default value is `false`. When set to `true`, it will prevent the pipeline creation when it can't write the log. Otherwise, it will ignore the error.


CsvHealthReporter will try to open the log file for writing during initialization. If it can't, a debug message will be output to the debugger viewer like Visual Studio Output window, etc. This can happen especially if a value for the log file path is not provided (default is used, which is application executables folder) and the application executables are residing on a read-only file system. Docker tools for Visual Studio use this configuration during debugging, so for containerized services the recommended practice is to specify the log file path explicitly.
CsvHealthReporter will try to open the log file for writing during initialization. If it can't, by default, a debug message will be output to the debugger viewer like Visual Studio Output window, etc. This can happen especially if a value for the log file path is not provided (default is used, which is application executables folder) and the application executables are residing on a read-only file system. Docker tools for Visual Studio use this configuration during debugging, so for containerized services the recommended practice is to specify the log file path explicitly.

### Pipeline Settings
The EventFlow configuration has settings allowing the application to adjust certain behaviors of the pipeline. These range from how many events the pipeline buffer, to the timeout the pipeline should use when waiting for an operation. If this section is omitted, the pipeline will use default settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"throttlingPeriodMsec": "1000",
"singleLogFileMaximumSizeInMBytes": 1,
"logRetentionInDays": 1,
"isDebugMode": false
"ensureOutputCanBeSaved": false
},
"schema-version": "2016-08-11"
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static class FileSuffix
private int flushPeriodMsec = 5000;
private FileStream fileStream;
internal StreamWriter StreamWriter;
internal bool IsDebugMode { get; private set; }
internal bool EnsureOutputCanBeSaved { get; private set; }
internal long SingleLogFileMaximumSizeInBytes { get; private set; }
#endregion

Expand Down Expand Up @@ -132,7 +132,7 @@ public void Activate()
if (StreamWriter == null)
{
message = $"Fail to set new stream writer for {nameof(CsvHealthReporter)}.";
if (IsDebugMode)
if (EnsureOutputCanBeSaved)
{
throw new InvalidOperationException(message);
}
Expand All @@ -146,7 +146,7 @@ public void Activate()
}
catch (UnauthorizedAccessException ex)
{
if (IsDebugMode)
if (EnsureOutputCanBeSaved)
{
throw;
}
Expand Down Expand Up @@ -395,7 +395,7 @@ private void Initialize(CsvHealthReporterConfiguration configuration, INewReport

this.reportCollection = new BlockingCollection<string>();

this.IsDebugMode = configuration.IsDebugMode;
this.EnsureOutputCanBeSaved = configuration.EnsureOutputCanBeSaved;

this.innerReportWriter = this.ReportText;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public class CsvHealthReporterConfiguration
public int? ThrottlingPeriodMsec { get; set; }
public int SingleLogFileMaximumSizeInMBytes { get; set; }
public int LogRetentionInDays { get; set; }
public bool IsDebugMode { get; set; }
public bool EnsureOutputCanBeSaved { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>1.1.7</Version>
<Version>1.1.8</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class CsvHealthReporterTests
private const string ThrottlingPeriodMsecKey = "ThrottlingPeriodMsec";
private const string SingleLogFileMaximumSizeInMBytesKey = "SingleLogFileMaximumSizeInMBytes";
private const string LogRetentionInDaysKey = "LogRetentionInDays";
private const string IsDebugModeKey = "IsDebugMode";
private const string EnsureOutputCanBeSavedKey = "EnsureOutputCanBeSaved";
private const int DefaultDelayMsec = 100;

[Fact]
Expand Down Expand Up @@ -370,10 +370,10 @@ public void ShouldHandleUnauthorizedAccessWhenCreatingTheFileStream()
}

[Fact]
public void ShouldThrowUnauthorizedAccessWhenIsDebugModeIsOn()
public void ShouldThrowUnauthorizedAccessWhenEnsureOutputCanBeSavedIsOn()
{
var configuration = BuildTestConfigration();
configuration[IsDebugModeKey] = "true";
configuration[EnsureOutputCanBeSavedKey] = "true";
string exceptionMessage = "Simulate no permission to write the file.";
using (CustomHealthReporter target = new CustomHealthReporter(configuration, 1000, setNewStreamWriter: () => throw new UnauthorizedAccessException(exceptionMessage)))
{
Expand Down Expand Up @@ -429,30 +429,30 @@ public void ShouldCleanUpExistingLogsPerRetentionPolicy()
}

[Fact]
public void ShouldSetIsDebugModeToFalseByDefault()
public void ShouldSetEnsureOutputCanBeSavedToFalseByDefault()
{
var configuration = BuildTestConfigration();
Assert.Null(configuration[IsDebugModeKey]);
Assert.Null(configuration[EnsureOutputCanBeSavedKey]);
using (CustomHealthReporter target = new CustomHealthReporter(configuration))
{
Assert.False(target.IsDebugMode);
Assert.False(target.EnsureOutputCanBeSaved);
}
}

[Fact]
public void ShouldSetIsDebugModeByConfiguration()
public void ShouldSetEnsureOutputCanBeSavedByConfiguration()
{
var configuration = BuildTestConfigration();
configuration[IsDebugModeKey] = "true";
configuration[EnsureOutputCanBeSavedKey] = "true";
using (CustomHealthReporter target = new CustomHealthReporter(configuration))
{
Assert.True(target.IsDebugMode);
Assert.True(target.EnsureOutputCanBeSaved);
}

configuration[IsDebugModeKey] = "false";
configuration[EnsureOutputCanBeSavedKey] = "false";
using (CustomHealthReporter target = new CustomHealthReporter(configuration))
{
Assert.False(target.IsDebugMode);
Assert.False(target.EnsureOutputCanBeSaved);
}
}

Expand Down

0 comments on commit 27164cc

Please sign in to comment.