Skip to content

Commit

Permalink
FH 1.0.14
Browse files Browse the repository at this point in the history
FH 1.0.14
  • Loading branch information
GitTorre authored Mar 15, 2022
2 parents 7e0a119 + 5230c42 commit 3c909f2
Show file tree
Hide file tree
Showing 29 changed files with 421 additions and 230 deletions.
8 changes: 4 additions & 4 deletions Build-SFPKGs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ function Build-SFPkg {
try {
Push-Location $scriptPath

Build-SFPkg "Microsoft.ServiceFabricApps.FabricHealer.Linux.SelfContained.1.0.13" "$scriptPath\bin\release\FabricHealer\linux-x64\self-contained\FabricHealerType"
Build-SFPkg "Microsoft.ServiceFabricApps.FabricHealer.Linux.FrameworkDependent.1.0.13" "$scriptPath\bin\release\FabricHealer\linux-x64\framework-dependent\FabricHealerType"
Build-SFPkg "Microsoft.ServiceFabricApps.FabricHealer.Linux.SelfContained.1.0.14" "$scriptPath\bin\release\FabricHealer\linux-x64\self-contained\FabricHealerType"
Build-SFPkg "Microsoft.ServiceFabricApps.FabricHealer.Linux.FrameworkDependent.1.0.14" "$scriptPath\bin\release\FabricHealer\linux-x64\framework-dependent\FabricHealerType"

Build-SFPkg "Microsoft.ServiceFabricApps.FabricHealer.Windows.SelfContained.1.0.13" "$scriptPath\bin\release\FabricHealer\win-x64\self-contained\FabricHealerType"
Build-SFPkg "Microsoft.ServiceFabricApps.FabricHealer.Windows.FrameworkDependent.1.0.13" "$scriptPath\bin\release\FabricHealer\win-x64\framework-dependent\FabricHealerType"
Build-SFPkg "Microsoft.ServiceFabricApps.FabricHealer.Windows.SelfContained.1.0.14" "$scriptPath\bin\release\FabricHealer\win-x64\self-contained\FabricHealerType"
Build-SFPkg "Microsoft.ServiceFabricApps.FabricHealer.Windows.FrameworkDependent.1.0.14" "$scriptPath\bin\release\FabricHealer\win-x64\framework-dependent\FabricHealerType"
}
finally {
Pop-Location
Expand Down
65 changes: 33 additions & 32 deletions FHTest/FHUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace FHTest
{
/// <summary>
/// NOTE: Run these tests on your machine with a local SF dev cluster running.
/// TODO: More code coverage.
/// </summary>

[TestClass]
Expand Down Expand Up @@ -73,13 +74,18 @@ private static bool IsLocalSFRuntimePresent()
}
}

/// <summary>
/// This function cancels the local repair tasks created by the tests.
/// </summary>
/// <returns></returns>
private static async Task CleanupTestRepairJobsAsync()
{
// Complete (Cancel) any existing Test Repair Jobs.
try
{
var repairTasks = await fabricClient.RepairManager.GetRepairTaskListAsync();
var testRepairTasks = repairTasks.Where(r => r.TaskId.EndsWith("TEST_0"));

foreach (var repairTask in testRepairTasks)
{
if (repairTask.State != RepairTaskState.Completed)
Expand All @@ -90,9 +96,7 @@ private static async Task CleanupTestRepairJobsAsync()
}
catch (FabricException)
{
#if DEBUG
throw;
#endif
}
}

Expand All @@ -103,10 +107,10 @@ public static async Task TestClassCleanupAsync()
}

/* GuanLogic Tests */
// TODO: Add more tests.
// Currently, the tests below validate logic rules and the successful scheduling of related local repair jobs.

// This test ensures your actual rule files contain legitimate rules. This will catch bugs in your
// logic. Of course, you should have caught these flaws in your end-to-end tests. This is just an extra precaution.
// This test ensures your shipping rule files (the guan files located in Config/LogicRules folder)
// contain correctly written rules and that the related local repair job is successfully created.
[TestMethod]
public async Task TestGuanLogic_AllRules_FabricHealer_EnsureWellFormedRules_QueryInitialized()
{
Expand All @@ -120,13 +124,15 @@ public async Task TestGuanLogic_AllRules_FabricHealer_EnsureWellFormedRules_Quer
TelemetryEnabled = false
};

// This will be the mock data used to create a repair task.
var foHealthData = new TelemetryData
{
ApplicationName = "fabric:/test",
NodeName = "TEST_0",
RepairId = "Test42",
Code = FOErrorWarningCodes.AppErrorMemoryMB,
ServiceName = "fabric:/test0/service0",
Value = 1024.0
};

var executorData = new RepairExecutorData
Expand All @@ -136,25 +142,20 @@ public async Task TestGuanLogic_AllRules_FabricHealer_EnsureWellFormedRules_Quer

foreach (var file in Directory.GetFiles(FHRulesDirectory))
{
List<string> repairRules = ParseRulesFile((await File.ReadAllLinesAsync(file, token)).ToList());
List<string> repairRules = ParseRulesFile(await File.ReadAllLinesAsync(file, token));

try
{
Assert.IsTrue(await TestInitializeGuanAndRunQuery(foHealthData, repairRules, executorData).ConfigureAwait(true));
await TestInitializeGuanAndRunQuery(foHealthData, repairRules, executorData);
}
catch (GuanException ge)
{
Console.WriteLine(ge.ToString());
throw;
throw new AssertFailedException(ge.Message, ge);
}
}

Assert.IsTrue(true);
}

// This test ensures a given rule can successfully be turned into a GL query.
// This means that the rule is well-formed logic and that the referenced predicates exist.
// So, if the rule is malformed or not a logic rule or no predicate exists as written, this test will fail.
// This test ensures your test rules housed in testrules_wellformed file or in fact correct.
[TestMethod]
public async Task TestGuanLogicRule_GoodRule_QueryInitialized()
{
Expand All @@ -170,7 +171,7 @@ public async Task TestGuanLogicRule_GoodRule_QueryInitialized()

string testRulesFilePath = Path.Combine(Environment.CurrentDirectory, "testrules_wellformed");
string[] rules = await File.ReadAllLinesAsync(testRulesFilePath, token).ConfigureAwait(true);
List<string> repairRules = ParseRulesFile(rules.ToList());
List<string> repairRules = ParseRulesFile(rules);
var foHealthData = new TelemetryData
{
ApplicationName = "fabric:/test0",
Expand All @@ -189,11 +190,17 @@ public async Task TestGuanLogicRule_GoodRule_QueryInitialized()
RepairPolicy = new RepairPolicy { RepairAction = RepairActionType.RestartCodePackage },
};

Assert.IsTrue(await TestInitializeGuanAndRunQuery(foHealthData, repairRules, executorData).ConfigureAwait(true));
try
{
await TestInitializeGuanAndRunQuery(foHealthData, repairRules, executorData);
}
catch (GuanException ge)
{
throw new AssertFailedException(ge.Message, ge);
}
}

// All rules in target rules file are malformed. They should all lead to GuanExceptions.
// If they do not lead to a GuanException from TestInitializeGuanAndRunQuery, then this test will fail.
// This test ensures your test rules housed in testrules_malformed file or in fact incorrect.
[TestMethod]
public async Task TestGuanLogicRule_BadRule_ShouldThrowGuanException()
{
Expand All @@ -208,7 +215,7 @@ public async Task TestGuanLogicRule_BadRule_ShouldThrowGuanException()
};

string[] rules = await File.ReadAllLinesAsync(Path.Combine(Environment.CurrentDirectory, "testrules_malformed"), token).ConfigureAwait(true);
List<string> repairAction = ParseRulesFile(rules.ToList());
List<string> repairAction = ParseRulesFile(rules);

var foHealthData = new TelemetryData
{
Expand All @@ -231,15 +238,9 @@ public async Task TestGuanLogicRule_BadRule_ShouldThrowGuanException()
await Assert.ThrowsExceptionAsync<GuanException>(async () => { await TestInitializeGuanAndRunQuery(foHealthData, repairAction, executorData); });
}

/* FH Repair Scheduler Tests */
// TODO.

/* FH Repair Excecutor Tests */
// TODO.

/* private Helpers */

private async Task<bool> TestInitializeGuanAndRunQuery(TelemetryData foHealthData, List<string> repairRules, RepairExecutorData executorData)
private async Task TestInitializeGuanAndRunQuery(TelemetryData foHealthData, List<string> repairRules, RepairExecutorData executorData)
{
var fabricClient = new FabricClient();
var repairTaskManager = new RepairTaskManager(fabricClient, context, token);
Expand Down Expand Up @@ -295,17 +296,16 @@ private async Task<bool> TestInitializeGuanAndRunQuery(TelemetryData foHealthDat
compoundTerm.AddArgument(new Constant(Convert.ToInt64(foHealthData.Value)), RepairConstants.MetricValue);
compoundTerms.Add(compoundTerm);

return await queryDispatcher.RunQueryAsync(compoundTerms).ConfigureAwait(false);
//return Task.FromResult(true);
await queryDispatcher.RunQueryAsync(compoundTerms).ConfigureAwait(false);
}

private List<string> ParseRulesFile(List<string> rules)
private static List<string> ParseRulesFile(string[] rules)
{
var repairRules = new List<string>();
int ptr1 = 0; int ptr2 = 0;
rules = rules.Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
int ptr1 = 0, ptr2 = 0;
rules = rules.Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();

while (ptr1 < rules.Count && ptr2 < rules.Count)
while (ptr1 < rules.Length && ptr2 < rules.Length)
{
// Single line comments removal.
if (rules[ptr2].TrimStart().StartsWith("##"))
Expand All @@ -329,6 +329,7 @@ private List<string> ParseRulesFile(List<string> rules)
{
rule = rule + ' ' + rules[i].Replace('\t', ' ').TrimStart(' ');
}

repairRules.Add(rule.Remove(rule.Length - 1, 1));
}
ptr2++;
Expand Down
11 changes: 11 additions & 0 deletions FHTest/testrules_wellformed
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ Mitigate(MetricName="MemoryMB", MetricValue=?MetricValue) :- ?MetricValue >= 102
?HealthEventCount >= 3,
TimeScopedRestartCodePackage(1, 01:00:00).

## Disk

Mitigate(FOErrorCode=?FOErrorCode) :- ?FOErrorCode == "FO042" || ?FOErrorCode == "FO043", GetRepairHistory(?repairCount, 08:00:00),
?repairCount < 4,
CheckFolderSize("E:\SvcFab\Log\Traces", MaxFolderSizeGB=50),
DeleteFiles("E:\SvcFab\Log\Traces", SortOrder=Ascending, MaxFilesToDelete=25, RecurseSubdirectories=false).

Mitigate(FOErrorCode=?FOErrorCode) :- ?FOErrorCode == "FO042" || ?FOErrorCode == "FO043", GetRepairHistory(?repairCount, 08:00:00),
?repairCount < 4,
CheckFolderSize("%SOMEPATHVAR%", MaxFolderSizeGB=50),
DeleteFiles("%SOMEPATHVAR%", SortOrder=Ascending, MaxFilesToDelete=25, RecurseSubdirectories=false).

## Ports

Expand Down
13 changes: 9 additions & 4 deletions FabricHealer.nuspec.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="3.3.0">
<id>%PACKAGE_ID%</id>
<version>1.0.13</version>
<version>1.0.14</version>
<releaseNotes>
- Fixed bugs due to Guan 1.0.4 breaking changes. *This version requires Guan 1.0.4*.
- Updated Disk Repair feature.
- Updated logic rules.
Added support for new FabricObserver 3.1.25 - new ephemeral ports metric (Percentage in use of total dynamic ports configured for machine).
Updated Disk logic rules with Folder Size Warning repair workflow.
Added more descriptions to all rules files to help clarify how to compose successful related logic.
Added ObserverName named argument to Mitigate CompoundTerm (e.g., Mitigate(ObserverName=DiskObserver) :- ...).
Added GetRepairRulesForSupportedObserver function to add more flexibility to getting related rules Lists. This will help limit required FH code changes to support new FO capabilities.
Renamed rules text files to '[repair type].guan'. Ex: AppRules.guan, DiskRules.guan, etc.
EnableTelemetryProvider is now an Application Parameter.
Code improvements.
</releaseNotes>
<authors>Microsoft</authors>
<license type="expression">MIT</license>
Expand Down
24 changes: 22 additions & 2 deletions FabricHealer/FabricHealer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<RuntimeIdentifier>win-x64</RuntimeIdentifier>-->
<RuntimeIdentifiers>linux-x64;win-x64</RuntimeIdentifiers>
<Product>FabricHealer</Product>
<Version>1.0.13</Version>
<FileVersion>1.0.13</FileVersion>
<Version>1.0.14</Version>
<FileVersion>1.0.14</FileVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<IsServiceFabricServiceProject>true</IsServiceFabricServiceProject>
<StartupObject>FabricHealer.Program</StartupObject>
Expand All @@ -39,4 +39,24 @@
<ItemGroup>
<ProjectReference Include="..\TelemetryLib\TelemetryLib.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="PackageRoot\Config\LogicRules\AppRules.guan">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="PackageRoot\Config\LogicRules\DiskRules.guan">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="PackageRoot\Config\LogicRules\FabricNodeRules.guan">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="PackageRoot\Config\LogicRules\ReplicaRules.guan">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="PackageRoot\Config\LogicRules\SystemAppRules.guan">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="PackageRoot\Config\LogicRules\VmRules.guan">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Loading

0 comments on commit 3c909f2

Please sign in to comment.