Skip to content

Commit

Permalink
Issue #292, concurrency changes to prevent CPU abuse, deps.
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Torre committed Jan 25, 2024
1 parent f853f44 commit b6b7dea
Show file tree
Hide file tree
Showing 41 changed files with 391 additions and 394 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.FabricObserver.Linux.SelfContained.3.2.13" "$scriptPath\bin\release\FabricObserver\linux-x64\self-contained\FabricObserverType"
Build-SFPkg "Microsoft.ServiceFabricApps.FabricObserver.Linux.FrameworkDependent.3.2.13" "$scriptPath\bin\release\FabricObserver\linux-x64\framework-dependent\FabricObserverType"
Build-SFPkg "Microsoft.ServiceFabricApps.FabricObserver.Linux.SelfContained.3.2.14" "$scriptPath\bin\release\FabricObserver\linux-x64\self-contained\FabricObserverType"
Build-SFPkg "Microsoft.ServiceFabricApps.FabricObserver.Linux.FrameworkDependent.3.2.14" "$scriptPath\bin\release\FabricObserver\linux-x64\framework-dependent\FabricObserverType"

Build-SFPkg "Microsoft.ServiceFabricApps.FabricObserver.Windows.SelfContained.3.2.13" "$scriptPath\bin\release\FabricObserver\win-x64\self-contained\FabricObserverType"
Build-SFPkg "Microsoft.ServiceFabricApps.FabricObserver.Windows.FrameworkDependent.3.2.13" "$scriptPath\bin\release\FabricObserver\win-x64\framework-dependent\FabricObserverType"
Build-SFPkg "Microsoft.ServiceFabricApps.FabricObserver.Windows.SelfContained.3.2.14" "$scriptPath\bin\release\FabricObserver\win-x64\self-contained\FabricObserverType"
Build-SFPkg "Microsoft.ServiceFabricApps.FabricObserver.Windows.FrameworkDependent.3.2.14" "$scriptPath\bin\release\FabricObserver\win-x64\framework-dependent\FabricObserverType"
}
finally {
Pop-Location
Expand Down
2 changes: 1 addition & 1 deletion ClusterObserver/ClusterObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public ClusterObserver(StatelessServiceContext serviceContext, bool ignoreDefaul
public override async Task ObserveAsync(CancellationToken token)
{
if (!IsEnabled || (!IsTelemetryEnabled && !IsEtwEnabled)
|| (RunInterval > TimeSpan.MinValue && DateTime.Now.Subtract(LastRunDateTime) < RunInterval))
|| (RunInterval > TimeSpan.Zero && DateTime.Now.Subtract(LastRunDateTime) < RunInterval))
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion ClusterObserver/PackageRoot/Data/Plugins/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ cd C:\Users\me\source\repos\service-fabric-observer
./Build-FabricObserver
./Build-NugetPackages

The output from the above commands, FabricObserver platform-specific nupkgs and a package you have to use for plugin authoring named Microsoft.ServiceFabricApps.FabricObserver.Extensibility.3.2.13.nupkg, would be located in
The output from the above commands, FabricObserver platform-specific nupkgs and a package you have to use for plugin authoring named Microsoft.ServiceFabricApps.FabricObserver.Extensibility.3.2.14.nupkg, would be located in
C:\Users\me\source\repos\service-fabric-observer\bin\release\FabricObserver\Nugets.
6 changes: 3 additions & 3 deletions Documentation/Deployment/service-fabric-observer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
},
"applicationTypeVersionFabricObserver": {
"type": "string",
"defaultValue": "3.2.13",
"defaultValue": "3.2.14",
"metadata": {
"description": "Provide the app version number of FabricObserver. This must be identical to the version, 3.2.13, in the referenced sfpkg specified in packageUrlFabricObserver."
"description": "Provide the app version number of FabricObserver. This must be identical to the version, 3.2.14, in the referenced sfpkg specified in packageUrlFabricObserver."
}
},
"packageUrlFabricObserver": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "This has to be a public accessible URL for the sfpkg file which contains the FabricObserver app package. Example: https://github.com/microsoft/service-fabric-observer/releases/download/[xxxxxxxx]/Microsoft.ServiceFabricApps.FabricObserver.Windows.SelfContained.3.2.13.sfpkg"
"description": "This has to be a public accessible URL for the sfpkg file which contains the FabricObserver app package. Example: https://github.com/microsoft/service-fabric-observer/releases/download/[xxxxxxxx]/Microsoft.ServiceFabricApps.FabricObserver.Windows.SelfContained.3.2.14.sfpkg"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"value": "<YOUR-CLUSTER-RESOURCE-NAME>"
},
"applicationTypeVersionFabricObserver": {
"value": "3.2.13"
"value": "3.2.14"
},
"packageUrlFabricObserver": {
"value": "<PUBLIC-ACCESSIBLE-URL-FOR-FABRICOBSERVER-SFPKG>"
Expand Down
4 changes: 2 additions & 2 deletions Documentation/OperationalTelemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ As with most of FabricObserver's application settings, you can also do this with
Connect-ServiceFabricCluster ...
$appParams = @{ "ObserverManagerEnableOperationalFOTelemetry" = "false"; }
Start-ServiceFabricApplicationUpgrade -ApplicationName fabric:/FabricObserver -ApplicationParameter $appParams -ApplicationTypeVersion 3.2.13 -UnMonitoredAuto
Start-ServiceFabricApplicationUpgrade -ApplicationName fabric:/FabricObserver -ApplicationParameter $appParams -ApplicationTypeVersion 3.2.14 -UnMonitoredAuto
```

Expand All @@ -44,7 +44,7 @@ Here is a full example of exactly what is sent in one of these telemetry events,
"ClusterId": "00000000-1111-1111-0000-00f00d000d",
"ClusterType": "SFRP",
"NodeNameHash": "3e83569d4c6aad78083cd081215dafc81e5218556b6a46cb8dd2b183ed0095ad",
"FOVersion": "3.2.13",
"FOVersion": "3.2.14",
"HasPlugins": "False",
"SFRuntimeVersion":"9.0.1028.9590"
"UpTime": "1.00:30:18.8058379",
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ cd C:\Users\me\source\repos\service-fabric-observer
./Build-FabricObserver
./Build-NugetPackages
```
The output from the above commands contains FabricObserver platform-specific nupkgs and a nupkg you have to use for plugin authoring named Microsoft.ServiceFabricApps.FabricObserver.Extensibility.3.2.13.nupkg. Nuget packages will be located in
The output from the above commands contains FabricObserver platform-specific nupkgs and a nupkg you have to use for plugin authoring named Microsoft.ServiceFabricApps.FabricObserver.Extensibility.3.2.14.nupkg. Nuget packages will be located in
C:\Users\me\source\repos\service-fabric-observer\bin\release\FabricObserver\Nugets.
4 changes: 2 additions & 2 deletions Documentation/Using.md
Original file line number Diff line number Diff line change
Expand Up @@ -710,15 +710,15 @@ $appParams = @{ "FabricSystemObserverEnabled" = "true"; "FabricSystemObserverMem
Then execute the application upgrade with

```Powershell
Start-ServiceFabricApplicationUpgrade -ApplicationName fabric:/FabricObserver -ApplicationTypeVersion 3.2.13 -ApplicationParameter $appParams -Monitored -FailureAction rollback
Start-ServiceFabricApplicationUpgrade -ApplicationName fabric:/FabricObserver -ApplicationTypeVersion 3.2.14 -ApplicationParameter $appParams -Monitored -FailureAction rollback
```

**Important**: This action will overwrite previous app paramemter changes that were made in an earlier application upgrade, for example. If you want to preserve any earlier changes, then you will need to
supply those parameter values again along with the new ones. You do this in the following, simple way:

```PowerShell
$appName = "fabric:/FabricObserver"
$appVersion = "3.2.13"
$appVersion = "3.2.14"
$application = Get-ServiceFabricApplication -ApplicationName $appName
$appParamCollection = $application.ApplicationParameters
$applicationParameterMap = @{}
Expand Down
4 changes: 2 additions & 2 deletions FabricObserver.Extensibility.nuspec.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="3.3.0">
<id>%PACKAGE_ID%</id>
<version>3.2.13</version>
<version>3.2.14</version>
<releaseNotes>
Note: This is library is required for observer plugins that target FabricObserver 3.2.13.
Note: This is library is required for observer plugins that target FabricObserver 3.2.14.
</releaseNotes>
<authors>Microsoft</authors>
<license type="expression">MIT</license>
Expand Down
18 changes: 9 additions & 9 deletions FabricObserver.Extensibility/FabricObserver.Extensibility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
<RootNamespace>FabricObserver</RootNamespace>
<Copyright>Copyright © 2023</Copyright>
<Product>FabricObserver</Product>
<Version>3.2.13</Version>
<FileVersion>3.2.13</FileVersion>
<Version>3.2.14</Version>
<FileVersion>3.2.14</FileVersion>
<NoWarn>CA1416</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.NLogTarget" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.22.0" />
<PackageReference Include="Microsoft.ApplicationInsights.NLogTarget" Version="2.22.0" />
<PackageReference Include="Microsoft.ServiceFabric.Services" Version="6.0.1017" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="5.2.4" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="7.0.0" />
<PackageReference Include="System.Management" Version="7.0.2" />
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="8.0.0" />
<PackageReference Include="System.Management" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TelemetryLib\TelemetryLib.csproj" />
Expand Down
109 changes: 46 additions & 63 deletions FabricObserver.Extensibility/ObserverBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public abstract class ObserverBase : IDisposable
private bool disposed;
private ConcurrentDictionary<string, (int DumpCount, DateTime LastDumpDate)> ServiceDumpCountDictionary;
private readonly object lockObj = new();

private bool IsTelemetryProviderEnabled
{
get; set;
}

protected ITelemetryProvider TelemetryClient
{
get; set;
}

public volatile bool HasActiveFabricErrorOrWarning;
public volatile int CurrentErrorCount;
public volatile int CurrentWarningCount;
Expand Down Expand Up @@ -230,14 +241,6 @@ public bool EnableCsvLogging
}
}

/// <summary>
/// The maximum number of days an archived observer log file will be stored. After this time, it will be deleted from disk.
/// </summary>
public int MaxLogArchiveFileLifetimeDays
{
get; set;
}

/// <summary>
/// The maximum number of days a csv file produced by CsvLogger will be stored. After this time, it will be deleted from disk.
/// </summary>
Expand All @@ -261,11 +264,6 @@ public ConcurrentQueue<string> ServiceNames
get; set;
} = new ConcurrentQueue<string>();

public string ServiceNamesLogPath
{
get; set;
}

public int MonitoredServiceProcessCount
{
get; set;
Expand All @@ -278,13 +276,13 @@ public int MonitoredAppCount

public TimeSpan RunInterval
{
get => ConfigurationSettings?.RunInterval ?? TimeSpan.MinValue;
get => ConfigurationSettings?.RunInterval ?? TimeSpan.FromMinutes(1);

set
{
if (ConfigurationSettings != null)
{
ConfigurationSettings.RunInterval = value;
ConfigurationSettings.RunInterval = value > TimeSpan.Zero ? value : TimeSpan.FromMinutes(1);
}
}
}
Expand Down Expand Up @@ -322,38 +320,30 @@ public bool UseCircularBuffer

public TimeSpan MonitorDuration
{
get => ConfigurationSettings?.MonitorDuration ?? TimeSpan.MinValue;
get => ConfigurationSettings?.MonitorDuration ?? TimeSpan.Zero;
set
{
if (ConfigurationSettings != null)
{
ConfigurationSettings.MonitorDuration = value;
// Prevent bad values.
ConfigurationSettings.MonitorDuration = value > TimeSpan.Zero ? value : TimeSpan.FromSeconds(1);
}
}
}

public TimeSpan MonitorSleepDuration
public TimeSpan CpuMonitorLoopSleepDuration
{
get => ConfigurationSettings?.MonitorSleepDuration ?? TimeSpan.MinValue;
get => ConfigurationSettings?.MonitorSleepDuration ?? TimeSpan.Zero;
set
{
if (ConfigurationSettings != null)
{
ConfigurationSettings.MonitorSleepDuration = value;
// Prevent bad values.
ConfigurationSettings.MonitorSleepDuration = value > TimeSpan.Zero ? value : TimeSpan.FromMilliseconds(1000);
}
}
}

protected bool IsTelemetryProviderEnabled
{
get; set;
}

protected ITelemetryProvider TelemetryClient
{
get; set;
}

public bool IsEtwProviderEnabled
{
get; set;
Expand Down Expand Up @@ -389,8 +379,7 @@ protected ObserverBase(FabricClient fabricClient, StatelessServiceContext servic
ConfigPackage = serviceContext.CodePackageActivationContext.GetConfigurationPackageObject("Config");
CodePackage = serviceContext.CodePackageActivationContext.GetCodePackageObject("Code");
FabricServiceContext = serviceContext;

SetObserverStaticConfiguration();
ConfigurationSettings = new ConfigSettings(ConfigPackage.Settings, ConfigurationSectionName);

if (ObserverName == ObserverConstants.AppObserverName)
{
Expand All @@ -411,21 +400,29 @@ protected ObserverBase(FabricClient fabricClient, StatelessServiceContext servic
logFolderBasePath = logFolderBase;
}

ObserverLogger = new Logger(ObserverName, logFolderBasePath, MaxLogArchiveFileLifetimeDays)
// Archive file lifetime - ObserverLogger files.
if (int.TryParse(
GetSettingParameterValue(
ObserverConstants.ObserverManagerConfigurationSectionName,
ObserverConstants.MaxArchivedLogFileLifetimeDaysParameter), out int maxFileArchiveLifetime))
{

}

SetObserverEtwTelemetryConfiguration();

ObserverLogger = new Logger(ObserverName, logFolderBasePath, maxFileArchiveLifetime > 0 ? maxFileArchiveLifetime : 7)
{
EnableETWLogging = IsEtwProviderEnabled
EnableETWLogging = IsEtwProviderEnabled,
EnableVerboseLogging = ConfigurationSettings.EnableVerboseLogging
};

ConfigurationSettings = new ConfigSettings(ConfigPackage.Settings, ConfigurationSectionName);
ObserverLogger.EnableVerboseLogging = ConfigurationSettings.EnableVerboseLogging;
HealthReporter = new ObserverHealthReporter(ObserverLogger);
IsObserverWebApiAppDeployed =
bool.TryParse(
GetSettingParameterValue(
ObserverConstants.ObserverManagerConfigurationSectionName,
ObserverConstants.ObserverWebApiEnabled), out bool obsWeb) && obsWeb && IsObserverWebApiAppInstalled();

ServiceNamesLogPath = Path.Combine(ObserverLogger.LogFolderBasePath, ObserverName, "ServiceNames", "Services.txt");
}

/// <summary>
Expand Down Expand Up @@ -1468,11 +1465,11 @@ public TimeSpan GetHealthReportTTL()
{
return TimeSpan.FromSeconds(obsSleepTime)
.Add(TimeSpan.FromMinutes(TtlAddMinutes))
.Add(RunInterval > TimeSpan.MinValue ? RunInterval : TimeSpan.Zero);
.Add(RunInterval > TimeSpan.Zero ? RunInterval : TimeSpan.Zero);
}

return DateTime.Now.Subtract(LastRunDateTime)
.Add(TimeSpan.FromSeconds(RunDuration > TimeSpan.MinValue ? RunDuration.TotalSeconds : 0))
.Add(TimeSpan.FromSeconds(RunDuration > TimeSpan.Zero ? RunDuration.TotalSeconds : 0))
.Add(TimeSpan.FromSeconds(obsSleepTime));
}

Expand All @@ -1491,31 +1488,23 @@ protected virtual void Dispose(bool disposing)
}
}

// Non-App parameters settings (set in Settings.xml only).
private void SetObserverStaticConfiguration()
public void SetObserverEtwTelemetryConfiguration()
{
// Archive file lifetime - ObserverLogger files.
if (int.TryParse(
GetSettingParameterValue(ObserverConstants.ObserverManagerConfigurationSectionName, ObserverConstants.MaxArchivedLogFileLifetimeDaysParameter), out int maxFileArchiveLifetime))
{
MaxLogArchiveFileLifetimeDays = maxFileArchiveLifetime;
}

// ETW
// ETW Provider.
if (bool.TryParse(
GetSettingParameterValue(ObserverConstants.ObserverManagerConfigurationSectionName, ObserverConstants.EnableETWProvider), out bool etwProviderEnabled))
{
IsEtwProviderEnabled = etwProviderEnabled;
}

// Telemetry.
// Telemetry Provider.
if (bool.TryParse(
GetSettingParameterValue(ObserverConstants.ObserverManagerConfigurationSectionName, ObserverConstants.TelemetryEnabled), out bool telemEnabled))
{
IsTelemetryProviderEnabled = telemEnabled;
}

if (!IsTelemetryProviderEnabled)
if (!IsTelemetryEnabled)
{
return;
}
Expand All @@ -1524,15 +1513,9 @@ private void SetObserverStaticConfiguration()
GetSettingParameterValue(
ObserverConstants.ObserverManagerConfigurationSectionName, ObserverConstants.TelemetryProviderType);

if (string.IsNullOrWhiteSpace(telemetryProviderType))
{
IsTelemetryProviderEnabled = false;
return;
}

if (!Enum.TryParse(telemetryProviderType, out TelemetryProviderType telemetryProvider))
if (string.IsNullOrWhiteSpace(telemetryProviderType) || !Enum.TryParse(telemetryProviderType, out TelemetryProviderType telemetryProvider))
{
IsTelemetryProviderEnabled = false;
IsTelemetryEnabled = false;
return;
}

Expand All @@ -1554,7 +1537,7 @@ private void SetObserverStaticConfiguration()

if (string.IsNullOrWhiteSpace(logAnalyticsWorkspaceId) || string.IsNullOrWhiteSpace(logAnalyticsSharedKey))
{
IsTelemetryProviderEnabled = false;
IsTelemetryEnabled = false;
return;
}

Expand All @@ -1568,7 +1551,7 @@ private void SetObserverStaticConfiguration()

if (string.IsNullOrWhiteSpace(aiConnString))
{
IsTelemetryProviderEnabled = false;
IsTelemetryEnabled = false;
return;
}

Expand All @@ -1577,7 +1560,7 @@ private void SetObserverStaticConfiguration()

default:

IsTelemetryProviderEnabled = false;
IsTelemetryEnabled = false;
break;
}
}
Expand Down
Loading

0 comments on commit b6b7dea

Please sign in to comment.